diff options
author | Hop311 <Hop3114@gmail.com> | 2024-01-02 15:40:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-02 15:40:00 +0100 |
commit | 4c8da86c3bede8834f381fa63edaa3e140131f69 (patch) | |
tree | ff3433a63e91b9239eb7226e75054314182d6c1f /src/openvic-simulation/scripts/Script.hpp | |
parent | 66b80459c9d49895de902432bce11176b1270878 (diff) | |
parent | 5f64f983d0cead266a28791be42162c443fd2a75 (diff) |
Merge pull request #112 from OpenVicProject/script-framework
Added framework for loading all Conditions and Effects
Diffstat (limited to 'src/openvic-simulation/scripts/Script.hpp')
-rw-r--r-- | src/openvic-simulation/scripts/Script.hpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/openvic-simulation/scripts/Script.hpp b/src/openvic-simulation/scripts/Script.hpp new file mode 100644 index 0000000..8efc277 --- /dev/null +++ b/src/openvic-simulation/scripts/Script.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include "openvic-simulation/dataloader/NodeTools.hpp" + +namespace OpenVic { + template<typename... _Context> + struct Script { + private: + ast::NodeCPtr _root; + + protected: + virtual bool _parse_script(ast::NodeCPtr root, _Context... context) = 0; + + public: + Script() : _root { nullptr } {} + Script(Script&&) = default; + + constexpr bool has_defines_node() const { + return _root != nullptr; + } + + constexpr NodeTools::NodeCallback auto expect_script() { + return NodeTools::assign_variable_callback(_root); + } + + bool parse_script(bool can_be_null, _Context... context) { + if (_root == nullptr) { + if (!can_be_null) { + Logger::error("Null/missing script node!"); + } + return can_be_null; + } + const bool ret = _parse_script(_root, context...); + _root = nullptr; + return ret; + } + }; +} |