| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- //
- // context.h
- // reflection
- //
- // Created by Sam Jaffe on 8/6/22.
- // Copyright © 2022 Sam Jaffe. All rights reserved.
- //
- #pragma once
- #include <initializer_list>
- #include <utility>
- #include "reflection/forward.h"
- #include "reflection/object.h"
- #include "reflection/scope.h"
- namespace reflection {
- class Context {
- public:
- struct Arg : std::pair<std::string_view, Object> {
- template <typename T> Arg(std::string_view id, T &&value)
- : pair(id, Object(std::forward<T>(value), std::string(id))) {}
- Arg(Object &&obj) : pair("", std::move(obj)) { first = second.name(); }
- };
-
- public:
- explicit Context(std::initializer_list<Arg> 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(ContextScope const &scope) const {
- return get(scope.context()).get(static_cast<Scope const &>(scope));
- }
- private:
- std::unordered_map<std::string_view, Object> data_;
- };
- }
|