blob: 82a14b8cbd8f7192f475a72f69b6f7c3d073a579 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#pragma once
#include "openvic-simulation/dataloader/NodeTools.hpp"
namespace OpenVic {
// TODO - is template needed if context is always DefinitionManager const&?
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;
}
};
}
|