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