diff options
author | hop311 <hop3114@gmail.com> | 2023-12-06 23:10:53 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2023-12-07 21:38:17 +0100 |
commit | 398377011cb3d3c970451dcd215f3610159f1ae2 (patch) | |
tree | 2a73255f595eabb1441419a08bd0d5e5407213e7 /src/openvic-simulation/dataloader/NodeTools.hpp | |
parent | 48a3f1729d709847d7cad33f594c77cac414e802 (diff) |
Vec/set callbacks + crime file + prov building pos
Diffstat (limited to 'src/openvic-simulation/dataloader/NodeTools.hpp')
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.hpp | 30 |
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; + }; + } } } |