This file contains hidden or 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
//! our function base class, non-templated. | |
//! it does really nothing, except helping us to store functions in the same container | |
class function_base { | |
public: | |
virtual ~function_base(void) = default; | |
}; | |
//! our function class, templated on return and parameters types | |
template <typename ReturnType, typename... Params> | |
class function; |
This file contains hidden or 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 T> | |
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); | |
} |
This file contains hidden or 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; | |
refleection_manager& operator=(const reflection_manager&) = delete; | |
static reflection_manager& get_instance(void) { | |
static reflection_manager instance; | |
return instance; | |
} |
This file contains hidden or 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 reflectable_base { | |
public: | |
virtual ~reflectable_base(void) = default; | |
virtual const std::string& get_name(void) const = 0; | |
}; | |
template <typename T> | |
class reflectable : reflectable_base { | |
public: |
This file contains hidden or 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 T> | |
class reflectable { | |
public: | |
//! constructor of a reflectable class where we can process the registration | |
reflectable(const std::string& class_name) : name(class_name) { | |
reflection_manager::get_instance().register_reflectable(*this); | |
} | |
//! function to get reflectable name | |
const std::string& get_name(void) const { |
This file contains hidden or 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 hidden or 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 reflectable { | |
public: | |
//! constructor of a reflectable class where we can process the registration | |
reflectable(/* ... */) { | |
//! registration of a class or member function here | |
} | |
}; | |
static reflectable register_some_class; |
This file contains hidden or 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
#include <iostream> | |
class A { | |
public: | |
A(void) { std::cout << "A::A()" << std::endl; } | |
}; | |
static A a; | |
int main(void) { |
This file contains hidden or 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
int main(void) { | |
REGISTER_CLASS(SomeClass) | |
REGISTER_MEMBER_FUNCTION(SomeClass::some_function) | |
// ... | |
} |
This file contains hidden or 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
#include <dlfcn.h> | |
#include <iostream> | |
extern "C" { | |
void display_nb(int nb) { | |
std::cout << nb << std::endl; | |
} | |
} |