Created
October 19, 2020 05:30
-
-
Save Cylix/9fe17a399d2a2ae58344b2ee0109a4ff to your computer and use it in GitHub Desktop.
Reflection in C++14 - Manager
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; | |
} | |
void register_reflectable(reflectable& r) { | |
// store the reflectable | |
this->reflectables.push_back({ r }); | |
} | |
void process_reflection(const std::string& class_name) { | |
// process reflection here | |
} | |
private: | |
reflection_manager(void) = default; | |
std::vector<std::reference_wrapper<reflectable>> reflectables; | |
}; | |
class reflectable { | |
public: | |
//! constructor of a reflectable class where we can process the registration | |
reflectable(const std::string& class_name) { | |
reflection_manager::get_instance().register_reflectable(*this); | |
} | |
}; | |
static reflectable register_some_class("SomeClass"); | |
int main(void) { | |
reflection_manager::get_instance().process_reflection("SomeClass"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment