You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@celix.apache.org by GitBox <gi...@apache.org> on 2022/11/27 13:45:36 UTC

[GitHub] [celix] PengZheng commented on a diff in pull request #447: Feature/cxx14 framework support

PengZheng commented on code in PR #447:
URL: https://github.com/apache/celix/pull/447#discussion_r1032907907


##########
conanfile.py:
##########
@@ -88,6 +90,8 @@ class CelixConan(ConanFile):
         "enable_address_sanitizer": False,
         "enable_undefined_sanitizer": False,
         "enable_thread_sanitizer": False,
+        "enable_testing_dependency_manager_for_cxx11": False,
+        "eenable_testing_for_cxx14": False,

Review Comment:
   These two should be removed from package id calculation, see  `package_id`.



##########
libs/framework/include/celix/Trackers.h:
##########
@@ -217,18 +217,19 @@ namespace celix {
      */
     class GenericServiceTracker : public AbstractTracker {
     public:
+#if __cplusplus >= 201703L //C++17 or higher
         GenericServiceTracker(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string_view _svcName,
                               std::string_view _svcVersionRange, celix::Filter _filter) : AbstractTracker{std::move(_cCtx)}, svcName{_svcName},
                                                                                    svcVersionRange{_svcVersionRange}, filter{std::move(_filter)} {
-            opts.trackerCreatedCallbackData = this;
-            opts.trackerCreatedCallback = [](void *data) {
-                auto* trk = static_cast<GenericServiceTracker*>(data);
-                {
-                    std::lock_guard<std::mutex> callbackLock{trk->mutex};
-                    trk->state = TrackerState::OPEN;
-                }
-            };
+            setupServiceTrackerOptions();
+        }
+#else
+        GenericServiceTracker(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string _svcName,

Review Comment:
   Will universal reference make string_view unnecessary?



##########
libs/framework/include/celix/TrackerBuilders.h:
##########
@@ -42,9 +42,9 @@ namespace celix {
         //NOTE private to prevent move so that a build() call cannot be forgotten
         ServiceTrackerBuilder(ServiceTrackerBuilder&&) noexcept = default;
     public:
-        explicit ServiceTrackerBuilder(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string_view _name) :
+        explicit ServiceTrackerBuilder(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string _name) :

Review Comment:
   I think `ServiceTrackerBuilder(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string&& _name)`, which eliminator a constructor call, is better.
   
   And the best solution I know is so called universal reference, from Effective Modern C++, Item 25:
   
   ```C++
   template<typename T>
   explicit ServiceTrackerBuilder(std::shared_ptr<celix_bundle_context_t> _cCtx, T&& _name) :
   cCtx{std::move(_cCtx)},
   name{std::forward<T>(_name)} {}
   
   ```
   
   If `_name` is a plain C string, this will also work without extra constructor calls. 
   This consideration should apply to several other places. 
   
   I also wonder if usage of universal reference will make string_view unnecessary? See `Trackers.h` for an example.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@celix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org