Created
October 19, 2020 05:36
-
-
Save Cylix/c3086b7e5d9d34c031e76f1f72ee2e0a to your computer and use it in GitHub Desktop.
Reflection in C++14 - Registration #3
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; | |
} | |
void register_reflectable(reflectable_base& r) { | |
// store the reflectable | |
this->reflectables.push_back({ r }); | |
} | |
void process_reflection(const std::string& class_name) { | |
for (const auto& reflectable : this->reflectables) | |
if (reflectable.get().get_name() == class_name) { | |
// process reflection here | |
} | |
} | |
private: | |
reflection_manager(void) = default; | |
std::vector<std::reference_wrapper<reflectable_base>> reflectables; | |
} | |
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