summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NT/src/factory.h7
-rw-r--r--NT/src/rotor.cpp2
-rw-r--r--NT/src/rotor.h25
3 files changed, 24 insertions, 10 deletions
diff --git a/NT/src/factory.h b/NT/src/factory.h
index ae8ddc4..b576c49 100644
--- a/NT/src/factory.h
+++ b/NT/src/factory.h
@@ -28,6 +28,13 @@ namespace Rotor {
}
return NULL;
};
+ Node *create(Json::Value &settings){
+ 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,xmlIO XML);
bool list_node(const std::string &t,Json::Value &JSON);
void list_node(Rotor::Node* type,xmlIO XML,int i=0);
diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp
index faea5f0..d244d49 100644
--- a/NT/src/rotor.cpp
+++ b/NT/src/rotor.cpp
@@ -128,4 +128,6 @@ Json::Value js;
f.list_node("multiply",js);
Json::StyledWriter writer;
cerr<<writer.write(js)<<endl;
+f.list_node("print",js);
+cerr<<writer.write(js)<<endl;
}
diff --git a/NT/src/rotor.h b/NT/src/rotor.h
index 6fed8df..0138191 100644
--- a/NT/src/rotor.h
+++ b/NT/src/rotor.h
@@ -33,6 +33,13 @@ struct TypeName<double> {
return "number";
}
};
+template <>
+struct TypeName<std::string> {
+ static const char* Get() {
+ return "string";
+ }
+};
+
namespace Rotor {
@@ -71,7 +78,7 @@ namespace Rotor {
class Variable { //pure virtual base type for variable pointers
public:
Variable(){connection=nullptr;};
- virtual void init(std::string n,std::string s)=0;
+ virtual void init(std::string s)=0;
virtual void init(Json::Value s)=0;
virtual ~Variable(){};
virtual bool connect(Node* target)=0;
@@ -82,11 +89,10 @@ namespace Rotor {
};
template <class T> class Variable_type : public Variable {
public:
- Variable_type(bool _c){connectable=_c;};
- void init(std::string n,std::string s){
+ Variable_type(std::string n,bool _c){name=n;connectable=_c;};
+ void init(std::string s){
std::istringstream cur(s);
cur >> value;
- name=n;
}
void init(Json::Value s){
std::istringstream cur(s["value"].asString());
@@ -121,11 +127,10 @@ namespace Rotor {
};
template <class T> class Variable_array_type: public Variable_array {
public:
- Variable_array_type(){connectable=true;};
- void init(std::string n,std::string s){
+ Variable_array_type(std::string n){name=n;connectable=true;};
+ void init(std::string s){
std::istringstream cur(s);
cur >> value;
- name=n;
}
void init(Json::Value s){
std::istringstream cur(s["value"].asString());
@@ -231,15 +236,15 @@ namespace Rotor {
}
std::string output_type(){return TypeName<NT>::Get();};
template <class IT> Variable_type<IT>* create_inlet(std::string name){
- vars[name]=new Variable_type<IT>(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>(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){
- vars[name]=new Variable_array_type<IT>();
+ vars[name]=new Variable_array_type<IT>(name);
return (dynamic_cast<Variable_array_type<IT>*>(vars[name]));
}
};