aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader/NodeTools.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/dataloader/NodeTools.hpp')
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index 1ca6cf0..45e6d4f 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -7,6 +7,7 @@
#include <optional>
#include <set>
#include <type_traits>
+#include <unordered_set>
#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
@@ -320,5 +321,34 @@ namespace OpenVic {
return true;
};
}
+
+ template<typename T, typename U>
+ Callback<T> auto vector_callback(std::vector<U>& vec) {
+ return [&vec](T val) -> bool {
+ vec.emplace_back(std::move(val));
+ return true;
+ };
+ }
+
+ template<typename T>
+ Callback<T> auto vector_callback(std::vector<T>& vec) {
+ return vector_callback<T, T>(vec);
+ }
+
+ template<typename T>
+ Callback<T const&> auto vector_callback_pointer(std::vector<T const*>& vec) {
+ return [&vec](T const& val) -> bool {
+ vec.emplace_back(&val);
+ return true;
+ };
+ }
+
+ template<typename T>
+ Callback<T const&> auto set_callback_pointer(std::unordered_set<T const*>& set) {
+ return [&set](T const& val) -> bool {
+ set.insert(&val);
+ return true;
+ };
+ }
}
}