summaryrefslogtreecommitdiff
path: root/NT/src/factory.h
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2014-01-03 19:57:48 +0000
committerTim Redfern <tim@eclectronics.org>2014-01-03 19:57:48 +0000
commit815d1149f9fb6be2c1bc05fb04f574eb928e050e (patch)
tree647ac891d00ab5561926a6566d37c70346df634a /NT/src/factory.h
parent820b73f2abdf51bd59cb5b74739fb6f264b7c54e (diff)
updated refactored files
Diffstat (limited to 'NT/src/factory.h')
-rw-r--r--NT/src/factory.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/NT/src/factory.h b/NT/src/factory.h
new file mode 100644
index 0000000..ac204a0
--- /dev/null
+++ b/NT/src/factory.h
@@ -0,0 +1,47 @@
+#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(std::string type,Node* proto){
+ type_map[type]=proto;
+ type_map[type]->type=type;
+ };
+ void add_type(std::string type,Node* proto,std::string category){
+ add_type(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("type")!=settings.end()) {
+ if (type_map.find(settings["type"])!=type_map.end()) {
+ return type_map[settings["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
+