aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader/NodeTools.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-09-19 17:40:09 +0200
committer GitHub <noreply@github.com>2023-09-19 17:40:09 +0200
commit9c89100e0c8854dff3174b078d235148585a8b03 (patch)
tree77f81dfd3ec85a659741e979c148b33b22595dd0 /src/openvic-simulation/dataloader/NodeTools.cpp
parent64d134ad20c333afa60373526d6fab27a07c6adc (diff)
parent72add97c47f0d17fc0019bb4cfec7506740a9c7d (diff)
Merge pull request #17 from OpenVicProject/dataloading-the-third
Scaffolding for `positions.txt` + modifier loading
Diffstat (limited to 'src/openvic-simulation/dataloader/NodeTools.cpp')
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp
index 63a97ad..7dd6e16 100644
--- a/src/openvic-simulation/dataloader/NodeTools.cpp
+++ b/src/openvic-simulation/dataloader/NodeTools.cpp
@@ -19,20 +19,20 @@ static node_callback_t _expect_type(callback_t<T const&> callback) {
};
}
-template<typename T = ast::AbstractStringNode>
+template<typename T>
requires(std::derived_from<T, ast::AbstractStringNode>)
-static callback_t<T const&> abstract_string_node_callback(callback_t<std::string_view> callback) {
+static callback_t<T const&> _abstract_string_node_callback(callback_t<std::string_view> callback) {
return [callback](T const& node) -> bool {
return callback(node._name);
};
}
node_callback_t NodeTools::expect_identifier(callback_t<std::string_view> callback) {
- return _expect_type<ast::IdentifierNode>(abstract_string_node_callback<ast::IdentifierNode>(callback));
+ return _expect_type<ast::IdentifierNode>(_abstract_string_node_callback<ast::IdentifierNode>(callback));
}
node_callback_t NodeTools::expect_string(callback_t<std::string_view> callback) {
- return _expect_type<ast::StringNode>(abstract_string_node_callback<ast::StringNode>(callback));
+ return _expect_type<ast::StringNode>(_abstract_string_node_callback<ast::StringNode>(callback));
}
node_callback_t NodeTools::expect_identifier_or_string(callback_t<std::string_view> callback) {
@@ -43,7 +43,7 @@ node_callback_t NodeTools::expect_identifier_or_string(callback_t<std::string_vi
cast_node = node->cast_to<ast::StringNode>();
}
if (cast_node != nullptr) {
- return abstract_string_node_callback(callback)(*cast_node);
+ return _abstract_string_node_callback<ast::AbstractStringNode>(callback)(*cast_node);
}
Logger::error("Invalid node type ", node->get_type(), " when expecting ", ast::IdentifierNode::get_type_static(), " or ", ast::StringNode::get_type_static());
} else {
@@ -148,6 +148,27 @@ node_callback_t NodeTools::expect_date(callback_t<Date> callback) {
);
}
+template<typename T, node_callback_t (*expect_func)(callback_t<T>)>
+node_callback_t _expect_vec2(callback_t<vec2_t<T>> callback) {
+ return [callback](ast::NodeCPtr node) -> bool {
+ vec2_t<T> vec;
+ bool ret = expect_dictionary_keys(
+ "x", ONE_EXACTLY, expect_func(assign_variable_callback(vec.x)),
+ "y", ONE_EXACTLY, expect_func(assign_variable_callback(vec.y))
+ )(node);
+ ret &= callback(vec);
+ return ret;
+ };
+}
+
+node_callback_t NodeTools::expect_ivec2(callback_t<ivec2_t> callback) {
+ return _expect_vec2<int64_t, expect_int>(callback);
+}
+
+node_callback_t NodeTools::expect_fvec2(callback_t<fvec2_t> callback) {
+ return _expect_vec2<fixed_point_t, expect_fixed_point>(callback);
+}
+
node_callback_t NodeTools::expect_assign(key_value_callback_t callback) {
return _expect_type<ast::AssignNode>(
[callback](ast::AssignNode const& assign_node) -> bool {