blob: 8c44507f8ff5f5764f38caf367c968f65f62ee27 (
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
|
#ifndef ROTOR_FACTORY_H
#define ROTOR_FACTORY_H
#include "rotor.h"
#include "nodes.h"
#include "xmlIO.h"
namespace Rotor {
class Node_factory{
public:
Node_factory();
~Node_factory(){
for (auto t:type_map) delete t.second;
}
void add_type(Node* proto){
type_map[proto->node_type]=proto;
};
void add_type(Node* proto,std::string category){
add_type(proto);
if (category_map.find(category)==category_map.end()) category_map[category]=vector<Node*>();
category_map[category].push_back(proto);
};
Node *create(std::map<std::string,std::string> &settings){
if (settings.find("node_type")!=settings.end()) {
if (type_map.find(settings["node_type"])!=type_map.end()) {
return type_map[settings["node_type"]]->clone(settings);
}
}
return NULL;
};
bool list_node(const std::string &t,xmlIO XML);
bool list_node(const std::string &t,Json::Value &JSON);
void list_node(Rotor::Node* type,xmlIO XML,int i=0);
Json::Value list_node(Rotor::Node* type);
void list_nodes(xmlIO XML);
void list_nodes(Json::Value &JSON);
void list_categories(xmlIO XML);
void list_categories(Json::Value &JSON);
private:
std::map<std::string,Node*> type_map;
std::map<std::string,std::vector<Rotor::Node*> > category_map;
};
}
#endif //ROTOR_H
|