summaryrefslogtreecommitdiff
path: root/rotord/src/rotor.h
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2013-09-24 14:49:29 +0100
committerComment <tim@gray.(none)>2013-09-24 14:49:29 +0100
commitf40d511775eb8dfae9a28870c5e0125b5e55b305 (patch)
tree1f26641cbfd4a9515f999cd03b5a73675ee75656 /rotord/src/rotor.h
parent6e615b00dbb54f33b928e0de0695087709fbc073 (diff)
category list XML/json
Diffstat (limited to 'rotord/src/rotor.h')
-rw-r--r--rotord/src/rotor.h125
1 files changed, 109 insertions, 16 deletions
diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h
index d6cbbc6..72ef7d0 100644
--- a/rotord/src/rotor.h
+++ b/rotord/src/rotor.h
@@ -1050,6 +1050,11 @@ namespace Rotor {
}
void add_type(string type,Node* proto){
type_map[type]=proto;
+ type_map[type]->type=type;
+ };
+ void add_type(string type,Node* proto,vector<Rotor::Node*> &category){
+ add_type(type,proto);
+ category.push_back(proto);
};
Node *create(map<string,string> &settings){
if (settings.find("type")!=settings.end()) {
@@ -1062,35 +1067,35 @@ namespace Rotor {
bool list_node(const string &t,xmlIO XML){
for (auto& type: type_map) {
if (type.first==t) {
- list_node(type,XML);
+ list_node(type.second,XML);
return true;
}
}
XML.addValue("error","Node /"+t+"/ not found");
};
- void list_node(std::pair<const std::basic_string<char>, Rotor::Node*> &type,xmlIO XML,int i=0){
+ void list_node(Rotor::Node* type,xmlIO XML,int i=0){
XML.addTag("node");
- XML.addAttribute("node","type",type.first,i);
- XML.addAttribute("node","inputs",type.second->duplicate_inputs?"expandable":"fixed",i);
- XML.addAttribute("node","title",type.second->title,i);
- XML.addAttribute("node","description",type.second->description,i);
- if (dynamic_cast<Signal_node*> (type.second)!=nullptr) XML.addAttribute("node","output","signal",i);
- if (dynamic_cast<Image_node*> (type.second)!=nullptr) XML.addAttribute("node","output","image",i);
+ XML.addAttribute("node","type",type->type,i);
+ XML.addAttribute("node","inputs",type->duplicate_inputs?"expandable":"fixed",i);
+ XML.addAttribute("node","title",type->title,i);
+ XML.addAttribute("node","description",type->description,i);
+ if (dynamic_cast<Signal_node*> (type)!=nullptr) XML.addAttribute("node","output","signal",i);
+ if (dynamic_cast<Image_node*> (type)!=nullptr) XML.addAttribute("node","output","image",i);
XML.pushTag("node",i);
- //if (type.second->description!="") {
+ //if (type->description!="") {
// XML.addTag("description");
- // XML.setValue("description",type.second->description,0);
+ // XML.setValue("description",type->description,0);
//}
int j=0;
- for (auto& input: type.second->inputs) {
+ for (auto& input: type->inputs) {
XML.addTag("signal_input");
XML.addAttribute("signal_input","title",input->title,j);
XML.addAttribute("signal_input","description",input->description,j);
j++;
}
j=0;
- if (dynamic_cast<Image_node*> (type.second)!=nullptr) {
- for (auto& input: (dynamic_cast<Image_node*>(type.second))->image_inputs) {
+ if (dynamic_cast<Image_node*> (type)!=nullptr) {
+ for (auto& input: (dynamic_cast<Image_node*>(type))->image_inputs) {
XML.addTag("image_input");
XML.addAttribute("image_input","title",input->title,j);
XML.addAttribute("image_input","description",input->description,j);
@@ -1098,7 +1103,7 @@ namespace Rotor {
}
}
j=0;
- for (auto& parameter: type.second->parameters) {
+ for (auto& parameter: type->parameters) {
XML.addTag("parameter");
XML.addAttribute("parameter","name",parameter.first,j);
XML.addAttribute("parameter","type",parameter.second->type,j);
@@ -1110,7 +1115,7 @@ namespace Rotor {
j++;
}
j=0;
- for (auto& attribute: type.second->attributes) {
+ for (auto& attribute: type->attributes) {
XML.addTag("attribute");
XML.addAttribute("attribute","name",attribute.first,j);
XML.addAttribute("attribute","title",attribute.second->title,j);
@@ -1136,11 +1141,98 @@ namespace Rotor {
int i=0;
for (auto& type: type_map) {
if (type.second->description!="") { //blank description = internal/ testing node
- list_node(type,XML,i);
+ list_node(type.second,XML,i);
i++;
}
}
}
+ void list_categories(xmlIO XML){
+ int i=0;
+ for (auto& category: categories) {
+ XML.addTag("category");
+ XML.addAttribute("category","name",category.first,i);
+ XML.pushTag("category",i);
+ int j=0;
+ for (auto& node: category.second){
+ list_node(node,XML,j);
+ j++;
+ }
+ XML.popTag();
+ i++;
+ }
+ }
+ void list_categories(Json::Value &JSON){
+ JSON["categories"]=Json::arrayValue;
+ for (auto& _category: categories) {
+ Json::Value category;
+ category["name"]=_category.first;
+ category["nodes"]=Json::arrayValue;
+ for (auto& _node: _category.second){
+ Json::Value node;
+ node["type"]=_node->type;
+ node["title"]=_node->title;
+ node["inputs"]=_node->duplicate_inputs?"expandable":"fixed";
+ if (dynamic_cast<Signal_node*> (_node)!=nullptr) node["output"]="signal";
+ if (dynamic_cast<Image_node*> (_node)!=nullptr) node["output"]="image";
+ node["description"]=_node->description;
+ if (_node->inputs.size()){
+ node["signal_inputs"]=Json::arrayValue;
+ for (auto& input: _node->inputs) {
+ Json::Value signal_input;
+ signal_input["title"]=input->title;
+ signal_input["description"]=input->description;
+ node["signal_inputs"].append(signal_input);
+ }
+ }
+ if (dynamic_cast<Image_node*> (_node)!=nullptr) {
+ if ((dynamic_cast<Image_node*>(_node))->image_inputs.size()){
+ node["image_inputs"]=Json::arrayValue;
+ for (auto& input: (dynamic_cast<Image_node*>(_node))->image_inputs) {
+ Json::Value image_input;
+ image_input["title"]=input->title;
+ image_input["description"]=input->description;
+ node["image_inputs"].append(image_input);
+ }
+ }
+ }
+ if (_node->parameters.size()){
+ node["parameters"]=Json::arrayValue;
+ for (auto& param: _node->parameters) {
+ Json::Value parameter;
+ parameter["name"]=param.first;
+ parameter["type"]=param.second->type;
+ parameter["title"]=param.second->title;
+ parameter["description"]=param.second->description;
+ parameter["value"]=param.second->value;
+ parameter["min"]=param.second->min;
+ parameter["max"]=param.second->max;
+ node["parameters"].append(parameter);
+ }
+ }
+ if (_node->attributes.size()){
+ node["attributes"]=Json::arrayValue;
+ for (auto& attr: _node->attributes) {
+ Json::Value attribute;
+ attribute["name"]=attr.first;
+ attribute["title"]=attr.second->title;
+ attribute["description"]=attr.second->description;
+ attribute["value"]=attr.second->value;
+ if (attr.second->vals.size()){ //document attribute enumeration
+ attribute["type"]="enum";
+ attribute["options"]=Json::arrayValue;
+ for (auto val: attr.second->vals){
+ attribute["options"].append(val);
+ }
+ }
+ else attribute["type"]="string";
+ node["attributes"].append(attribute);
+ }
+ }
+ category["nodes"].append(node);
+ }
+ JSON["categories"].append(category);
+ }
+ }
void list_nodes(Json::Value &JSON){
JSON["nodeslist"]=Json::arrayValue;
for (auto& type: type_map) {
@@ -1211,6 +1303,7 @@ namespace Rotor {
}
private:
unordered_map<string,Node*> type_map;
+ unordered_map<string,vector<Rotor::Node*> > categories;
};
}