From 366f1b3941315641bdcb0ee98465b4d2134eee86 Mon Sep 17 00:00:00 2001 From: Hop311 Date: Fri, 25 Aug 2023 23:25:12 +0100 Subject: Followup big dataloader commit --- src/openvic/dataloader/NodeTools.hpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/openvic/dataloader/NodeTools.hpp') diff --git a/src/openvic/dataloader/NodeTools.hpp b/src/openvic/dataloader/NodeTools.hpp index ca7130c..48c3710 100644 --- a/src/openvic/dataloader/NodeTools.hpp +++ b/src/openvic/dataloader/NodeTools.hpp @@ -2,13 +2,13 @@ #include -#include - #include "openvic/types/Colour.hpp" -#include "openvic/types/Return.hpp" #include "openvic/types/Date.hpp" +#include "openvic/types/Return.hpp" #include "openvic/types/fixed_point/FP.hpp" +#include + namespace OpenVic { namespace ast = ovdl::v2script::ast; @@ -27,7 +27,24 @@ namespace OpenVic { return_t expect_colour(ast::NodeCPtr node, std::function callback); return_t expect_date(ast::NodeCPtr node, std::function callback); return_t expect_assign(ast::NodeCPtr node, std::function callback); - return_t expect_list(ast::NodeCPtr node, std::function callback, size_t length = 0, bool file_node = false); + + static const std::function default_length_callback = [](size_t size) -> size_t { return size; }; + + template requires requires(T& t) { + { t.size() } -> std::same_as; + t.reserve( size_t {} ); + } + std::function reserve_length_callback(T& t) { + return [&t](size_t size) -> size_t { + t.reserve(t.size() + size); + return size; + }; + } + + return_t expect_list_and_length(ast::NodeCPtr node, std::function length_callback, std::function callback, bool file_node = false); + return_t expect_list_of_length(ast::NodeCPtr node, std::function callback, size_t length, bool file_node = false); + return_t expect_list(ast::NodeCPtr node, std::function callback, bool file_node = false); + return_t expect_dictionary_and_length(ast::NodeCPtr node, std::function length_callback, std::function callback, bool file_node = false); return_t expect_dictionary(ast::NodeCPtr node, std::function callback, bool file_node = false); static const std::function success_callback = [](ast::NodeCPtr) -> return_t { return SUCCESS; }; -- cgit v1.2.3-56-ga3b1