From b2b3466554af194b402c272f4366c1e139367f86 Mon Sep 17 00:00:00 2001 From: Axel Menzel Date: Tue, 22 Dec 2015 22:49:11 +0100 Subject: [PATCH] - added CMake option to make creation of benchmark targets optional (Default: TRUE, The benchmarks will be created) - adjusted README links (without www, the website will not correctly forward) - showed in the class docu, how methods can be invoked with wrapper types - made clear in the docu, what policy is used when registering a constructor --- CMake/3rd_party_libs.cmake | 3 ++ CMakeLists.txt | 3 +- README.md | 2 +- doc/md_pages/building_install.md | 1 + doc/md_pages/tutorial/default_arguments.md | 6 ++-- doc/md_pages/tutorial/register_classes.md | 34 ++++++++++++++++++++-- src/CMakeLists.txt | 5 +++- src/rttr/registration.h | 2 ++ 8 files changed, 47 insertions(+), 9 deletions(-) diff --git a/CMake/3rd_party_libs.cmake b/CMake/3rd_party_libs.cmake index 48973867..76c5d7e1 100644 --- a/CMake/3rd_party_libs.cmake +++ b/CMake/3rd_party_libs.cmake @@ -34,6 +34,9 @@ MESSAGE(STATUS ${LIBRARY_OUTPUT_DIRECTORY}) MESSAGE(STATUS "Finding 3rd party libs...") MESSAGE(STATUS "===========================") +# there is a the moment a problem with finding multiple versions of boost, +# i.e. the static AND the static runtime version; that is not possible atm. +# Because of that, the benchmarks cannot be build with the static runtime lib option enabled set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_RUNTIME OFF) set(BOOST_ALL_DYN_LINK OFF) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93c173b7..d64ee41f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,11 +50,12 @@ include(utility) option(BUILD_STATIC "Build RTTR as static library" FALSE) option(BUILD_WITH_STATIC_RUNTIME_LIBS "Link against the static runtime libraries" FALSE) option(BUILD_WITH_RTTI "Enable build with C++ runtime type information for compilation" TRUE) +option(BUILD_BENCHMARKS "Enable this to build the benchmarks" TRUE) option(USE_PCH "Use precompiled header files for compilation" TRUE) option(CUSTOM_DOXYGEN_STYLE "Enable this option to use a custom doxygen style for HTML documentation; Otherwise the default will be used" TRUE) option(BUILD_WEBSITE_DOCU "Enable this option to create the special docu for the website" FALSE) -# one precompiled headers cannot be used for multipleninja targets +# one precompiled headers cannot be used for multiple ninja targets # thats why we have to disable this option, when BUILD_STATIC or # BUILD_WITH_STATIC_RUNTIME_LIBS is ON (every target will create the same PCH.pch file) # to get it working, we need the feature to enable different source properties diff --git a/README.md b/README.md index 5ce568b4..69391204 100644 --- a/README.md +++ b/README.md @@ -105,4 +105,4 @@ The installation guide can be found [here](http://www.rttr.org/doc/rttr-0-9-5/bu Get Started: ------------ -Take a look at the [documentation](http://rttr.org/doc/rttr-0-9-5/classes.html) or start with the [tutorial](http://rttr.org/doc/rttr-0-9-5/tutorial_page.html). +Take a look at the [documentation](http://www.rttr.org/doc/rttr-0-9-5/classes.html) or start with the [tutorial](http://www.rttr.org/doc/rttr-0-9-5/tutorial_page.html). diff --git a/doc/md_pages/building_install.md b/doc/md_pages/building_install.md index 2156bdb2..817db985 100644 --- a/doc/md_pages/building_install.md +++ b/doc/md_pages/building_install.md @@ -34,6 +34,7 @@ The build of RTTR can be configured at CMake configuration time with following v - `BUILD_STATIC`: Build RTTR as static library; Default: `FALSE` - `BUILD_WITH_STATIC_RUNTIME_LIBS`: Link against the static runtime libraries; Default: `FALSE` - `BUILD_WITH_RTTI`: Enable the C++ language feature for runtime type information (RTTI); Default: `TRUE` +- `BUILD_BENCHMARKS`: Enable this to build the benchmarks; Default: `TRUE` - `USE_PCH`: Use precompiled header files for compilation; Default: `TRUE`* - `CUSTOM_DOXYGEN_STYLE`: Enable this option to use a custom doxygen style for HTML documentation; Otherwise the default will be used; Default: `TRUE` diff --git a/doc/md_pages/tutorial/default_arguments.md b/doc/md_pages/tutorial/default_arguments.md index b0f815b6..a4e0752f 100644 --- a/doc/md_pages/tutorial/default_arguments.md +++ b/doc/md_pages/tutorial/default_arguments.md @@ -16,9 +16,9 @@ void my_function(int a, bool b, const std::string& text, const int* ptr); RTTR_REGISTRATION { registration::method("my_function", &my_function) - ( - default_arguments(true, std::string("default text"), nullptr) - ); + ( + default_arguments(true, std::string("default text"), nullptr) + ); } \endcode diff --git a/doc/md_pages/tutorial/register_classes.md b/doc/md_pages/tutorial/register_classes.md index 6153e4a0..ef17f817 100644 --- a/doc/md_pages/tutorial/register_classes.md +++ b/doc/md_pages/tutorial/register_classes.md @@ -94,11 +94,15 @@ struct Foo Foo(); Foo(int, double); Foo(const std::string&); + + static Foo* create(); }; ~~~~ -For registering these constructors you now have to specify every parameter as template parameter +For registering three `Foo` constructors you now have to specify every parameter as template parameter in the member function @ref rttr::registration::class_::constructor() "constructor()". +As second option, it is possible to register a static function as constructor. +In order to do this, just forward the function pointer. ~~~~{.cpp} RTTR_REGISTRATION @@ -108,11 +112,13 @@ RTTR_REGISTRATION registration::class_("Foo") .constructor<>() .constructor() - .constructor(); + .constructor() + .constructor(&Foo::create); } ~~~~ When a constructor is registered a destructor is registered automatically. +The used default policy for creating an instance is @ref rttr::policy::ctor::as_object "policy::ctor::as_object". Register class properties ------------------------- @@ -299,6 +305,28 @@ int main() } ~~~~ +It is possible to invoke a method, when the instance is wrapped inside a wrapper class, for example `std::shared_ptr`. + +~~~~{.cpp} +int main() +{ + std::shared_ptr obj = std::make_shared(23); + + method meth = type::get_by_name("test_class").get_method("print_value"); + + method.invoke(obj); // successful invoke + method.invoke(obj.get()); // successful invoke + method.invoke(*obj.get()); // successful invoke + + variant var = obj; + // or use the variant + method.invoke(var); // successful invoke + + return 0; +} +~~~~ +When you want to use RTTR with a custom wrapper type, you have provide a specialization of the class template @ref rttr::wrapper_mapper "wrapper_mapper". + Set/Get property of a class --------------------------- Properties can be also set and get in two steps: @@ -322,7 +350,7 @@ int main() ~~~~ In difference to the global properties, a valid \ref type object and an instance (object) of the class is now needed to set and get the value. -It doesn't matter in what hierarchy level the object is. Or if its a pointer, an object on the stack or wrapped inside a variant. +It doesn't matter in what hierarchy level the object is or if its a pointer, an object on the stack or wrapped inside a variant. RTTR will try to cast the given object to the class type where the property was registered to.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d6b6c1ae..4f58afd7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,4 +32,7 @@ add_subdirectory (rttr) add_subdirectory (unit_tests) -add_subdirectory (benchmarks) + +if (${BUILD_BENCHMARKS}) + add_subdirectory (benchmarks) +endif() diff --git a/src/rttr/registration.h b/src/rttr/registration.h index 3e7da3a5..b09accaa 100644 --- a/src/rttr/registration.h +++ b/src/rttr/registration.h @@ -153,6 +153,8 @@ class RTTR_API registration * \param level The access level of the constructor; default is: registration::public_access.
* (can be also: registration::protected_access or registration::private_access) * + * \remark The default constructor create policy is: \ref policy::ctor::as_object. + * * \see constructor, type::get_constructor(), type::create() * * \return A \ref bind object, in order to chain more calls.