Skip to content

Instantly share code, notes, and snippets.

@Cylix
Created October 19, 2020 05:36
Show Gist options
  • Save Cylix/c3086b7e5d9d34c031e76f1f72ee2e0a to your computer and use it in GitHub Desktop.
Save Cylix/c3086b7e5d9d34c031e76f1f72ee2e0a to your computer and use it in GitHub Desktop.
Reflection in C++14 - Registration #3
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