diff options
author | Hop311 <Hop3114@gmail.com> | 2024-01-14 12:27:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-14 12:27:56 +0100 |
commit | 2fcc7ccd409701f6bad343e57afe74bd05246b68 (patch) | |
tree | 8e2f7f4de34ec3d62e55f9918ce26900c16a5d0f /src/openvic-simulation/interface/LoadBase.hpp | |
parent | 046e5619277c6f3dffbb29244b4b88029da31bee (diff) | |
parent | 70948572ef0fb5c6dae453c410fdaedfab36741b (diff) |
Merge pull request #129 from OpenVicProject/registry-template-fun
Reworked `UniqueKeyRegistry` template params
Diffstat (limited to 'src/openvic-simulation/interface/LoadBase.hpp')
-rw-r--r-- | src/openvic-simulation/interface/LoadBase.hpp | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/openvic-simulation/interface/LoadBase.hpp b/src/openvic-simulation/interface/LoadBase.hpp index 3ee7c83..74aece9 100644 --- a/src/openvic-simulation/interface/LoadBase.hpp +++ b/src/openvic-simulation/interface/LoadBase.hpp @@ -5,27 +5,27 @@ namespace OpenVic { - template<typename... _Context> + template<typename... Context> class LoadBase { protected: LoadBase() = default; - virtual bool _fill_key_map(NodeTools::key_map_t&, _Context...) = 0; + virtual bool _fill_key_map(NodeTools::key_map_t&, Context...) = 0; public: LoadBase(LoadBase&&) = default; virtual ~LoadBase() = default; - bool load(ast::NodeCPtr node, _Context... context) { + bool load(ast::NodeCPtr node, Context... context) { NodeTools::key_map_t key_map; bool ret = _fill_key_map(key_map, context...); ret &= NodeTools::expect_dictionary_key_map(std::move(key_map))(node); return ret; } - template<std::derived_from<LoadBase<_Context...>> T, std::derived_from<T> U> + template<std::derived_from<LoadBase<Context...>> T, std::derived_from<T> U> static NodeTools::node_callback_t _expect_instance( - NodeTools::callback_t<std::unique_ptr<T>&&> callback, _Context... context + NodeTools::callback_t<std::unique_ptr<T>&&> callback, Context... context ) { return [callback, &context...](ast::NodeCPtr node) -> bool { std::unique_ptr<T> instance { std::make_unique<U>() }; @@ -38,14 +38,14 @@ namespace OpenVic { OV_DETAIL_GET_TYPE_BASE_CLASS(LoadBase) }; - template<typename... _Context> - class Named : public LoadBase<_Context...> { + template<typename... Context> + class Named : public LoadBase<Context...> { std::string PROPERTY(name); protected: Named() = default; - virtual bool _fill_key_map(NodeTools::key_map_t& key_map, _Context...) override { + virtual bool _fill_key_map(NodeTools::key_map_t& key_map, Context...) override { using namespace OpenVic::NodeTools; return add_key_map_entries(key_map, "name", ONE_EXACTLY, expect_string(assign_variable_callback_string(name))); } @@ -64,19 +64,21 @@ namespace OpenVic { OV_DETAIL_GET_TYPE }; - template<typename T, typename... _Context> - requires std::derived_from<T, Named<_Context...>> - struct _get_name { - constexpr std::string_view operator()(T const* item) const { - return item->get_name(); + template<typename Value, typename... Context> + requires std::derived_from<Value, Named<Context...>> + struct RegistryValueInfoNamed { + using value_type = Value; + + static constexpr std::string_view get_identifier(value_type const& item) { + return item.get_name(); } }; - template<typename T, typename... _Context> - requires std::derived_from<T, Named<_Context...>> - using NamedRegistry = ValueRegistry<T, _get_name<T, _Context...>>; + template<typename Value, typename... Context> + requires std::derived_from<Value, Named<Context...>> + using NamedRegistry = ValueRegistry<RegistryValueInfoNamed<Value, Context...>>; - template<typename T, typename... _Context> - requires std::derived_from<T, Named<_Context...>> - using NamedInstanceRegistry = InstanceRegistry<T, _get_name<T, _Context...>>; + template<typename Value, typename... Context> + requires std::derived_from<Value, Named<Context...>> + using NamedInstanceRegistry = InstanceRegistry<RegistryValueInfoNamed<Value, Context...>>; } |