From 70948572ef0fb5c6dae453c410fdaedfab36741b Mon Sep 17 00:00:00 2001 From: hop311 Date: Sat, 13 Jan 2024 20:14:06 +0000 Subject: Reworked UniqueKeyRegistry template params + added support for std::deque storage --- src/openvic-simulation/interface/LoadBase.hpp | 40 ++++++++++++++------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'src/openvic-simulation/interface') 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 + template 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> T, std::derived_from U> + template> T, std::derived_from U> static NodeTools::node_callback_t _expect_instance( - NodeTools::callback_t&&> callback, _Context... context + NodeTools::callback_t&&> callback, Context... context ) { return [callback, &context...](ast::NodeCPtr node) -> bool { std::unique_ptr instance { std::make_unique() }; @@ -38,14 +38,14 @@ namespace OpenVic { OV_DETAIL_GET_TYPE_BASE_CLASS(LoadBase) }; - template - class Named : public LoadBase<_Context...> { + template + class Named : public LoadBase { 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 - requires std::derived_from> - struct _get_name { - constexpr std::string_view operator()(T const* item) const { - return item->get_name(); + template + requires std::derived_from> + struct RegistryValueInfoNamed { + using value_type = Value; + + static constexpr std::string_view get_identifier(value_type const& item) { + return item.get_name(); } }; - template - requires std::derived_from> - using NamedRegistry = ValueRegistry>; + template + requires std::derived_from> + using NamedRegistry = ValueRegistry>; - template - requires std::derived_from> - using NamedInstanceRegistry = InstanceRegistry>; + template + requires std::derived_from> + using NamedInstanceRegistry = InstanceRegistry>; } -- cgit v1.2.3-56-ga3b1