// // context.h // reflection // // Created by Sam Jaffe on 8/6/22. // Copyright © 2022 Sam Jaffe. All rights reserved. // #pragma once #include #include #include "reflection/forward.h" #include "reflection/object.h" #include "reflection/property.h" namespace reflection { class Context { public: struct Arg : std::pair { template Arg(std::string_view id, T &&value) : pair(id, Object(std::forward(value), std::string(id))) {} Arg(Object &&obj) : pair("", std::move(obj)) { first = second.name(); } }; public: explicit Context(std::initializer_list data) : data_(data.begin(), data.end()) {} Object const & get(std::string_view id) const { return data_.at(id); } bool has(std::string_view id) const { return data_.count(id); } Object get(Property const &scope) const { if (scope.begin() == scope.end()) { return get(scope.context()); } return get(scope.context()).get(scope); } private: std::unordered_map data_; }; }