From d2e91829abc8dd46fa4685d1cab89ef6fe907471 Mon Sep 17 00:00:00 2001 From: hop311 Date: Fri, 20 Oct 2023 09:16:38 +0100 Subject: Separated node->string and string->value parsing --- src/openvic-simulation/dataloader/NodeTools.cpp | 48 +++++++++++++------------ 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'src/openvic-simulation/dataloader/NodeTools.cpp') diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp index 85bc572..c99a2f0 100644 --- a/src/openvic-simulation/dataloader/NodeTools.cpp +++ b/src/openvic-simulation/dataloader/NodeTools.cpp @@ -103,18 +103,20 @@ node_callback_t NodeTools::expect_uint64(callback_t callback) { ); } -node_callback_t NodeTools::expect_fixed_point(callback_t callback) { - return expect_identifier( - [callback](std::string_view identifier) -> bool { - bool successful = false; - const fixed_point_t val = fixed_point_t::parse(identifier.data(), identifier.length(), &successful); - if (successful) { - return callback(val); - } - Logger::error("Invalid fixed point identifier text: ", identifier); - return false; +callback_t NodeTools::expect_fixed_point_str(callback_t callback) { + return [callback](std::string_view identifier) -> bool { + bool successful = false; + const fixed_point_t val = fixed_point_t::parse(identifier.data(), identifier.length(), &successful); + if (successful) { + return callback(val); } - ); + Logger::error("Invalid fixed point identifier text: ", identifier); + return false; + }; +} + +node_callback_t NodeTools::expect_fixed_point(callback_t callback) { + return expect_identifier(expect_fixed_point_str(callback)); } node_callback_t NodeTools::expect_colour(callback_t callback) { @@ -142,18 +144,20 @@ node_callback_t NodeTools::expect_colour(callback_t callback) { }; } -node_callback_t NodeTools::expect_date(callback_t callback) { - return expect_identifier( - [callback](std::string_view identifier) -> bool { - bool successful = false; - const Date date = Date::from_string(identifier, &successful); - if (successful) { - return callback(date); - } - Logger::error("Invalid date identifier text: ", identifier); - return false; +callback_t NodeTools::expect_date_str(callback_t callback) { + return [callback](std::string_view identifier) -> bool { + bool successful = false; + const Date date = Date::from_string(identifier, &successful); + if (successful) { + return callback(date); } - ); + Logger::error("Invalid date identifier text: ", identifier); + return false; + }; +} + +node_callback_t NodeTools::expect_date(callback_t callback) { + return expect_identifier(expect_date_str(callback)); } node_callback_t NodeTools::expect_years(callback_t callback) { -- cgit v1.2.3-56-ga3b1