summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NT/src/graph.cpp5
-rw-r--r--NT/src/rotor.h47
2 files changed, 38 insertions, 14 deletions
diff --git a/NT/src/graph.cpp b/NT/src/graph.cpp
index 3fec39d..87a7b87 100644
--- a/NT/src/graph.cpp
+++ b/NT/src/graph.cpp
@@ -62,10 +62,7 @@ bool Graph::parse_json(string &data,string &media_path){
//
//node.create_links(nodes)
//will allow the nodes to be passed into each member of a variable array
- for (auto var: node->vars){
-
-
- }
+ node->create_connections(nodes);
nodes[node_id]=node;
}
else cerr << "ERROR: duplicate node '"<<node_id<<"' "<< endl;
diff --git a/NT/src/rotor.h b/NT/src/rotor.h
index 4d73050..0a016a2 100644
--- a/NT/src/rotor.h
+++ b/NT/src/rotor.h
@@ -94,24 +94,37 @@ namespace Rotor {
virtual Json::Value to_json()=0;
virtual void init(Json::Value s)=0;
virtual bool connect(Node* target)=0;
- virtual std::string get_type()=0;
+ virtual std::string get_type()=0;
+ virtual void create_connection(std::unordered_map<std::string,Node*> &nodes)=0;
bool is_connected(){
if (connection) return true;
return false;
}
std::string get_connection_id();
+ std::string name;
protected:
Node* connection;
bool connectable;
- std::string name;
+ std::string input;
};
template <class T> class Variable_type : public Variable {
public:
- Variable_type(std::string _name,bool _connectable){name=_name;connectable=_connectable;};
+ Variable_type(std::string _name="",std::string _input="",bool _connectable=true){name=_name;input=_input;connectable=_connectable;};
void init(Json::Value s){
std::istringstream cur(s["value"].asString());
cur >> value;
name=s["name"].asString();
+ input=s["input"].asString();
+ }
+ void create_connection(std::unordered_map<std::string,Node*> &nodes){
+ for (auto node:nodes){
+ if (node.first==input){
+ if (connect(node.second)) {
+ std::cerr<<"connecting '"<<TypeName<T>::Get()<<"' input to '"<<input<<"'"<<std::endl;
+ }
+ else std::cerr<<"could not connect '"<<TypeName<T>::Get()<<"'' input to '"<<input<<"'"<<std::endl;
+ }
+ }
}
Json::Value to_json();
std::string get_type(){ //need this to output node templates
@@ -139,15 +152,24 @@ namespace Rotor {
class Variable_array: public Variable {
public:
Variable_array(){};
+ protected:
std::vector<Variable> values;
};
template <class T> class Variable_array_type: public Variable_array {
public:
Variable_array_type(std::string n){name=n;connectable=true;};
void init(Json::Value s){
- std::istringstream cur(s["value"].asString());
- cur >> value;
name=s["name"].asString();
+ if (!s["input"].empty()){
+ for (uint32_t i=0;i<s["input"].size();i++){
+ add("",s["input"][i].asString());
+ }
+ }
+ }
+ void create_connection(std::unordered_map<std::string,Node*> &nodes){
+ for (auto v:values){
+ v.create_connection(nodes);
+ }
}
Json::Value to_json();
std::string get_type(){
@@ -162,8 +184,11 @@ namespace Rotor {
}
return false;
}
+ void add(std::string _name,std::string _input,bool _connectable=true){
+ values.push_back(Variable_type<T>(_name,_input,_connectable));
+ }
void add(std::string _name="",bool _connectable=true,int num=1){
- for (int i=0;i<num;i++) values.push_back(Variable_type<T>(_name,_connectable));
+ for (int i=0;i<num;i++) values.push_back(Variable_type<T>(_name,"",_connectable));
}
bool connect(uint32_t which,Node* target){
if (values.size()>which){
@@ -213,8 +238,11 @@ namespace Rotor {
Json::Value to_json();
virtual Node* clone(Json::Value &_settings)=0;
virtual std::string get_output_type()=0;
- std::unordered_map<std::string,Variable*> vars;
+ void create_connections(std::unordered_map<std::string,Node*> &nodes){
+ for (auto var:vars) var.second->create_connection(nodes);
+ }
protected:
+ std::unordered_map<std::string,Variable*> vars;
std::string type;
std::string id;
std::string type_id;
@@ -235,11 +263,11 @@ namespace Rotor {
}
std::string get_output_type(){return TypeName<NT>::Get();};
template <class IT> Variable_type<IT>* create_inlet(std::string name){
- vars[name]=new Variable_type<IT>(name,true);
+ vars[name]=new Variable_type<IT>(name,"",true);
return (dynamic_cast<Variable_type<IT>*>(vars[name]));
}
template <class IT> Variable_type<IT>* create_attribute(std::string name){
- vars[name]=new Variable_type<IT>(name,false);
+ vars[name]=new Variable_type<IT>(name,"",false);
return (dynamic_cast<Variable_type<IT>*>(vars[name]));
}
template <class IT> Variable_array_type<IT>* create_array(std::string name){
@@ -247,7 +275,6 @@ namespace Rotor {
return (dynamic_cast<Variable_array_type<IT>*>(vars[name]));
}
};
-
}
#endif //ROTOR_H