Skip to content

Commit

Permalink
- added CMake option to make creation of benchmark targets optional (…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
acki-m committed Dec 22, 2015
1 parent e9dc1fa commit b2b3466
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CMake/3rd_party_libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
1 change: 1 addition & 0 deletions doc/md_pages/building_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
6 changes: 3 additions & 3 deletions doc/md_pages/tutorial/default_arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 31 additions & 3 deletions doc/md_pages/tutorial/register_classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_<T>::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
Expand All @@ -108,11 +112,13 @@ RTTR_REGISTRATION
registration::class_<Foo>("Foo")
.constructor<>()
.constructor<int,double>()
.constructor<const std::string&>();
.constructor<const std::string&>()
.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
-------------------------
Expand Down Expand Up @@ -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<T>`.

~~~~{.cpp}
int main()
{
std::shared_ptr<test_class> obj = std::make_shared<test_class>(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<T> "wrapper_mapper<T>".

Set/Get property of a class
---------------------------
Properties can be also set and get in two steps:
Expand All @@ -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.

<hr>
Expand Down
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@

add_subdirectory (rttr)
add_subdirectory (unit_tests)
add_subdirectory (benchmarks)

if (${BUILD_BENCHMARKS})
add_subdirectory (benchmarks)
endif()
2 changes: 2 additions & 0 deletions src/rttr/registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class RTTR_API registration
* \param level The access level of the constructor; default is: registration::public_access.<br>
* (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.
Expand Down

0 comments on commit b2b3466

Please sign in to comment.