-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogic.cpp
More file actions
47 lines (44 loc) · 1.25 KB
/
logic.cpp
File metadata and controls
47 lines (44 loc) · 1.25 KB
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
40
41
42
43
44
45
46
47
#include "logic.h"
#include <stack>
#include <iostream>
#ifdef _WIN32
#include <windows.h>
#include <psapi.h>
#endif
namespace Logic {
Error::Error(std::string s) {
msg = s;
}
const char *Error::what() const noexcept {
return msg.c_str();
}
NodeType::NodeType(std::string id, std::initializer_list<std::initializer_list<int>> argtypes, OnResolveType onResolve)
: id{id}, onResolve{onResolve} {
for (auto il : argtypes) {
this->argtypes.push_back(ArgTypes{il});
}
}
ValueType Node::resolve(Object *as) {
return nodeTypes[nodeType].onResolve(this, as);
}
Node Node::from_type(std::string s) {
int index = 0;
for (auto nodeType : nodeTypes) {
if (nodeType.id == s) {
Node result;
result.nodeType = index;
result.value = NullValue();
return result;
}
index++;
}
std::string emsg = "The node type '";
emsg += s;
emsg += "' doesn't exist.";
throw Error(emsg);
}
void Node::add_input(Node *n) {
argNodes.push_back(n);
n->outNodes.push_back(this);
}
}