// // Struct.h // Clock Signal // // Created by Thomas Harte on 06/03/2020. // Copyright © 2020 Thomas Harte. All rights reserved. // #ifndef Struct_h #define Struct_h #include #include #include #include namespace Reflection { class Struct { public: template const Type &get(const std::string &name) { return *std::any_cast(contents_[name]); } template void set(const std::string &name, const Type &value) { *std::any_cast(contents_[name]) = value; } const std::type_info &type_of(const std::string &name) { return contents_[name].type(); } std::vector all_keys() { std::vector keys; for(const auto &pair: contents_) { keys.push_back(pair.first); } return keys; } protected: template void declare(Type *t, const std::string &name) { contents_[name] = t; } private: std::unordered_map contents_; }; } #endif /* Struct_h */