This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REGISTER_CLASS(SomeClass, (fct_1)(fct_2)(fct_3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! macro to convert any kind of value to string | |
#define __REFLEX_TO_STRING(val) #val | |
//! macro called for each member function to build a pair of <string, member_function_pointer> | |
#define __REFLEX_MAKE_REGISTERABLE_FUNCTION(r, type, i, function) \ | |
BOOST_PP_COMMA_IF(i) std::make_pair(std::string(__REFLEX_TO_STRING(function)), &type::function) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! main macro who build the static variable | |
#define REGISTER_CLASS(type, functions) \ | |
static reflectable<type> \ | |
reflectable_##type(#type, BOOST_PP_SEQ_FOR_EACH_I( __REFLEX_MAKE_REGISTERABLE_FUNCTION, \ | |
type, \ | |
functions )); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! macro to convert any kind of value to string | |
#define __REFLEX_TO_STRING(val) #val | |
//! macro called for each member function to build a pair of <string, member_function_pointer> | |
#define __REFLEX_MAKE_REGISTERABLE_FUNCTION(r, type, i, function) \ | |
BOOST_PP_COMMA_IF(i) std::make_pair(std::string(__REFLEX_TO_STRING(function)), &type::function) | |
//! main macro who build the static variable | |
#define REGISTER_CLASS(type, functions) \ | |
static reflectable<type> \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static reflectable<SomeClass> register_some_class("SomeClass", | |
std::make_pair(std::string("some_fct_1"), &SomeClass::some_fct_1), | |
std::make_pair(std::string("some_fct_2"), &SomeClass::some_fct_2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename ReturnType, typename... Params> | |
struct reflection_maker; | |
template <typename ReturnType, typename... Params> | |
struct reflection_maker<ReturnType(Params...)> { | |
static ReturnType invoke(const std::string& class_name, const std::string& function_name, Params... params) { | |
return reflection_manager::get_instance().reflect<ReturnType, Params...>(class_name, function_name, params...); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class reflection_manager { | |
public: | |
~reflection_manager(void) = default; | |
reflection_manager(const reflection_manager&) = delete; | |
reflection_manager& operator=(const reflection_manager&) = delete; | |
static reflection_manager& get_instance(void) { | |
static reflection_manager instance; | |
return instance; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! register specific member function | |
template <typename ReturnType, typename... Params> | |
void register_function(const std::pair<std::string, ReturnType (Type::*)(Params...)>& f) { | |
//! wrap the instanciation of a new object of type Type and the call to the function f in a C++11 lambda | |
auto f_wrapper = [f](Params... params) -> ReturnType { | |
return (Type().*f.second)(params...); | |
}; | |
//! store function information | |
functions.push_back({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! iterate over the parameters pack | |
template <typename Head, typename... Tail> | |
void register_function(const Head& head, Tail... tail) { | |
register_function(head); | |
register_function(tail...); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename Type> | |
class reflectable : reflectable_base { | |
public: | |
//! constructor of a reflectable class where we can process the registration | |
//! note the presence of variadic template to accept any number of member functions | |
template <typename... Fcts> | |
reflectable(const std::string& class_name, Fcts... fcts) : name(class_name) { | |
reflection_manager::get_instance().register_reflectable(*this); | |
register_function(fcts...); | |
} |
NewerOlder