This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/509-update-cxx-support-to-cxx14 in repository https://gitbox.apache.org/repos/asf/celix.git
commit bd2487aa1d572bcd5af80d3068fd9fe79d8d825c Author: Pepijn Noltes <[email protected]> AuthorDate: Sun Oct 1 14:52:07 2023 +0200 #509: Remove C++17 support for lib utils and framework --- .asf.yaml | 2 +- CMakeLists.txt | 7 +- README.md | 2 +- .../include/celix/rsa/EndpointDescription.h | 3 +- conanfile.py | 4 - examples/celix-examples/CMakeLists.txt | 2 +- libs/framework/gtest/CMakeLists.txt | 77 ------------- .../gtest/src/CxxBundleContextTestSuite.cc | 15 --- .../gtest/src/DependencyManagerTestSuite.cc | 21 ++-- libs/framework/include/celix/Bundle.h | 19 ---- libs/framework/include/celix/BundleContext.h | 114 -------------------- libs/framework/include/celix/FrameworkUtils.h | 6 -- libs/framework/include/celix/ServiceRegistration.h | 16 --- .../include/celix/ServiceRegistrationBuilder.h | 9 -- libs/framework/include/celix/TrackerBuilders.h | 4 - libs/framework/include/celix/Trackers.h | 66 +----------- libs/framework/include/celix/UseServiceBuilder.h | 4 - libs/utils/gtest/CMakeLists.txt | 31 ++---- libs/utils/gtest/src/CxxPropertiesTestSuite.cc | 75 ------------- libs/utils/gtest/src/CxxUtilsTestSuite.cc | 36 ------- libs/utils/include/celix/Filter.h | 29 ----- libs/utils/include/celix/Utils.h | 119 --------------------- 22 files changed, 29 insertions(+), 632 deletions(-) diff --git a/.asf.yaml b/.asf.yaml index 031b60eb..f0effca9 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -18,7 +18,7 @@ # https://cwiki.apache.org/confluence/display/INFRA/git+-+.asf.yaml+features --- github: - description: "Apache Celix is a framework for C, C++14 and C++17 to develop dynamic modular software applications using component and in-process service-oriented programming." + description: "Apache Celix is a framework for C and C++14 to develop dynamic modular software applications using component and in-process service-oriented programming." homepage: https://celix.apache.org/ labels: - apache diff --git a/CMakeLists.txt b/CMakeLists.txt index fddf991f..0a67c35f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,8 +64,11 @@ set(CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "-Wall -Werror -Wextra -Weffc++ -Wformat -Wno-error=deprecated-declarations ${CMAKE_CXX_FLAGS}") if (NOT DEFINED CMAKE_CXX_STANDARD) - #Celix header only C++ supported is based on C++14 and C++17. + #Celix header only C++ supported is based on C++14. However, test code can be and is written in C++17. #Default using C++14 to ensure the code compiles for C++14. + + #There are 2 exceptions: The libraries Promises and PushStream are C++17 only. + #To ensure IDE like CLion can provide optimal C++17 support, the CMAKE_CXX_STANDARD variable is only set if #not already defined. set(CMAKE_CXX_STANDARD 14) @@ -161,13 +164,11 @@ option(CELIX_INSTALL_DEPRECATED_API "whether to install (and use) deprecated api option(CELIX_USE_ZIP_INSTEAD_OF_JAR "Default Celix cmake command will use jar to package bundle (if found). This option enforces Celix to use zip instead." OFF) option(CELIX_CXX14 "Build C++14 libraries and bundles. Note for tests C++ is always used." ON) -option(CELIX_CXX17 "Build C++17 libraries and bundles." ON) if (CELIX_CXX17 AND NOT CELIX_CXX14) set(CELIX_CXX14 ON) endif () option(ENABLE_TESTING_DEPENDENCY_MANAGER_FOR_CXX11 "Test the Dependency Manager for C++11 support" OFF) -option(ENABLE_TESTING_FOR_CXX14 "Test celix utils and framework C++ header for C++14 support" OFF) option(ENABLE_CMAKE_WARNING_TESTS "Enable cmake warning tests to test warning prints" OFF) option(ENABLE_TESTING_ON_CI "Whether to enable testing on CI. This influence allowed timing errors during unit tests" OFF) diff --git a/README.md b/README.md index e3b625e1..c0c2a07f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ limitations under the License. [](https://codecov.io/gh/apache/celix) [](https://scan.coverity.com/projects/6685) -Apache Celix is a framework for C, C++14 and C++17 to develop dynamic modular software applications using component +Apache Celix is a framework for C and C++14 to develop dynamic modular software applications using component and in-process service-oriented programming. Apache Celix is inspired by the [OSGi specification](https://www.osgi.org/) adapted for C and C++. diff --git a/bundles/cxx_remote_services/rsa_spi/include/celix/rsa/EndpointDescription.h b/bundles/cxx_remote_services/rsa_spi/include/celix/rsa/EndpointDescription.h index a747debe..57af0f8c 100644 --- a/bundles/cxx_remote_services/rsa_spi/include/celix/rsa/EndpointDescription.h +++ b/bundles/cxx_remote_services/rsa_spi/include/celix/rsa/EndpointDescription.h @@ -173,7 +173,8 @@ namespace celix::rsa { result.set(celix::rsa::SERVICE_IMPORTED, true); if (result.get(celix::rsa::ENDPOINT_ID).empty()) { - result.set(celix::rsa::ENDPOINT_ID, std::string{frameworkUUID} + "-" + serviceProperties.get(celix::SERVICE_ID)); + std::string value = std::string{frameworkUUID} + "-" + serviceProperties.get(celix::SERVICE_ID); + result.set(celix::rsa::ENDPOINT_ID, value); } return result; diff --git a/conanfile.py b/conanfile.py index dc145bbd..f5434d44 100644 --- a/conanfile.py +++ b/conanfile.py @@ -47,8 +47,6 @@ class CelixConan(ConanFile): "enable_address_sanitizer": False, "enable_undefined_sanitizer": False, "enable_thread_sanitizer": False, - "enable_testing_dependency_manager_for_cxx11": False, - "enable_testing_for_cxx14": False, "build_all": False, "build_deployment_admin": False, "build_http_admin": False, @@ -147,8 +145,6 @@ class CelixConan(ConanFile): del self.info.options.build_cxx_rsa_integration del self.info.options.build_examples del self.info.options.build_shell_bonjour - del self.info.options.enable_testing_dependency_manager_for_cxx11 - del self.info.options.enable_testing_for_cxx14 del self.info.options.enable_cmake_warning_tests del self.info.options.enable_testing_on_ci del self.info.options.enable_ccache diff --git a/examples/celix-examples/CMakeLists.txt b/examples/celix-examples/CMakeLists.txt index 92c68f0f..29e4b49d 100644 --- a/examples/celix-examples/CMakeLists.txt +++ b/examples/celix-examples/CMakeLists.txt @@ -36,7 +36,7 @@ if (EXAMPLES) add_subdirectory(services_example_cxx) add_subdirectory(dependency_manager_example_cxx) endif () - if (CELIX_CXX17) + if (CELIX_CXX14) add_subdirectory(readme_cxx_examples) endif () diff --git a/libs/framework/gtest/CMakeLists.txt b/libs/framework/gtest/CMakeLists.txt index f822270e..044659b8 100644 --- a/libs/framework/gtest/CMakeLists.txt +++ b/libs/framework/gtest/CMakeLists.txt @@ -15,8 +15,6 @@ # specific language governing permissions and limitations # under the License. -set(CMAKE_CXX_STANDARD 17) - add_celix_bundle(simple_test_bundle1 NO_ACTIVATOR VERSION 1.0.0) celix_bundle_name(simple_test_bundle1 "Simple Test Bundle") celix_bundle_group(simple_test_bundle1 "test/group") @@ -170,78 +168,3 @@ if (EI_TESTS) add_test(NAME test_framework_with_ei COMMAND test_framework_with_ei) setup_target_for_coverage(test_framework_with_ei SCAN_DIR ..) endif () - -if (ENABLE_TESTING_DEPENDENCY_MANAGER_FOR_CXX11) - #Setting standard to C++11 and testing C++ dependency manager to ensure that this still support C++11. - #This ensure that the C++11 dependency manager is backwards compatible with Celix 2.2.1 - set(CMAKE_CXX_STANDARD 11) - add_executable(test_dep_man_with_cxx11 - src/DependencyManagerTestSuite.cc - ) - target_link_libraries(test_dep_man_with_cxx11 PRIVATE framework_cut Celix::framework GTest::gtest GTest::gtest_main) - target_compile_definitions(test_dep_man_with_cxx11 PRIVATE - SIMPLE_CXX_DEP_MAN_BUNDLE_LOC="${SIMPLE_CXX_DEP_MAN_BUNDLE_LOC}" - ) - celix_deprecated_utils_headers(test_dep_man_with_cxx11) - celix_deprecated_framework_headers(test_dep_man_with_cxx11) - add_test(NAME test_dep_man_with_cxx11 COMMAND test_dep_man_with_cxx11) - setup_target_for_coverage(test_dep_man_with_cxx11 SCAN_DIR ..) - - #Also to ensure that CELIX_GEN_CXX_BUNDLE_ACTIVATOR still works for C++11 bundle activators with a - #dependency manager argument, the HelloWorldCxxActivatorWithDepMan will be used to create a C++11 bundle - add_celix_bundle(test_dep_man_bundle_activator_with_cxx11 SOURCES src/HelloWorldCxxActivatorWithDepMan.cc VERSION 1.0.0) -endif () - -if (ENABLE_TESTING_FOR_CXX14) - #Setting standard to C++14 and testing the C++ framework headers to ensure that C++14 is also supported. - set(CMAKE_CXX_STANDARD 14) - - add_executable(test_framework_with_cxx14 ${CELIX_FRAMEWORK_TEST_SOURCES}) - target_link_libraries(test_framework_with_cxx14 PRIVATE framework_cut Celix::framework GTest::gtest GTest::gtest_main) - celix_deprecated_utils_headers(test_framework_with_cxx14) - celix_deprecated_framework_headers(test_framework_with_cxx14) - add_celix_bundle_dependencies(test_framework_with_cxx14 - simple_test_bundle1 - simple_test_bundle2 simple_test_bundle3 simple_test_bundle4 - simple_test_bundle5 bundle_with_exception unresolvable_bundle simple_cxx_bundle simple_cxx_dep_man_bundle cmp_test_bundle) - target_include_directories(test_framework_with_cxx14 PRIVATE ../src) - - #Also to ensure that CELIX_GEN_CXX_BUNDLE_ACTIVATOR still for C++11. - add_celix_bundle(simple_cxx_bundle_with_cxx1 SOURCES src/HelloWorldCxxActivator.cc VERSION 1.0.0) - add_celix_bundle(simple_cxx_dep_man_bundle_with_cxx1 SOURCES src/HelloWorldCxxActivatorWithDepMan.cc VERSION 1.0.0) - add_celix_bundle_dependencies(test_framework_with_cxx14 simple_cxx_bundle_with_cxx1 simple_cxx_dep_man_bundle_with_cxx1) - - celix_get_bundle_file(simple_cxx_bundle_with_cxx1 SIMPLE_CXX_BUNDLE_WITH_CXX11_LOC) - celix_get_bundle_file(simple_cxx_dep_man_bundle_with_cxx1 SIMPLE_CXX_DEP_MAN_WITH_CXX11_BUNDLE_LOC) - - #embed bundle in the test_framework executable - celix_target_embedded_bundles(test_framework_with_cxx14 simple_test_bundle1 simple_test_bundle2) - - #Create bundle set definitions - celix_target_bundle_set_definition(test_framework_with_cxx14 NAME BUNDLE_EMPTY_TEST_SET) - celix_target_bundle_set_definition(test_framework_with_cxx14 NAME BUNDLE_TEST_SET - #Note this test set has two version fo bundle1, this is done for testing purpose. - simple_test_bundle1 simple_test_bundle3 simple_test_bundle1 simple_test_bundle2 - ) - - target_compile_definitions(test_framework_with_cxx14 PRIVATE - SIMPLE_TEST_BUNDLE1_LOCATION="${SIMPLE_TEST_BUNDLE1}" - SIMPLE_TEST_BUNDLE2_LOCATION="${SIMPLE_TEST_BUNDLE2}" - SIMPLE_TEST_BUNDLE3_LOCATION="${SIMPLE_TEST_BUNDLE3}" - SIMPLE_TEST_BUNDLE4_LOCATION="${SIMPLE_TEST_BUNDLE4_FILENAME}" - SIMPLE_TEST_BUNDLE5_LOCATION="${SIMPLE_TEST_BUNDLE5_FILENAME}" - TEST_BUNDLE_WITH_EXCEPTION_LOCATION="${BUNDLE_WITH_EXCEPTION}" - TEST_BUNDLE_UNRESOLVABLE_LOCATION="${UNRESOLVABLE_BUNDLE}" - SIMPLE_CXX_BUNDLE_LOC="${SIMPLE_CXX_BUNDLE_WITH_CXX11_LOC}" - CMP_TEST_BUNDLE_LOC="${CMP_TEST_BUNDLE_LOC}" - SIMPLE_CXX_DEP_MAN_BUNDLE_LOC="${SIMPLE_CXX_DEP_MAN_WITH_CXX11_BUNDLE_LOC}" - CMP_TEST_BUNDLE_LOC="${CMP_TEST_BUNDLE_LOC}" - COND_TEST_BUNDLE_LOC="${COND_TEST_BUNDLE_LOC}" - INSTALL_AND_START_BUNDLES_CONFIG_PROPERTIES_FILE="${CMAKE_CURRENT_BINARY_DIR}/install_and_start_bundles.properties" - ) - if (ENABLE_TESTING_ON_CI) - target_compile_definitions(test_framework_with_cxx14 PRIVATE TESTING_ON_CI=1) - endif () - add_test(NAME test_framework_with_cxx14 COMMAND test_framework_with_cxx14) - setup_target_for_coverage(test_framework_with_cxx14 SCAN_DIR ..) -endif () diff --git a/libs/framework/gtest/src/CxxBundleContextTestSuite.cc b/libs/framework/gtest/src/CxxBundleContextTestSuite.cc index 8e40eb9c..580a56f8 100644 --- a/libs/framework/gtest/src/CxxBundleContextTestSuite.cc +++ b/libs/framework/gtest/src/CxxBundleContextTestSuite.cc @@ -725,21 +725,6 @@ TEST_F(CxxBundleContextTestSuite, GetBundleInformation) { EXPECT_TRUE(startCalled); } -#if __cplusplus >= 201703L //C++17 or higher -class TestInterfaceWithStaticInfo { -public: - static constexpr std::string_view NAME = "TestName"; - static constexpr std::string_view VERSION = "1.2.3"; -}; - -TEST_F(CxxBundleContextTestSuite, RegisterServiceWithNameAndVersionInfo) { - auto reg = ctx->registerService<TestInterfaceWithStaticInfo>(std::make_shared<TestInterfaceWithStaticInfo>()) - .build(); - EXPECT_EQ(reg->getServiceName(), "TestName"); - EXPECT_EQ(reg->getServiceVersion(), "1.2.3"); -} -#endif - TEST_F(CxxBundleContextTestSuite, listBundles) { auto list = ctx->listBundleIds(); EXPECT_EQ(0, list.size()); diff --git a/libs/framework/gtest/src/DependencyManagerTestSuite.cc b/libs/framework/gtest/src/DependencyManagerTestSuite.cc index 4e2cdd8b..2138515d 100644 --- a/libs/framework/gtest/src/DependencyManagerTestSuite.cc +++ b/libs/framework/gtest/src/DependencyManagerTestSuite.cc @@ -1152,19 +1152,18 @@ TEST_F(DependencyManagerTestSuite, testStateToString) { } -#if __cplusplus >= 201703L //C++17 or higher - -class TestInterfaceWithStaticInfo { +class TestInterface { public: static constexpr const char * const NAME = "TestName"; static constexpr const char * const VERSION = "1.2.3"; }; -TEST_F(DependencyManagerTestSuite, ProvideInterfaceWithStaticInfo) { - class TestComponent : public TestInterfaceWithStaticInfo {}; +TEST_F(DependencyManagerTestSuite, ProvideInterfaceInfo) { + class TestComponent : public TestInterface {}; celix::dm::DependencyManager dm{ctx}; auto& cmp = dm.createComponent<TestComponent>(); - cmp.createProvidedService<TestInterfaceWithStaticInfo>(); + cmp.createProvidedService<TestInterface>(TestInterface::NAME) + .setVersion(TestInterface::VERSION); cmp.build(); EXPECT_EQ(cmp.getState(), celix::dm::ComponentState::TRACKING_OPTIONAL); @@ -1176,11 +1175,11 @@ TEST_F(DependencyManagerTestSuite, ProvideInterfaceWithStaticInfo) { EXPECT_EQ(it->second, "1.2.3"); } -TEST_F(DependencyManagerTestSuite, CreateInterfaceWithStaticInfo) { - class TestComponent : public TestInterfaceWithStaticInfo {}; +TEST_F(DependencyManagerTestSuite, CreateInterfaceInfo) { + class TestComponent : public TestInterface {}; celix::dm::DependencyManager dm{ctx}; auto& cmp = dm.createComponent<TestComponent>(); - cmp.addInterface<TestInterfaceWithStaticInfo>(); + cmp.addInterfaceWithName<TestInterface>(TestInterface::NAME, TestInterface::VERSION); cmp.build(); EXPECT_EQ(cmp.getState(), celix::dm::ComponentState::TRACKING_OPTIONAL); @@ -1196,7 +1195,7 @@ TEST_F(DependencyManagerTestSuite, TestPrintInfo) { celix::dm::DependencyManager dm{ctx}; auto& cmp = dm.createComponent<Cmp1>(); cmp.addInterface<TestService>(); - cmp.createServiceDependency<TestInterfaceWithStaticInfo>(); + cmp.createServiceDependency<TestInterface>(TestInterface::NAME); cmp.build(); char* buf = nullptr; @@ -1255,5 +1254,3 @@ TEST_F(DependencyManagerTestSuite, TestPrintInfo) { ss << cmp; EXPECT_TRUE(strstr(ss.str().c_str(), "Cmp1")); } - -#endif \ No newline at end of file diff --git a/libs/framework/include/celix/Bundle.h b/libs/framework/include/celix/Bundle.h index 5cc5e73f..d977d323 100644 --- a/libs/framework/include/celix/Bundle.h +++ b/libs/framework/include/celix/Bundle.h @@ -71,15 +71,9 @@ namespace celix { * @param path The relative path to a bundle resource. * @return The use-able entry path or an empty string if the entry is not found. */ -#if __cplusplus >= 201703L //C++17 or higher - std::string getEntry(std::string_view path) const { - return getEntryInternal(path.data()); - } -#else std::string getEntry(const std::string& path) const { return getEntryInternal(path.c_str()); } -#endif /** * @brief Return a use-able entry path for the provided relative path to a bundle persistent storage. @@ -96,32 +90,19 @@ namespace celix { * @param path The relative path to a bundle persistent storage entry. * @return The use-able entry path or an empty string if the entry is not found. */ -#if __cplusplus >= 201703L //C++17 or higher - std::string getDataFile(std::string_view path) const { - return getDataFileInternal(path.data()); - } -#else std::string getDataFile(const std::string& path) const { return getDataFileInternal(path.c_str()); } -#endif /** * @brief Get a manifest attribute value from the bundle manifest. * @param attribute The attribute to get the value from. * @return The attribute value or an empty string if the attribute is not present in the bundle manifest. */ -#if __cplusplus >= 201703L //C++17 or higher - std::string getManifestValue(std::string_view attribute) const { - const char* header = celix_bundle_getManifestValue(cBnd.get(), attribute.data()); - return header == nullptr ? std::string{} : std::string{header}; - } -#else std::string getManifestValue(const std::string& attribute) const { const char* header = celix_bundle_getManifestValue(cBnd.get(), attribute.c_str()); return header == nullptr ? std::string{} : std::string{header}; } -#endif /** * @brief the symbolic name of the bundle. diff --git a/libs/framework/include/celix/BundleContext.h b/libs/framework/include/celix/BundleContext.h index e217d60c..d98c0c5e 100644 --- a/libs/framework/include/celix/BundleContext.h +++ b/libs/framework/include/celix/BundleContext.h @@ -79,19 +79,11 @@ namespace celix { * @param name The optional name of the service. If not provided celix::typeName<I> will be used to defer the service name. * @return A ServiceRegistrationBuilder object. */ -#if __cplusplus >= 201703L //C++17 or higher - template<typename I, typename Implementer> - ServiceRegistrationBuilder<I> registerService(std::shared_ptr<Implementer> implementer, std::string_view name = {}) { - std::shared_ptr<I> svc = implementer; //note Implement should be derived from I - return ServiceRegistrationBuilder<I>{cCtx, std::move(svc), celix::typeName<I>(name)}; - } -#else template<typename I, typename Implementer> ServiceRegistrationBuilder<I> registerService(std::shared_ptr<Implementer> implementer, const std::string& name = {}) { std::shared_ptr<I> svc = implementer; //note Implement should be derived from I return ServiceRegistrationBuilder<I>{cCtx, std::move(svc), celix::typeName<I>(name)}; } -#endif /** * @brief Register a (unmanaged) service in the Celix framework using a fluent builder API. @@ -103,19 +95,11 @@ namespace celix { * By default the service registration is configure to register the service async, but to unregister the * service sync (because the svc pointer is unmanaged). */ -#if __cplusplus >= 201703L //C++17 or higher - template<typename I, typename Implementer> - ServiceRegistrationBuilder<I> registerUnmanagedService(Implementer* svc, std::string_view name = {}) { - auto unmanagedSvc = std::shared_ptr<I>{svc, [](I*){/*nop*/}}; - return ServiceRegistrationBuilder<I>{cCtx, std::move(unmanagedSvc), celix::typeName<I>(name), true, false}; - } -#else template<typename I, typename Implementer> ServiceRegistrationBuilder<I> registerUnmanagedService(Implementer* svc, const std::string& name = {}) { auto unmanagedSvc = std::shared_ptr<I>{svc, [](I*){/*nop*/}}; return ServiceRegistrationBuilder<I>{cCtx, std::move(unmanagedSvc), celix::typeName<I>(name), true, false}; } -#endif //TODO registerServiceFactory<I>() @@ -145,17 +129,10 @@ namespace celix { * @param name The optional service name to use. If not provided celix::typeName<I> will be used to defer the service name. * @return A UseServiceBuilder object. */ -#if __cplusplus >= 201703L //C++17 or higher - template<typename I> - UseServiceBuilder<I> useService(std::string_view name = {}) { - return UseServiceBuilder<I>{cCtx, celix::typeName<I>(name), true}; - } -#else template<typename I> UseServiceBuilder<I> useService(const std::string& name = {}) { return UseServiceBuilder<I>{cCtx, celix::typeName<I>(name), true}; } -#endif /** * @brief Use services registered in the Celix framework using a fluent builder API. @@ -180,17 +157,10 @@ namespace celix { * @param name The optional service name to use. If not provided celix::typeName<I> will be used to defer the service name. * @return A UseServiceBuilder object. */ -#if __cplusplus >= 201703L //C++17 or higher - template<typename I> - UseServiceBuilder<I> useServices(std::string_view name = {}) { - return UseServiceBuilder<I>{cCtx, celix::typeName<I>(name), false}; - } -#else template<typename I> UseServiceBuilder<I> useServices(const std::string& name = {}) { return UseServiceBuilder<I>{cCtx, celix::typeName<I>(name), false}; } -#endif /** * @brief Finds the highest ranking service using the optional provided (LDAP) filter @@ -203,17 +173,10 @@ namespace celix { * @param versionRange An optional version range. * @return The service id of the found service or -1 if the service was not found. */ -#if __cplusplus >= 201703L //C++17 or higher - template<typename I> - long findService(std::string_view filter = {}, std::string_view versionRange = {}) { - return findServiceWithName(celix::typeName<I>(), filter, versionRange); - } -#else template<typename I> long findService(const std::string& filter = {}, const std::string& versionRange = {}) { return findServiceWithName(celix::typeName<I>(), filter, versionRange); } -#endif /** * @brief Finds the highest ranking service using the provided service name and @@ -224,16 +187,6 @@ namespace celix { * @param versionRange An optional version range. * @return The service id of the found service or -1 if the service was not found. */ -#if __cplusplus >= 201703L //C++17 or higher - long findServiceWithName(std::string_view name, std::string_view filter = {}, std::string_view versionRange = {}) { - waitIfAbleForEvents(); - celix_service_filter_options_t opts{}; - opts.serviceName = name.empty() ? nullptr : name.data(); - opts.filter = filter.empty() ? nullptr : filter.data(); - opts.versionRange = versionRange.empty() ? nullptr : versionRange.data(); - return celix_bundleContext_findServiceWithOptions(cCtx.get(), &opts); - } -#else long findServiceWithName(const std::string& name, const std::string& filter = {}, const std::string& versionRange = {}) { waitIfAbleForEvents(); celix_service_filter_options_t opts{}; @@ -242,7 +195,6 @@ namespace celix { opts.versionRange = versionRange.empty() ? nullptr : versionRange.data(); return celix_bundleContext_findServiceWithOptions(cCtx.get(), &opts); } -#endif /** * @brief Finds all services matching the optional provided (LDAP) filter @@ -255,17 +207,10 @@ namespace celix { * @param versionRange An optional version range. * @return A vector of service ids. */ -#if __cplusplus >= 201703L //C++17 or higher - template<typename I> - std::vector<long> findServices(std::string_view filter = {}, std::string_view versionRange = {}) { - return findServicesWithName(celix::typeName<I>(), filter, versionRange); - } -#else template<typename I> std::vector<long> findServices(const std::string& filter = {}, const std::string& versionRange = {}) { return findServicesWithName(celix::typeName<I>(), filter, versionRange); } -#endif /** * @brief Finds all service matching the provided service name and the optional (LDAP) filter @@ -276,21 +221,12 @@ namespace celix { * @param versionRange An optional version range. * @return A vector of service ids. */ -#if __cplusplus >= 201703L //C++17 or higher - std::vector<long> findServicesWithName(std::string_view name, std::string_view filter = {}, std::string_view versionRange = {}) { - return findServicesWithNameInternal( - name.empty() ? nullptr : name.data(), - filter.empty() ? nullptr : filter.data(), - versionRange.empty() ? nullptr : versionRange.data()); - } -#else std::vector<long> findServicesWithName(const std::string& name, const std::string& filter = {}, const std::string& versionRange = {}) { return findServicesWithNameInternal( name.empty() ? nullptr : name.c_str(), filter.empty() ? nullptr : filter.c_str(), versionRange.empty() ? nullptr : versionRange.c_str()); } -#endif /** * @brief Track services in the Celix framework using a fluent builder API. @@ -312,17 +248,10 @@ namespace celix { * @param name The optional service name. If empty celix::typeName<I> will be used to defer the service name. * @return A ServiceTrackerBuilder object. */ -#if __cplusplus >= 201703L //C++17 or higher - template<typename I> - ServiceTrackerBuilder<I> trackServices(std::string_view name = {}) { - return ServiceTrackerBuilder<I>{cCtx, celix::typeName<I>(name)}; - } -#else template<typename I> ServiceTrackerBuilder<I> trackServices(const std::string& name = {}) { return ServiceTrackerBuilder<I>{cCtx, celix::typeName<I>(name)}; } -#endif /** * @brief Track services in the Celix framework using a fluent builder API. @@ -374,17 +303,10 @@ namespace celix { * @param name The optional service name. If empty celix::typeName<I> will be used to defer the service name. * @return A MetaTrackerBuilder object. */ -#if __cplusplus >= 201703L //C++17 or higher - template<typename I> - MetaTrackerBuilder trackServiceTrackers(std::string_view name = {}) { - return MetaTrackerBuilder(cCtx, celix::typeName<I>(name)); - } -#else template<typename I> MetaTrackerBuilder trackServiceTrackers(const std::string& name = {}) { return MetaTrackerBuilder(cCtx, celix::typeName<I>(name)); } -#endif /** * @brief Track service trackers in the Celix framework using a fluent builder API. @@ -412,15 +334,9 @@ namespace celix { * @param autoStart If the bundle should also be started. * @return the bundleId (>= 0) or < 0 if the bundle could not be installed and possibly started. */ -#if __cplusplus >= 201703L //C++17 or higher - long installBundle(std::string_view bndLocation, bool autoStart = true) { - return celix_bundleContext_installBundle(cCtx.get(), bndLocation.data(), autoStart); - } -#else long installBundle(const std::string& bndLocation, bool autoStart = true) { return celix_bundleContext_installBundle(cCtx.get(), bndLocation.c_str(), autoStart); } -#endif /** * @brief Uninstall the bundle with the provided bundle id. @@ -490,15 +406,9 @@ namespace celix { * bundle url from the bundle cache will be used. * @return true if the bundle is found & correctly started or if the bundle is updated async. False if not. */ -#if __cplusplus >= 201703L //C++17 or higher - bool updateBundle(long bndId, std::string_view updatedBundleUrl = {}) { - return celix_bundleContext_updateBundle(cCtx.get(), bndId, updatedBundleUrl.empty() ? nullptr : updatedBundleUrl.data()); - } -#else bool updateBundle(long bndId, const std::string& updatedBundleUrl = {}) { return celix_bundleContext_updateBundle(cCtx.get(), bndId, updatedBundleUrl.empty() ? nullptr : updatedBundleUrl.data()); } -#endif /** * @brief List the installed and started bundle ids. @@ -531,15 +441,9 @@ namespace celix { * @param defaultVal The default value to use if the property is not found. * @return The config property value for the provided key or the provided defaultValue is the name is not found. */ -#if __cplusplus >= 201703L //C++17 or higher - std::string getConfigProperty(std::string_view name, std::string_view defaultValue) const { - return std::string{celix_bundleContext_getProperty(cCtx.get(), name.data(), defaultValue.data())}; - } -#else std::string getConfigProperty(const std::string& name, const std::string& defaultValue) const { return std::string{celix_bundleContext_getProperty(cCtx.get(), name.c_str(), defaultValue.c_str())}; } -#endif /** * @brief Gets the config property for the provided name and returns it as a long. @@ -553,15 +457,9 @@ namespace celix { * @return The config property value (as long) for the provided key or the provided defaultValue is the name * is not found or not a valid long. */ -#if __cplusplus >= 201703L //C++17 or higher - long getConfigPropertyAsLong(std::string_view name, long defaultValue) const { - return celix_bundleContext_getPropertyAsLong(cCtx.get(), name.data(), defaultValue); - } -#else long getConfigPropertyAsLong(const std::string& name, long defaultValue) const { return celix_bundleContext_getPropertyAsLong(cCtx.get(), name.c_str(), defaultValue); } -#endif /** * @brief Gets the config property for the provided name and returns it as a double. @@ -575,15 +473,9 @@ namespace celix { * @return The config property value (as double) for the provided key or the provided defaultValue is the name * is not found or not a valid double. */ -#if __cplusplus >= 201703L //C++17 or higher - double getConfigPropertyAsDouble(std::string_view name, double defaultValue) const { - return celix_bundleContext_getPropertyAsDouble(cCtx.get(), name.data(), defaultValue); - } -#else double getConfigPropertyAsDouble(const std::string& name, double defaultValue) const { return celix_bundleContext_getPropertyAsDouble(cCtx.get(), name.c_str(), defaultValue); } -#endif /** * @brief Gets the config property for the provided name and returns it as a bool. @@ -599,15 +491,9 @@ namespace celix { * @return The config property value (as boolean) for the provided key or the provided defaultValue is the name * is not found or not a valid boolean. */ -#if __cplusplus >= 201703L //C++17 or higher - long getConfigPropertyAsBool(std::string_view name, bool defaultValue) const { - return celix_bundleContext_getPropertyAsBool(cCtx.get(), name.data(), defaultValue); - } -#else long getConfigPropertyAsBool(const std::string& name, bool defaultValue) const { return celix_bundleContext_getPropertyAsBool(cCtx.get(), name.c_str(), defaultValue); } -#endif /** * @brief Get the bundle of this bundle context. diff --git a/libs/framework/include/celix/FrameworkUtils.h b/libs/framework/include/celix/FrameworkUtils.h index 91932c59..d90c4b09 100644 --- a/libs/framework/include/celix/FrameworkUtils.h +++ b/libs/framework/include/celix/FrameworkUtils.h @@ -88,14 +88,8 @@ namespace celix { * @param autoStart Whether to also start the installed bundles. * @return The number of installed bundles. */ -#if __cplusplus >= 201703L //C++17 or higher - inline std::size_t installBundleSet(celix::Framework& framework, std::string_view bundleSet, bool autoStart = true) { - return celix_framework_utils_installBundleSet(framework.getCFramework(), bundleSet.data(), autoStart); - } -#else inline std::size_t installBundleSet(celix::Framework& framework, const std::string& bundleSet, bool autoStart = true) { return celix_framework_utils_installBundleSet(framework.getCFramework(), bundleSet.c_str(), autoStart); } -#endif } \ No newline at end of file diff --git a/libs/framework/include/celix/ServiceRegistration.h b/libs/framework/include/celix/ServiceRegistration.h index 9e7a6f7b..b5d2898a 100644 --- a/libs/framework/include/celix/ServiceRegistration.h +++ b/libs/framework/include/celix/ServiceRegistration.h @@ -67,21 +67,6 @@ namespace celix { * @return The new ServiceRegistration object as shared ptr. * @throws celix::Exception */ -#if __cplusplus >= 201703L //C++17 or higher - static std::shared_ptr<ServiceRegistration> create(std::shared_ptr<celix_bundle_context_t> cCtx, - std::shared_ptr<void> svc, - std::string_view name, - std::string_view version, - celix::Properties properties, - bool registerAsync, - bool unregisterAsync, - std::vector<std::function<void(ServiceRegistration&)>> onRegisteredCallbacks, - std::vector<std::function<void(ServiceRegistration&)>> onUnregisteredCallbacks) { - return createInternal(std::move(cCtx), std::move(svc), name.data(), - version.data(), std::move(properties), registerAsync, - unregisterAsync, std::move(onRegisteredCallbacks), std::move(onUnregisteredCallbacks)); - } -#else static std::shared_ptr<ServiceRegistration> create(std::shared_ptr<celix_bundle_context_t> cCtx, std::shared_ptr<void> svc, const std::string& name, @@ -95,7 +80,6 @@ namespace celix { version.c_str(), std::move(properties), registerAsync, unregisterAsync, std::move(onRegisteredCallbacks), std::move(onUnregisteredCallbacks)); } -#endif /** * @brief The service name for this service registration. diff --git a/libs/framework/include/celix/ServiceRegistrationBuilder.h b/libs/framework/include/celix/ServiceRegistrationBuilder.h index 4982766f..61b30bb9 100644 --- a/libs/framework/include/celix/ServiceRegistrationBuilder.h +++ b/libs/framework/include/celix/ServiceRegistrationBuilder.h @@ -64,24 +64,15 @@ namespace celix { * * This will lead to a 'service.version' service property. */ -#if __cplusplus >= 201703L //C++17 or higher - ServiceRegistrationBuilder& setVersion(std::string_view v) { version = v; return *this; } -#else ServiceRegistrationBuilder& setVersion(std::string v) { version = std::move(v); return *this; } -#endif /** * @brief Add a property to the service properties. * * If a key is already present the value will be overridden. */ -#if __cplusplus >= 201703L //C++17 or higher - template<typename T> - ServiceRegistrationBuilder& addProperty(std::string_view key, T&& value) { properties.template set(key, std::forward<T>(value)); return *this; } -#else template<typename T> ServiceRegistrationBuilder& addProperty(const std::string& key, T&& value) { properties.set(key, std::forward<T>(value)); return *this; } -#endif /** * @brief Set the service properties. diff --git a/libs/framework/include/celix/TrackerBuilders.h b/libs/framework/include/celix/TrackerBuilders.h index 35883d82..536ed059 100644 --- a/libs/framework/include/celix/TrackerBuilders.h +++ b/libs/framework/include/celix/TrackerBuilders.h @@ -57,11 +57,7 @@ namespace celix { * Example: * "(property_key=value)" */ -#if __cplusplus >= 201703L //C++17 or higher - ServiceTrackerBuilder& setFilter(std::string_view f) { filter = celix::Filter{f}; return *this; } -#else ServiceTrackerBuilder& setFilter(const std::string& f) { filter = celix::Filter{f}; return *this; } -#endif /** * @brief Set filter to be used to matching services. diff --git a/libs/framework/include/celix/Trackers.h b/libs/framework/include/celix/Trackers.h index 5498607c..442f74b7 100644 --- a/libs/framework/include/celix/Trackers.h +++ b/libs/framework/include/celix/Trackers.h @@ -216,19 +216,11 @@ 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)} { - setupServiceTrackerOptions(); - } -#else GenericServiceTracker(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string _svcName, std::string _svcVersionRange, celix::Filter _filter) : AbstractTracker{std::move(_cCtx)}, svcName{std::move(_svcName)}, svcVersionRange{std::move(_svcVersionRange)}, filter{std::move(_filter)} { setupServiceTrackerOptions(); } -#endif ~GenericServiceTracker() override = default; @@ -319,29 +311,6 @@ namespace celix { * @return The new service tracker as shared ptr. * @throws celix::Exception */ -#if __cplusplus >= 201703L //C++17 or higher - static std::shared_ptr<ServiceTracker<I>> create( - std::shared_ptr<celix_bundle_context_t> cCtx, - std::string_view svcName, - std::string_view svcVersionRange, - celix::Filter filter, - std::vector<std::function<void(const std::shared_ptr<I>&, const std::shared_ptr<const celix::Properties>&, const std::shared_ptr<const celix::Bundle>&)>> setCallbacks, - std::vector<std::function<void(const std::shared_ptr<I>&, const std::shared_ptr<const celix::Properties>&, const std::shared_ptr<const celix::Bundle>&)>> addCallbacks, - std::vector<std::function<void(const std::shared_ptr<I>&, const std::shared_ptr<const celix::Properties>&, const std::shared_ptr<const celix::Bundle>&)>> remCallbacks) { - auto tracker = std::shared_ptr<ServiceTracker<I>>{ - new ServiceTracker<I>{ - std::move(cCtx), - svcName, - svcVersionRange, - std::move(filter), - std::move(setCallbacks), - std::move(addCallbacks), - std::move(remCallbacks)}, - AbstractTracker::delCallback<ServiceTracker<I>>()}; - tracker->open(); - return tracker; - } -#else static std::shared_ptr<ServiceTracker<I>> create( std::shared_ptr<celix_bundle_context_t> cCtx, std::string svcName, @@ -363,7 +332,6 @@ namespace celix { tracker->open(); return tracker; } -#endif /** * @brief Get the current highest ranking service tracked by this tracker. @@ -417,19 +385,7 @@ namespace celix { std::shared_ptr<const celix::Bundle> owner; }; -#if __cplusplus >= 201703L //C++17 or higher - ServiceTracker(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string_view _svcName, - std::string_view _svcVersionRange, celix::Filter _filter, - std::vector<std::function<void(const std::shared_ptr<I>&, const std::shared_ptr<const celix::Properties>&, const std::shared_ptr<const celix::Bundle>&)>> _setCallbacks, - std::vector<std::function<void(const std::shared_ptr<I>&, const std::shared_ptr<const celix::Properties>&, const std::shared_ptr<const celix::Bundle>&)>> _addCallbacks, - std::vector<std::function<void(const std::shared_ptr<I>&, const std::shared_ptr<const celix::Properties>&, const std::shared_ptr<const celix::Bundle>&)>> _remCallbacks) : - GenericServiceTracker{std::move(_cCtx), _svcName, _svcVersionRange, std::move(_filter)}, - setCallbacks{std::move(_setCallbacks)}, - addCallbacks{std::move(_addCallbacks)}, - remCallbacks{std::move(_remCallbacks)} { - setupServiceTrackerOptions(); - } -#else + ServiceTracker(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string _svcName, std::string _svcVersionRange, celix::Filter _filter, std::vector<std::function<void(const std::shared_ptr<I>&, const std::shared_ptr<const celix::Properties>&, const std::shared_ptr<const celix::Bundle>&)>> _setCallbacks, @@ -441,7 +397,6 @@ namespace celix { remCallbacks{std::move(_remCallbacks)} { setupServiceTrackerOptions(); } -#endif static std::shared_ptr<SvcEntry> createEntry(void* voidSvc, const celix_properties_t* cProps, const celix_bundle_t* cBnd) { long svcId = celix_properties_getAsLong(cProps, OSGI_FRAMEWORK_SERVICE_ID, -1L); @@ -750,23 +705,7 @@ namespace celix { * @return The new meta tracker as shared ptr. * @throws celix::Exception. */ -#if __cplusplus >= 201703L //C++17 or higher - static std::shared_ptr<MetaTracker> create( - std::shared_ptr<celix_bundle_context_t> cCtx, - std::string_view serviceName, - std::vector<std::function<void(const ServiceTrackerInfo&)>> onTrackerCreated, - std::vector<std::function<void(const ServiceTrackerInfo&)>> onTrackerDestroyed) { - auto tracker = std::shared_ptr<MetaTracker>{ - new MetaTracker{ - std::move(cCtx), - std::string{serviceName}, - std::move(onTrackerCreated), - std::move(onTrackerDestroyed)}, - AbstractTracker::delCallback<MetaTracker>()}; - tracker->open(); - return tracker; - } -#else + static std::shared_ptr<MetaTracker> create( std::shared_ptr<celix_bundle_context_t> cCtx, std::string serviceName, @@ -782,7 +721,6 @@ namespace celix { tracker->open(); return tracker; } -#endif /** * @see AbstractTracker::open diff --git a/libs/framework/include/celix/UseServiceBuilder.h b/libs/framework/include/celix/UseServiceBuilder.h index 1e86cee6..db73ed89 100644 --- a/libs/framework/include/celix/UseServiceBuilder.h +++ b/libs/framework/include/celix/UseServiceBuilder.h @@ -70,11 +70,7 @@ namespace celix { * Example: * "(property_key=value)" */ -#if __cplusplus >= 201703L //C++17 or higher - UseServiceBuilder& setFilter(std::string_view f) { filter = celix::Filter{f}; return *this; } -#else UseServiceBuilder& setFilter(const std::string& f) { filter = celix::Filter{f}; return *this; } -#endif /** * @brief Set filter to be used to matching services. diff --git a/libs/utils/gtest/CMakeLists.txt b/libs/utils/gtest/CMakeLists.txt index c6ae1cff..07ac013f 100644 --- a/libs/utils/gtest/CMakeLists.txt +++ b/libs/utils/gtest/CMakeLists.txt @@ -15,21 +15,14 @@ # specific language governing permissions and limitations # under the License. -set(CMAKE_CXX_STANDARD 17) - -set(CELIX_UTIL_TEST_SOURCES_FOR_CXX_HEADERS +add_executable(test_utils src/CxxUtilsTestSuite.cc src/CxxPropertiesTestSuite.cc src/CxxFilterTestSuite.cc -) - -add_executable(test_utils src/LogTestSuite.cc src/LogUtilsTestSuite.cc src/VersionRangeTestSuite.cc src/TimeUtilsTestSuite.cc - src/HashMapTestSuite.cc - src/ArrayListTestSuite.cc src/FileUtilsTestSuite.cc src/FilterTestSuite.cc src/CelixUtilsTestSuite.cc @@ -38,10 +31,16 @@ add_executable(test_utils src/ThreadsTestSuite.cc src/CelixErrnoTestSuite.cc src/CelixUtilsAutoCleanupTestSuite.cc - ${CELIX_UTIL_TEST_SOURCES_FOR_CXX_HEADERS} ) -target_link_libraries(test_utils PRIVATE utils_cut Celix::utils GTest::gtest GTest::gtest_main libzip::zip) +add_library(test_utils_cxx17tests STATIC + src/ArrayListTestSuite.cc #Uses constexpr + src/HashMapTestSuite.cc #Uses constexpr +) +target_link_libraries(test_utils_cxx17tests PRIVATE utils_cut Celix::utils GTest::gtest GTest::gtest_main) +target_compile_features(test_utils_cxx17tests PRIVATE cxx_std_17) + +target_link_libraries(test_utils PRIVATE utils_cut Celix::utils GTest::gtest GTest::gtest_main libzip::zip test_utils_cxx17tests) target_include_directories(test_utils PRIVATE ../src) #for version_private (needs refactoring of test) celix_deprecated_utils_headers(test_utils) @@ -112,15 +111,3 @@ if (EI_TESTS) add_test(NAME test_utils_with_ei COMMAND test_utils_with_ei) setup_target_for_coverage(test_utils_with_ei SCAN_DIR ..) endif () - -if (ENABLE_TESTING_FOR_CXX14) - #Setting standard to C++14 and testing C++ Properties.h, Filter.h and Utils.h to ensure that C++14 is supported. - set(CMAKE_CXX_STANDARD 14) - add_executable(test_utils_cxx_headers_with_cxx14 - ${CELIX_UTIL_TEST_SOURCES_FOR_CXX_HEADERS} - ) - target_link_libraries(test_utils_cxx_headers_with_cxx14 PRIVATE utils_cut GTest::gtest GTest::gtest_main) - add_test(NAME test_utils_cxx_headers_with_cxx14 COMMAND test_utils_cxx_headers_with_cxx14) - setup_target_for_coverage(test_utils_cxx_headers_with_cxx14 SCAN_DIR ..) -endif () - diff --git a/libs/utils/gtest/src/CxxPropertiesTestSuite.cc b/libs/utils/gtest/src/CxxPropertiesTestSuite.cc index 01241b99..a66e433d 100644 --- a/libs/utils/gtest/src/CxxPropertiesTestSuite.cc +++ b/libs/utils/gtest/src/CxxPropertiesTestSuite.cc @@ -88,78 +88,3 @@ TEST_F(CxxPropertiesTestSuite, testWrap) { celix_properties_destroy(props); } - -#if __cplusplus >= 201703L //C++17 or higher -TEST_F(CxxPropertiesTestSuite, testStringView) { - constexpr std::string_view stringViewKey = "KEY1"; - constexpr std::string_view stringViewValue = "VALUE1"; - std::string stringKey{"KEY2"}; - std::string stringValue{"VALUE2"}; - const char* charKey = "KEY3"; - const char* charValue = "VALUE3"; - - { - //rule: I can create properties with initializer_list using std::string, const char* and string_view - celix::Properties props { - {charKey, charValue}, - {stringKey, stringValue}, - {stringViewKey, stringViewValue} - }; - EXPECT_EQ(props.size(), 3); - - //rule: I can use the subscript operator using string_view objects - constexpr std::string_view k = "KEY2"; - constexpr std::string_view v = "VALUE_NEW"; - std::string check = props[k]; - EXPECT_EQ(check, "VALUE2"); - props[k] = v; - check = props[k]; - EXPECT_EQ(check, v); - } - - { - //rule: I can use set/get with string_view - constexpr std::string_view key = "TEST_KEY"; - constexpr std::string_view value = "TEST_VALUE"; - - celix::Properties props{}; - - props.set(key, value); - EXPECT_EQ(value, props.get(key)); - props[key] = value; - EXPECT_EQ(value, props.get(key)); - EXPECT_EQ(1, props.size()); - - props.set(key, std::string{"string value"}); - EXPECT_EQ("string value", props.get(key)); - props.set(key, "string value"); - EXPECT_EQ("string value", props.get(key)); - EXPECT_EQ(1, props.size()); - - props.set(key, 1L); //long - EXPECT_EQ(1L, props.getAsLong(key, -1)); - props.set(key, 1.0); //double - EXPECT_EQ(1.0, props.getAsDouble(key, -1)); - props.set(key, true); //bool - EXPECT_EQ(true, props.getAsBool(key, false)); - } -} - -TEST_F(CxxPropertiesTestSuite, testUseOfConstexprInSetMethod) { - celix::Properties props{}; - - //Test if different bool "types" are correctly handled - props.set("key1", true); - props.set<const bool>("key2", false); - props.set<const bool&>("key3", 1); - props.set<bool&&>("key4", 0); - props.set<volatile bool&&>("key5", true); - EXPECT_EQ(5, props.size()); - - EXPECT_EQ(props.getAsBool("key1", false), true); - EXPECT_EQ(props.get("key2"), "false"); - EXPECT_EQ(props.get("key3"), "true"); - EXPECT_EQ(props.get("key4"), "false"); - EXPECT_EQ(props.get("key5"), "true"); -} -#endif diff --git a/libs/utils/gtest/src/CxxUtilsTestSuite.cc b/libs/utils/gtest/src/CxxUtilsTestSuite.cc index a0a2a3fe..6adf1f91 100644 --- a/libs/utils/gtest/src/CxxUtilsTestSuite.cc +++ b/libs/utils/gtest/src/CxxUtilsTestSuite.cc @@ -32,14 +32,6 @@ namespace example { std::string VERSION; //dummy non-static VERSION member, should not impact the typeVersion call }; -#if __cplusplus >= 201703L //C++17 or higher - class TestType2 { - public: - static constexpr std::string_view NAME = "AnotherTestTypeName"; - static constexpr const char * const VERSION = "1.2.0"; - }; -#endif - class TestType3 { public: static constexpr int NAME = 4; //dummy static int, which should not be used as type name (cannot be used to construct a string) @@ -54,25 +46,11 @@ TEST_F(UtilsTestSuite, testTypeName) { auto name = celix::typeName<example::TestType>(); EXPECT_FALSE(name.empty()); -#if __cplusplus >= 201703L //C++17 or higher - //When inferring a type name with no provided name, but the type has a NAME static member, - //the call should return the string value of the NAME static member (only support if C++17 is used). - name = celix::typeName<example::TestType2>(); - EXPECT_EQ(std::string{name}, std::string{"AnotherTestTypeName"}); -#endif - //When inferring a type name with a provided name and the type does not have a NAME static member, //the call should return the provided name. name = celix::typeName<example::TestType>("OverrideName"); EXPECT_EQ(name, std::string{"OverrideName"}); -#if __cplusplus >= 201703L //C++17 or higher - //When inferring a type name with a provided name and the type also has a NAME static member, - //the call should return the provided name (only support if C++17 is used). - name = celix::typeName<example::TestType2>("OverrideName"); - EXPECT_EQ(name, std::string{"OverrideName"}); -#endif - //When inferring a type name, where there is a static NAME member but not of the right type (constructable from string), //the call should return an inferred name based on __PRETTY_FUNCTION__ (see celix::impl::extractTypeName) name = celix::typeName<example::TestType3>(); @@ -86,24 +64,10 @@ TEST_F(UtilsTestSuite, testTypeVersion) { auto version = celix::typeVersion<example::TestType>(); EXPECT_TRUE(version.empty()); -#if __cplusplus >= 201703L //C++17 or higher - //When inferring a type version with no provided version and the type has a VERSION static member, - //the call should return the value of the static member VERSION (only support if C++17 is used). - version = celix::typeVersion<example::TestType2>(); - EXPECT_EQ(std::string{version}, std::string{"1.2.0"}); -#endif - //When inferring a type version with a provided version and the type does not have a VERSION static member, //the call should return the provided version. version = celix::typeVersion<example::TestType>("2.2.2"); EXPECT_EQ(version, std::string{"2.2.2"}); - -#if __cplusplus >= 201703L //C++17 or higher - //When inferring a type version with a provided version and the type does have a VERSION static member, - //the call should return the provided version (only support if C++17 is used). - version = celix::typeVersion<example::TestType2>("2.2.2"); - EXPECT_EQ(version, std::string{"2.2.2"}); -#endif } TEST_F(UtilsTestSuite, testSplit) { diff --git a/libs/utils/include/celix/Filter.h b/libs/utils/include/celix/Filter.h index 9fd33f3f..97c10159 100644 --- a/libs/utils/include/celix/Filter.h +++ b/libs/utils/include/celix/Filter.h @@ -51,11 +51,7 @@ namespace celix { class Filter { public: Filter() : cFilter{createFilter("")} {} -#if __cplusplus >= 201703L //C++17 or higher - explicit Filter(std::string_view filterStr) : cFilter{createFilter(filterStr.data())} {} -#else explicit Filter(const std::string& filterStr) : cFilter{createFilter(filterStr.c_str())} {} -#endif Filter(Filter&&) = default; @@ -104,30 +100,17 @@ namespace celix { * @brief Find the attribute based on the provided key. * @return The found attribute value or an empty string if the attribute was not found. */ -#if __cplusplus >= 201703L //C++17 or higher - std::string findAttribute(std::string_view attributeKey) const { - auto* cValue = celix_filter_findAttribute(cFilter.get(), attributeKey.data()); - return cValue == nullptr ? std::string{} : std::string{cValue}; - } -#else std::string findAttribute(const std::string& attributeKey) const { auto* cValue = celix_filter_findAttribute(cFilter.get(), attributeKey.data()); return cValue == nullptr ? std::string{} : std::string{cValue}; } -#endif /** * @brief Check whether the filter has a attribute with the provided attribute key. */ -#if __cplusplus >= 201703L //C++17 or higher - bool hasAttribute(std::string_view attributeKey) const { - return celix_filter_findAttribute(cFilter.get(), attributeKey.data()) != nullptr; - } -#else bool hasAttribute(const std::string& attributeKey) const { return celix_filter_findAttribute(cFilter.get(), attributeKey.data()) != nullptr; } -#endif /** * @brief Check whether the filter indicates the mandatory presence of an attribute with a specific value for the provided attribute key. @@ -138,15 +121,9 @@ namespace celix { * using this method for attribute key "key1" on filter "(key1>=value1)" yields false. * using this method for attribute key "key1" on filter "(|(key1=value1)(key2=value2))" yields false. */ -#if __cplusplus >= 201703L //C++17 or higher - bool hasMandatoryEqualsValueAttribute(std::string_view attributeKey) const { - return celix_filter_hasMandatoryEqualsValueAttribute(cFilter.get(), attributeKey.data()); - } -#else bool hasMandatoryEqualsValueAttribute(const std::string& attributeKey) const { return celix_filter_hasMandatoryEqualsValueAttribute(cFilter.get(), attributeKey.c_str()); } -#endif /** * @brief Check whether the filter indicates the mandatory absence of an attribute, regardless of its value, for the provided attribute key. @@ -157,15 +134,9 @@ namespace celix { * using this function for attribute key "key1" on the filter "(key1=value)" yields false. * using this function for attribute key "key1" on the filter "(|(!(key1=*))(key2=value2))" yields false. */ -#if __cplusplus >= 201703L //C++17 or higher - bool hasMandatoryNegatedPresenceAttribute(std::string_view attributeKey) const { - return celix_filter_hasMandatoryNegatedPresenceAttribute(cFilter.get(), attributeKey.data()); - } -#else bool hasMandatoryNegatedPresenceAttribute(const std::string& attributeKey) const { return celix_filter_hasMandatoryNegatedPresenceAttribute(cFilter.get(), attributeKey.data()); } -#endif /** * @brief Get the underlining C filter object. diff --git a/libs/utils/include/celix/Utils.h b/libs/utils/include/celix/Utils.h index 8eb25f61..08cd9ba5 100644 --- a/libs/utils/include/celix/Utils.h +++ b/libs/utils/include/celix/Utils.h @@ -102,124 +102,7 @@ namespace celix { } return result; } -} - -#if __cplusplus >= 201703L //C++17 or higher -namespace celix::impl { - - template<typename T> - constexpr typename std::enable_if_t<std::is_constructible_v<std::string, T>, bool> - canBeConstructedWithString() { return true; } - - template<typename T> - constexpr typename std::enable_if_t<not std::is_constructible_v<std::string, T>, bool> - canBeConstructedWithString() { return false; } - - template<typename T> - constexpr typename std::enable_if_t<std::is_member_object_pointer_v<decltype(&T::NAME)>, bool> - isNameMemberStatic() { return false; } - - template<typename T> - constexpr typename std::enable_if_t<!std::is_member_object_pointer_v<decltype(&T::NAME)>, bool> - isNameMemberStatic() { return canBeConstructedWithString<decltype(T::NAME)>(); } - - template<typename, typename = void> - constexpr bool hasStaticMemberName = false; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-value" - /** - * Partial specialization only possible (and chosen) when late binding of decltype succeeds -> - * i.e. when T::NAME exists. - * note T::NAME is unused, so suppressing unused-value warning - */ - template<typename T> - constexpr bool hasStaticMemberName<T, decltype(T::NAME,void())> = isNameMemberStatic<T>(); -#pragma GCC diagnostic pop - - template<typename T> - constexpr typename std::enable_if_t<std::is_member_object_pointer_v<decltype(&T::VERSION)>, bool> - isVersionMemberStatic() { return false; } - - template<typename T> - constexpr typename std::enable_if_t<not std::is_member_object_pointer_v<decltype(&T::VERSION)>, bool> - isVersionMemberStatic() { return canBeConstructedWithString<decltype(T::VERSION)>(); } - - template<typename, typename = void> - constexpr bool hasStaticMemberVersion = false; - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-value" - /** - * Partial specialization only possible (and chosen) when late binding of decltype succeeds -> - * i.e. when T::VERSION exists. - * note T::VERSION is unused, so suppressing unused-value warning - */ - template<typename T> - constexpr bool hasStaticMemberVersion<T, decltype(T::VERSION,void())> = isVersionMemberStatic<T>(); -#pragma GCC diagnostic pop -} - -namespace celix { - /** - * @brief Returns the inferred type name for the template I if the providedTypeName is empty. - * - * If the a non empty providedTypeName is provided this will be returned. - * If the provideTypeName is empty and a static constexpr and accessible member I::NAME exists, - * that will be returned. - * Otherwise the celix::impl::typeName will be used to infer the type name. - * celix::impl::typeName uses the macro __PRETTY_FUNCTION__ to extract a type name. - */ - template<typename I> - std::string typeName(std::string_view providedTypeName = "") { - if (!providedTypeName.empty()) { - return std::string{providedTypeName}; - } else if constexpr (celix::impl::hasStaticMemberName<I>) { - return std::string{I::NAME}; - } else { - return celix::impl::extractTypeName<I>(); - } - } - - /** - * @brief Returns the inferred cmp type name for the template T if the providedCmpTypeName is empty. - * - * If the a non empty providedCmpTypeName is provided this will be returned. - * Otherwise the celix::impl::typeName will be used to infer the type name. - * celix::impl::typeName uses the macro __PRETTY_FUNCTION__ to extract a type name. - */ - template<typename T> - std::string cmpTypeName(std::string_view providedCmpTypeName = "") { - if (!providedCmpTypeName.empty()) { - return std::string{providedCmpTypeName}; - } else { - return celix::impl::extractTypeName<T>(); - } - } - - /** - * @brief Returns the inferred type version for the template I if the providedVersion is empty. - * - * If the a non empty providedVersion is provided this will be returned. - * If the providedVersion is empty and a static constexpr and accessible member I::VERSION exists, - * that will be returned. - * Otherwise a empty string will be returned. - */ - template<typename I> - std::string typeVersion(std::string_view providedVersion = "") { - if (!providedVersion.empty()) { - return std::string{providedVersion}; - } else if constexpr (celix::impl::hasStaticMemberVersion<I>) { - return std::string{I::VERSION}; - } else { - return ""; - } - } -} - -#else //Assuming at least C++11 - -namespace celix { /** * @brief Returns the inferred type name for the template I if the providedTypeName is empty. * @@ -269,6 +152,4 @@ namespace celix { } } -#endif - #undef CELIX_RTTI_ENABLED \ No newline at end of file
