blob: 2bd51aca935a82b177f0eadfa6e1083d4fb0f53f (
plain)
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
48
|
#include "factory.h"
using namespace Rotor;
using namespace std;
Node_factory::Node_factory(std::string _log_id){
log_id=_log_id;
//for now, statically load prototype map in constructor
add_type(new Time(),"nodes");
add_type(new Multiply(),"nodes");
add_type(new Print(),"nodes");
}
Json::Value Node_factory::list_node(const string &_type){
Json::Value json;
for (auto& type: type_map) {
if (type.first==_type) {
json["node"]=type.second->to_json();
return json;
}
}
json["error"]="Node '"+_type+"' not found";
return json;
};
Json::Value Node_factory::list_nodes(){
Json::Value json;
json["nodeslist"]=Json::arrayValue;
for (auto& type: type_map) {
if (type.second->get_description()!="") { //blank description = internal/ testing node
json["nodeslist"].append(list_node(type.first));
}
}
return json;
}
Json::Value Node_factory::list_categories(){
Json::Value json;
json["category"]=Json::arrayValue;
for (auto& _category: category_map) {
Json::Value category;
category["name"]=_category.first;
category["nodes"]=Json::arrayValue;
for (auto& _node: _category.second){
category["nodes"].append(list_node(_node->get_type()));
}
json["category"].append(category);
}
return json;
}
|