aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp2
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp48
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp8
3 files changed, 34 insertions, 24 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 475cdd1..cfc944d 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -48,7 +48,7 @@ static constexpr bool path_equals(std::string_view lhs, std::string_view rhs) {
template<typename T>
concept is_filename = std::same_as<T, std::filesystem::path> || std::convertible_to<T, std::string_view>;
-bool filename_equals(const is_filename auto& lhs, const is_filename auto& rhs) {
+static bool filename_equals(const is_filename auto& lhs, const is_filename auto& rhs) {
auto left = [&lhs] {
if constexpr (std::same_as<std::decay_t<decltype(lhs)>, std::filesystem::path>)
return lhs.filename().string();
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<uint64_t> callback) {
);
}
-node_callback_t NodeTools::expect_fixed_point(callback_t<fixed_point_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<std::string_view> NodeTools::expect_fixed_point_str(callback_t<fixed_point_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<fixed_point_t> callback) {
+ return expect_identifier(expect_fixed_point_str(callback));
}
node_callback_t NodeTools::expect_colour(callback_t<colour_t> callback) {
@@ -142,18 +144,20 @@ node_callback_t NodeTools::expect_colour(callback_t<colour_t> callback) {
};
}
-node_callback_t NodeTools::expect_date(callback_t<Date> 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<std::string_view> NodeTools::expect_date_str(callback_t<Date> 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<Date> callback) {
+ return expect_identifier(expect_date_str(callback));
}
node_callback_t NodeTools::expect_years(callback_t<Timespan> callback) {
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index f06a85f..66b614a 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -4,6 +4,7 @@
#include <cstdint>
#include <functional>
#include <map>
+#include <set>
#include <type_traits>
#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
@@ -16,10 +17,13 @@ namespace OpenVic {
namespace ast = ovdl::v2script::ast;
/* Template for map from strings to Ts, in which string_views can be
- * searched for without needing to be copied into a string, */
+ * searched for without needing to be copied into a string */
template<typename T>
using string_map_t = std::map<std::string, T, std::less<void>>;
+ /* String set type supporting heterogeneous key lookup */
+ using string_set_t = std::set<std::string, std::less<void>>;
+
namespace NodeTools {
template<typename Fn, typename Return = void, typename ...Args>
@@ -93,9 +97,11 @@ namespace OpenVic {
});
}
+ callback_t<std::string_view> expect_fixed_point_str(callback_t<fixed_point_t> callback);
node_callback_t expect_fixed_point(callback_t<fixed_point_t> callback);
node_callback_t expect_colour(callback_t<colour_t> callback);
+ callback_t<std::string_view> expect_date_str(callback_t<Date> callback);
node_callback_t expect_date(callback_t<Date> callback);
node_callback_t expect_years(callback_t<Timespan> callback);
node_callback_t expect_months(callback_t<Timespan> callback);