diff --git a/CMakeLists.txt b/CMakeLists.txt index 1af95a8c..76fb4f58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ option(BUILD_PACKAGE "Enable this to build the installer" ON) option(USE_PCH "Use precompiled header files for compilation" ON) option(CUSTOM_DOXYGEN_STYLE "Enable this option to use a custom doxygen style for HTML documentation; Otherwise the default will be used" ON) option(BUILD_WEBSITE_DOCU "Enable this option to create the special docu for the website" OFF) +option(USE_LATEST_STD "Build the library using the latest std-library fetures and making it probably not backward compatible." OFF) # one precompiled headers cannot be used for multiple ninja targets # thats why we have to disable this option, when BUILD_STATIC or diff --git a/src/examples/scripting/chaiscript_visitor.h b/src/examples/scripting/chaiscript_visitor.h index a43a64ff..c02214a9 100644 --- a/src/examples/scripting/chaiscript_visitor.h +++ b/src/examples/scripting/chaiscript_visitor.h @@ -81,7 +81,7 @@ class chaiscript_visitor : public rttr::visitor template void visit_global_method(const method_info& info) { - m_chai.add(chaiscript::fun(info.function_ptr), info.method_item.get_name().to_string()); + m_chai.add(chaiscript::fun(info.function_ptr), std::string(info.method_item.get_name())); } ///////////////////////////////////////////////////////////////////////////////////// @@ -89,7 +89,7 @@ class chaiscript_visitor : public rttr::visitor template void visit_method(const method_info& info) { - m_chai.add(chaiscript::fun(info.function_ptr), info.method_item.get_name().to_string()); + m_chai.add(chaiscript::fun(info.function_ptr), std::string(info.method_item.get_name())); } ///////////////////////////////////////////////////////////////////////////////////// @@ -97,20 +97,20 @@ class chaiscript_visitor : public rttr::visitor template void visit_property(const property_info& info) { - m_chai.add(chaiscript::fun(info.property_accessor), info.property_item.get_name().to_string()); + m_chai.add(chaiscript::fun(info.property_accessor), std::string(info.property_item.get_name())); } template void visit_getter_setter_property(const property_getter_setter_info& info) { - m_chai.add(chaiscript::fun(info.property_getter), std::string("get_") + info.property_item.get_name().to_string()); - m_chai.add(chaiscript::fun(info.property_setter), std::string("set_") + info.property_item.get_name().to_string()); + m_chai.add(chaiscript::fun(info.property_getter), std::string("get_") + std::string(info.property_item.get_name())); + m_chai.add(chaiscript::fun(info.property_setter), std::string("set_") + std::string(info.property_item.get_name())); } template void visit_readonly_property(const property_info& info) { - m_chai.add(chaiscript::fun(info.property_accessor), info.property_item.get_name().to_string()); + m_chai.add(chaiscript::fun(info.property_accessor), std::string(info.property_item.get_name())); } ///////////////////////////////////////////////////////////////////////////////////// @@ -119,7 +119,7 @@ class chaiscript_visitor : public rttr::visitor template static std::string get_type_name() { - return rttr::type::template get().get_name().to_string(); + return std::string(rttr::type::template get().get_name()); } private: diff --git a/src/rttr/CMakeLists.txt b/src/rttr/CMakeLists.txt index fc656457..5fd73e9a 100644 --- a/src/rttr/CMakeLists.txt +++ b/src/rttr/CMakeLists.txt @@ -39,6 +39,16 @@ if (USE_PCH) activate_precompiled_headers("detail/base/pch.h" SRC_FILES) endif() +# Determine the minium required standard. +if (USE_LATEST_STD) + if (MAX_CXX_STANDARD GREATER_EQUAL 17) + list(APPEND COMPILE_DEFS "RTTR_USE_STD_STRING_VIEW") + set(MIN_CXX_STANDARD cxx_std_17) + endif () +else () + set(MIN_CXX_STANDARD cxx_std_11) # at least c++11 is needed to compile RTTR +endif () + if (${BUILD_RTTR_DYNAMIC}) add_library(rttr_core SHARED ${UnityBuild} ${SRC_FILES} ${HPP_FILES}) add_library(RTTR::Core ALIAS rttr_core) @@ -46,8 +56,6 @@ if (${BUILD_RTTR_DYNAMIC}) target_compile_definitions(rttr_core PRIVATE RTTR_DLL_EXPORTS) target_compile_definitions(rttr_core PUBLIC RTTR_DLL) - - set_target_properties(rttr_core PROPERTIES VERSION ${RTTR_VERSION} SOVERSION ${RTTR_VERSION} EXPORT_NAME Core @@ -55,12 +63,14 @@ if (${BUILD_RTTR_DYNAMIC}) CXX_STANDARD ${MAX_CXX_STANDARD} CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1) - + + target_compile_definitions(rttr_core PUBLIC ${COMPILE_DEFS}) + target_link_libraries(rttr_core PRIVATE ${CMAKE_DL_LIBS}) if(${CMAKE_VERSION} VERSION_GREATER "3.8.0") - target_compile_features(rttr_core PUBLIC cxx_std_11) # at least c++11 is needed to compile RTTR + target_compile_features(rttr_core PUBLIC ${MIN_CXX_STANDARD}) endif() target_include_directories(rttr_core PUBLIC @@ -94,7 +104,9 @@ if (BUILD_STATIC) EXPORT_NAME Core_Lib CXX_STANDARD ${MAX_CXX_STANDARD} DEBUG_POSTFIX ${RTTR_DEBUG_POSTFIX}) - + + target_compile_definitions(rttr_core PUBLIC ${COMPILE_DEFS}) + target_link_libraries(rttr_core_lib PRIVATE ${CMAKE_DL_LIBS}) if (MSVC) @@ -139,6 +151,8 @@ if (BUILD_WITH_STATIC_RUNTIME_LIBS) $ $) + target_compile_definitions(rttr_core PUBLIC ${COMPILE_DEFS}) + target_link_libraries(rttr_core_s PRIVATE ${CMAKE_DL_LIBS}) set_target_properties(rttr_core_s PROPERTIES diff --git a/src/rttr/detail/base/core_prerequisites.h b/src/rttr/detail/base/core_prerequisites.h index f60d91c3..ccf053af 100644 --- a/src/rttr/detail/base/core_prerequisites.h +++ b/src/rttr/detail/base/core_prerequisites.h @@ -278,6 +278,9 @@ namespace rttr # define RTTR_END_DISABLE_OVERRIDE_WARNING #endif +# define RTTR_BEGIN_DISABLE_SELF_ASSIGN_OVERLOADED_WARNING +# define RTTR_END_DISABLE_SELF_ASSIGN_OVERLOADED_WARNING + # define RTTR_DECLARE_PLUGIN_CTOR __attribute__((constructor)) # define RTTR_DECLARE_PLUGIN_DTOR __attribute__((destructor)) @@ -316,6 +319,15 @@ namespace rttr # define RTTR_DECLARE_PLUGIN_CTOR __attribute__((__constructor__)) # define RTTR_DECLARE_PLUGIN_DTOR __attribute__((__destructor__)) +#if defined(__has_warning) && __has_warning("-Wself-assign-overloaded") +# define RTTR_BEGIN_DISABLE_SELF_ASSIGN_OVERLOADED_WARNING _Pragma ("clang diagnostic push") \ + _Pragma ("clang diagnostic ignored \"-Wself-assign-overloaded\"") +# define RTTR_END_DISABLE_SELF_ASSIGN_OVERLOADED_WARNING _Pragma ("clang diagnostic pop") +#else +# define RTTR_BEGIN_DISABLE_SELF_ASSIGN_OVERLOADED_WARNING +# define RTTR_END_DISABLE_SELF_ASSIGN_OVERLOADED_WARNING +#endif + #elif RTTR_COMPILER == RTTR_COMPILER_MSVC # define RTTR_BEGIN_DISABLE_DEPRECATED_WARNING __pragma( warning( push )) \ __pragma( warning( disable: 4996)) @@ -332,11 +344,23 @@ namespace rttr # define RTTR_DECLARE_PLUGIN_DTOR # define RTTR_BEGIN_DISABLE_OVERRIDE_WARNING # define RTTR_END_DISABLE_OVERRIDE_WARNING - +# define RTTR_BEGIN_DISABLE_SELF_ASSIGN_OVERLOADED_WARNING +# define RTTR_END_DISABLE_SELF_ASSIGN_OVERLOADED_WARNING #else # pragma message("WARNING: unknown compiler, don't know how to disable deprecated warnings") #endif +///////////////////////////////////////////////////////////////////////////////////////// +// Enable some C++17 Features +///////////////////////////////////////////////////////////////////////////////////////// +#ifdef RTTR_USE_STD_STRING_VIEW + #if __cplusplus >= 201703L + #define RTTR_ENABLE_STD_STRING_VIEW + #else + #error "Linking with this library needs C++17, as std::string_view is required." + #endif +#endif + } // end namespace rttr #endif // RTTR_CORE_PREREQUISITES_H_ diff --git a/src/rttr/detail/constructor/constructor_wrapper_base.cpp b/src/rttr/detail/constructor/constructor_wrapper_base.cpp index 6f0422be..94722b47 100644 --- a/src/rttr/detail/constructor/constructor_wrapper_base.cpp +++ b/src/rttr/detail/constructor/constructor_wrapper_base.cpp @@ -77,12 +77,12 @@ void constructor_wrapper_base::create_signature_string() RTTR_NOEXCEPT return; auto param_info_list = get_parameter_infos(); - m_signature = get_instantiated_type().get_raw_type().get_name().to_string() + "( "; + m_signature = string(get_instantiated_type().get_raw_type().get_name()) + "( "; auto ref_list = get_is_reference(); auto const_list = get_is_const(); for (const auto& param : param_info_list) { - m_signature += param.get_type().get_name() + string(is_const_list[const_list[param.get_index()]]) + string(is_ref_list[ref_list[param.get_index()]]); + m_signature += string(param.get_type().get_name()) + string(is_const_list[const_list[param.get_index()]]) + string(is_ref_list[ref_list[param.get_index()]]); if (param.get_index() < param_info_list.size() - 1) m_signature += ", "; } diff --git a/src/rttr/detail/impl/array_range_impl.h b/src/rttr/detail/impl/array_range_impl.h index 1119f46b..b350b01d 100644 --- a/src/rttr/detail/impl/array_range_impl.h +++ b/src/rttr/detail/impl/array_range_impl.h @@ -32,6 +32,7 @@ #include "rttr/property.h" #include "rttr/type.h" #include +#include namespace rttr { diff --git a/src/rttr/detail/impl/string_view_impl.h b/src/rttr/detail/impl/string_view_impl.h index 1329cbaa..4650bec7 100644 --- a/src/rttr/detail/impl/string_view_impl.h +++ b/src/rttr/detail/impl/string_view_impl.h @@ -268,15 +268,6 @@ basic_string_view::operator std::basic_string -template -std::basic_string basic_string_view::to_string(const Allocator& a) const -{ - return std::basic_string(begin(), end(), a); -} - -///////////////////////////////////////////////////////////////////////////////////////// - template RTTR_CXX14_CONSTEXPR int basic_string_view::compare(basic_string_view v) const RTTR_NOEXCEPT { @@ -586,14 +577,14 @@ template RTTR_INLINE std::basic_string operator+(basic_string_view lhs, const std::basic_string& rhs) { - return (lhs.to_string() + rhs); + return (std::string(lhs) + rhs); } template RTTR_INLINE std::basic_string operator+(const std::basic_string& lhs, basic_string_view rhs) { - return (lhs + rhs.to_string()); + return (lhs + std::string(rhs)); } template diff --git a/src/rttr/detail/library/library_unix.cpp b/src/rttr/detail/library/library_unix.cpp index 7c8393b6..5a1278b6 100644 --- a/src/rttr/detail/library/library_unix.cpp +++ b/src/rttr/detail/library/library_unix.cpp @@ -37,6 +37,8 @@ #include #include +using namespace std; + namespace { @@ -91,7 +93,7 @@ static rttr::string_view get_error() { using namespace rttr; auto err = dlerror(); - return err ? string_view(err): string_view(); + return err ? rttr::string_view(err): rttr::string_view(); } } // end namespace anonymous @@ -146,7 +148,7 @@ bool library_private::load_native() if (!m_handle) { - m_error_string = "Cannot load library " + m_file_name + " " + get_error(); + m_error_string = "Cannot load library " + m_file_name + " " + string(get_error()); } else { @@ -163,7 +165,7 @@ bool library_private::unload_native() { if (dlclose(m_handle)) { - m_error_string = "Cannot unload library: '" + m_file_name + "'" + get_error(); + m_error_string = "Cannot unload library: '" + m_file_name + "'" + string(get_error()); return false; } diff --git a/src/rttr/detail/method/method_wrapper_base.cpp b/src/rttr/detail/method/method_wrapper_base.cpp index 5ce98b2b..b5e76cf6 100644 --- a/src/rttr/detail/method/method_wrapper_base.cpp +++ b/src/rttr/detail/method/method_wrapper_base.cpp @@ -100,7 +100,7 @@ void method_wrapper_base::create_signature_string() RTTR_NOEXCEPT auto const_list = get_is_const(); for (const auto& param : param_list) { - m_signature += param.get_type().get_name().to_string() + string(is_const_list[const_list[param.get_index()]]) + string(is_ref_list[ref_list[param.get_index()]]); + m_signature += string(param.get_type().get_name()) + string(is_const_list[const_list[param.get_index()]]) + string(is_ref_list[ref_list[param.get_index()]]); if (param.get_index() < param_list.size() - 1) m_signature += ", "; } diff --git a/src/rttr/detail/type/type_data.h b/src/rttr/detail/type/type_data.h index 927f9c29..07459643 100644 --- a/src/rttr/detail/type/type_data.h +++ b/src/rttr/detail/type/type_data.h @@ -304,7 +304,7 @@ RTTR_LOCAL std::unique_ptr make_type_data() raw_type_info::get_type().m_type_data, wrapper_type_info::get_type().m_type_data, array_raw_type::get_type().m_type_data, - ::rttr::detail::get_type_name().to_string(), ::rttr::detail::get_type_name(), + std::string{::rttr::detail::get_type_name()}, ::rttr::detail::get_type_name(), get_size_of::value(), pointer_count::value, diff --git a/src/rttr/detail/type/type_register.cpp b/src/rttr/detail/type/type_register.cpp index 25181117..dc4e318f 100644 --- a/src/rttr/detail/type/type_register.cpp +++ b/src/rttr/detail/type/type_register.cpp @@ -396,7 +396,7 @@ static void move_pointer_and_ref_to_type(std::string& type_name) static std::string normalize_orig_name(string_view name) { - std::string normalized_name = name.to_string(); + std::string normalized_name(name); move_pointer_and_ref_to_type(normalized_name); return normalized_name; @@ -695,7 +695,7 @@ std::string type_register_private::derive_name(const type& t) auto custom_name = t.get_raw_array_type().get_name(); auto raw_name_orig = normalize_orig_name( t.get_raw_array_type().get_full_name()); - return derive_name_impl(src_name_orig, raw_name_orig, custom_name.to_string()); + return derive_name_impl(src_name_orig, raw_name_orig, string(custom_name)); } else if (t != t.get_raw_type()) { @@ -703,7 +703,7 @@ std::string type_register_private::derive_name(const type& t) auto custom_name = t.get_raw_type().get_name(); auto raw_name_orig = normalize_orig_name( t.get_raw_type().get_full_name()); - return derive_name_impl(src_name_orig, raw_name_orig, custom_name.to_string()); + return derive_name_impl(src_name_orig, raw_name_orig, string(custom_name)); } else { @@ -718,7 +718,7 @@ void type_register_private::register_custom_name(type& t, string_view custom_nam if (!t.is_valid()) return; - update_custom_name(custom_name.to_string(), t); + update_custom_name(string(custom_name), t); // we have to make a copy of the list, because we also perform an insertion with 'update_custom_name' auto tmp_type_list = m_custom_name_to_id.value_data(); diff --git a/src/rttr/detail/variant/variant_data_converter.h b/src/rttr/detail/variant/variant_data_converter.h index d0e94e4a..b481d1cc 100644 --- a/src/rttr/detail/variant/variant_data_converter.h +++ b/src/rttr/detail/variant/variant_data_converter.h @@ -1431,7 +1431,7 @@ struct convert_from_enum static RTTR_INLINE bool to(const T& from, std::string& to) { - to = get_enumeration_name(from).to_string(); + to = std::string(get_enumeration_name(from)); return (to.empty() == false); } diff --git a/src/rttr/library.cpp b/src/rttr/library.cpp index 55b70ffa..e5ba60d8 100644 --- a/src/rttr/library.cpp +++ b/src/rttr/library.cpp @@ -51,7 +51,7 @@ class library_manager auto& manager = get_instance(); std::lock_guard lock(manager.m_library_mutex); - auto file_as_string = file_name.to_string(); + std::string file_as_string(file_name); auto itr = manager.m_library_map.find(file_as_string); if (itr != manager.m_library_map.end()) return itr->second; @@ -73,7 +73,7 @@ class library_manager auto& manager = get_instance(); std::lock_guard lock(manager.m_library_mutex); - auto itr = manager.m_library_map.find(item->get_file_name().to_string()); // because we use string_view to find the item + auto itr = manager.m_library_map.find(std::string(item->get_file_name())); // because we use string_view to find the item if (itr != manager.m_library_map.end()) manager.m_library_map.erase(itr); } diff --git a/src/rttr/string_view.h b/src/rttr/string_view.h index cda8d509..4a7fffd3 100644 --- a/src/rttr/string_view.h +++ b/src/rttr/string_view.h @@ -30,13 +30,22 @@ #define RTTR_STRING_VIEW_H_ #include "rttr/detail/base/core_prerequisites.h" - #include -#include +#ifdef RTTR_ENABLE_STD_STRING_VIEW + +#include namespace rttr { + template + using basic_string_view = std::basic_string_view; + using string_view = basic_string_view; +} + +#else +namespace rttr +{ /*! * The class template \ref basic_string_view describes an non-owning reference to a * constant contiguous sequence of char-like objects. @@ -247,14 +256,6 @@ class basic_string_view template explicit operator std::basic_string() const; - /*! - * \brief Creates a `basic_string` with a copy of the content of the current view. - * - * \return A `basic_string` containing a copy of the characters of the current view. - */ - template > - std::basic_string to_string(const Allocator& a = Allocator()) const; - /*! * \brief The function compares the two views by calling `Traits::compare(data(), v.data(), length)`, * where \p length is the small of `size()` and `v.size()`. @@ -497,4 +498,5 @@ using string_view = basic_string_view; #include "rttr/detail/impl/string_view_impl.h" +#endif // RTTR_ENABLE_STD_STRING_VIEW #endif // RTTR_STRING_VIEW_H_ diff --git a/src/rttr/type.cpp b/src/rttr/type.cpp index 77aa4514..f445a33a 100644 --- a/src/rttr/type.cpp +++ b/src/rttr/type.cpp @@ -478,7 +478,7 @@ variant type::invoke(string_view name, std::vector args) type type::get_by_name(string_view name) RTTR_NOEXCEPT { auto& custom_name_to_id = detail::type_register_private::get_instance().get_custom_name_to_id(); - auto ret = custom_name_to_id.find(name); + auto ret = custom_name_to_id.find(std::string(name)); if (ret != custom_name_to_id.end()) return (*ret); diff --git a/src/unit_tests/method/test_method_reflection.cpp b/src/unit_tests/method/test_method_reflection.cpp index a6843874..1f319ee0 100644 --- a/src/unit_tests/method/test_method_reflection.cpp +++ b/src/unit_tests/method/test_method_reflection.cpp @@ -418,7 +418,7 @@ TEST_CASE("Test method signature", "[method]") REQUIRE(methods.size() == 22); REQUIRE(methods[0].get_signature() == "method_1( )"); - REQUIRE(methods[3].get_signature() == std::string("method_4( ") + type::get().get_name() + " & )"); + REQUIRE(methods[3].get_signature() == std::string("method_4( ") + std::string(type::get().get_name()) + " & )"); REQUIRE(methods[4].get_signature() == "method_5( double* )"); REQUIRE(methods[5].get_signature() == "method_5( int, double )"); REQUIRE(methods[21].get_signature() == "method_13( )"); diff --git a/src/unit_tests/misc/library_test.cpp b/src/unit_tests/misc/library_test.cpp index f7e71c4e..c44e3b9a 100644 --- a/src/unit_tests/misc/library_test.cpp +++ b/src/unit_tests/misc/library_test.cpp @@ -97,11 +97,11 @@ TEST_CASE("library - load", "[library]") SECTION("load with suffix") { #if RTTR_PLATFORM == RTTR_PLATFORM_WINDOWS - library lib(library_name + std::string(".dll")); + library lib(std::string(library_name) + std::string(".dll")); #elif RTTR_PLATFORM == RTTR_PLATFORM_LINUX - library lib(library_name + std::string(".so")); + library lib(std::string(library_name) + std::string(".so")); #elif RTTR_PLATFORM == RTTR_PLATFORM_APPLE - library lib(library_name + std::string(".dylib")); + library lib(std::string(library_name) + std::string(".dylib")); #else #error "Don't know library suffix on this plattform!" #endif diff --git a/src/unit_tests/misc/string_view_test.cpp b/src/unit_tests/misc/string_view_test.cpp index 43cc83cc..f75f03d3 100644 --- a/src/unit_tests/misc/string_view_test.cpp +++ b/src/unit_tests/misc/string_view_test.cpp @@ -215,7 +215,7 @@ TEST_CASE("string_view - std::string operator()", "[string_view]") TEST_CASE("string_view - to_string", "[string_view]") { string_view text = "Hello World"; - std::string string_value = text.to_string(); + std::string string_value(text); CHECK(string_value == "Hello World"); } diff --git a/src/unit_tests/variant/variant_assign_test.cpp b/src/unit_tests/variant/variant_assign_test.cpp index 4f6509d7..24ae77dd 100644 --- a/src/unit_tests/variant/variant_assign_test.cpp +++ b/src/unit_tests/variant/variant_assign_test.cpp @@ -153,7 +153,10 @@ TEST_CASE("variant::operator=() - self assignment", "[variant]") SECTION("self assign - empty") { variant a; + + RTTR_BEGIN_DISABLE_SELF_ASSIGN_OVERLOADED_WARNING a = a; + RTTR_END_DISABLE_SELF_ASSIGN_OVERLOADED_WARNING CHECK(a.is_valid() == false); } @@ -161,7 +164,10 @@ TEST_CASE("variant::operator=() - self assignment", "[variant]") SECTION("self assign - full") { variant a = 1; + + RTTR_BEGIN_DISABLE_SELF_ASSIGN_OVERLOADED_WARNING a = a; + RTTR_END_DISABLE_SELF_ASSIGN_OVERLOADED_WARNING CHECK(a.is_valid() == true); }