aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/types/IdentifierRegistry.hpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-11-13 13:42:37 +0100
committer GitHub <noreply@github.com>2023-11-13 13:42:37 +0100
commitf572664cbe1aa5ec2cb6907de3083f058c20af7e (patch)
treec9a61c5dd15fb1eae1555f47119423dbba315e76 /src/openvic-simulation/types/IdentifierRegistry.hpp
parentba7bfc52803781c970d6e8afc84c7d3d3e843726 (diff)
parentce84886cb931975f622134d6c8d32a69c675d975 (diff)
Merge pull request #71 from OpenVicProject/gui-loading
GUI and GFX file loading
Diffstat (limited to 'src/openvic-simulation/types/IdentifierRegistry.hpp')
-rw-r--r--src/openvic-simulation/types/IdentifierRegistry.hpp37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp
index 1121956..662815e 100644
--- a/src/openvic-simulation/types/IdentifierRegistry.hpp
+++ b/src/openvic-simulation/types/IdentifierRegistry.hpp
@@ -214,24 +214,31 @@ namespace OpenVic {
value_type CONST* get_item_by_index(size_t index) CONST { \
return index < items.size() ? &items[index] : nullptr; \
} \
- NodeTools::callback_t<std::string_view> expect_item_str(NodeTools::callback_t<value_type CONST&> callback) CONST { \
- return [this, callback](std::string_view identifier) -> bool { \
+ NodeTools::callback_t<std::string_view> expect_item_str( \
+ NodeTools::callback_t<value_type CONST&> callback, bool warn \
+ ) CONST { \
+ return [this, callback, warn](std::string_view identifier) -> bool { \
value_type CONST* item = get_item_by_identifier(identifier); \
if (item != nullptr) { \
return callback(*item); \
} \
- Logger::error("Invalid ", name, ": ", identifier); \
- return false; \
+ if (!warn) { \
+ Logger::error("Invalid ", name, ": ", identifier); \
+ return false; \
+ } else { \
+ Logger::warning("Invalid ", name, ": ", identifier); \
+ return true; \
+ } \
}; \
} \
- NodeTools::node_callback_t expect_item_identifier(NodeTools::callback_t<value_type CONST&> callback) CONST { \
- return NodeTools::expect_identifier(expect_item_str(callback)); \
+ NodeTools::node_callback_t expect_item_identifier(NodeTools::callback_t<value_type CONST&> callback, bool warn) CONST { \
+ return NodeTools::expect_identifier(expect_item_str(callback, warn)); \
} \
NodeTools::node_callback_t expect_item_dictionary( \
NodeTools::callback_t<value_type CONST&, ast::NodeCPtr> callback \
) CONST { \
return NodeTools::expect_dictionary([this, callback](std::string_view key, ast::NodeCPtr value) -> bool { \
- return expect_item_str(std::bind(callback, std::placeholders::_1, value))(key); \
+ return expect_item_str(std::bind(callback, std::placeholders::_1, value), false)(key); \
}); \
}
@@ -348,14 +355,14 @@ namespace OpenVic {
return plural.get_item_identifiers(); \
} \
NodeTools::callback_t<std::string_view> expect_##singular##_str( \
- NodeTools::callback_t<decltype(plural)::value_type const&> callback \
+ NodeTools::callback_t<decltype(plural)::value_type const&> callback, bool warn = false \
) const { \
- return plural.expect_item_str(callback); \
+ return plural.expect_item_str(callback, warn); \
} \
NodeTools::node_callback_t expect_##singular##_identifier( \
- NodeTools::callback_t<decltype(plural)::value_type const&> callback \
+ NodeTools::callback_t<decltype(plural)::value_type const&> callback, bool warn = false \
) const { \
- return plural.expect_item_identifier(callback); \
+ return plural.expect_item_identifier(callback, warn); \
} \
NodeTools::node_callback_t expect_##singular##_dictionary( \
NodeTools::callback_t<decltype(plural)::value_type const&, ast::NodeCPtr> callback \
@@ -373,14 +380,14 @@ namespace OpenVic {
return plural.get_item_by_identifier(identifier); \
} \
NodeTools::callback_t<std::string_view> expect_##singular##_str( \
- NodeTools::callback_t<decltype(plural)::value_type&> callback \
+ NodeTools::callback_t<decltype(plural)::value_type&> callback, bool warn = false \
) { \
- return plural.expect_item_str(callback); \
+ return plural.expect_item_str(callback, warn); \
} \
NodeTools::node_callback_t expect_##singular##_identifier( \
- NodeTools::callback_t<decltype(plural)::value_type&> callback \
+ NodeTools::callback_t<decltype(plural)::value_type&> callback, bool warn = false \
) { \
- return plural.expect_item_identifier(callback); \
+ return plural.expect_item_identifier(callback, warn); \
} \
NodeTools::node_callback_t expect_##singular##_dictionary( \
NodeTools::callback_t<decltype(plural)::value_type&, ast::NodeCPtr> callback \