summaryrefslogtreecommitdiff
path: root/NT/src/rotor.h
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2014-01-14 17:00:14 +0000
committerTim Redfern <tim@eclectronics.org>2014-01-14 17:00:14 +0000
commit874194d055d0c90a7874a06be95ca2e087616a9d (patch)
tree1ca94dde41b6046960475b2091d2b35043a161a5 /NT/src/rotor.h
parent52710ced0e723117afa2d40f3b21e1fa2d1ad2ad (diff)
converting settings initiaiers to json
Diffstat (limited to 'NT/src/rotor.h')
-rw-r--r--NT/src/rotor.h26
1 files changed, 19 insertions, 7 deletions
diff --git a/NT/src/rotor.h b/NT/src/rotor.h
index d261954..30b4ba1 100644
--- a/NT/src/rotor.h
+++ b/NT/src/rotor.h
@@ -30,7 +30,7 @@ struct TypeName<int> {
template <>
struct TypeName<double> {
static const char* Get() {
- return "double";
+ return "number";
}
};
@@ -71,23 +71,26 @@ namespace Rotor {
class Variable { //pure virtual base type for variable pointers
public:
Variable(){connection=nullptr;};
- virtual void init(std::string s)=0;
+ virtual void init(std::string n,std::string s)=0;
virtual ~Variable(){};
virtual bool connect(Node* target)=0;
virtual std::string get_type()=0;
Node* connection;
bool connectable;
+ std::string name;
};
template <class T> class Variable_type : public Variable {
public:
Variable_type(bool _c){connectable=_c;};
- void init(std::string s){
+ void init(std::string n,std::string s){
std::istringstream cur(s);
cur >> value;
+ name=n;
}
std::string get_type(){ //need this to output node templates
return TypeName<T>::Get();
}
+//have to cast connect and get_output to use templated return types
bool connect(Node* target){
if (connectable){
if (dynamic_cast<Node_type<T>*>(target)){
@@ -112,10 +115,11 @@ namespace Rotor {
};
template <class T> class Variable_array_type: public Variable_array {
public:
- Variable_array_type(){};
- void init(std::string s){
+ Variable_array_type(){connectable=true;};
+ void init(std::string n,std::string s){
std::istringstream cur(s);
cur >> value;
+ name=n;
}
std::string get_type(){ //need this to output node templates
return TypeName<T>::Get();
@@ -176,9 +180,9 @@ namespace Rotor {
Json::Value list_json();
virtual Node* clone(std::map<std::string,std::string> &_settings)=0;
virtual std::string output_type()=0;
- std::string node_type;
- std::string node_id;
+ std::string type;
std::string id;
+ std::string type_id;
std::string description;
std::string title;
std::string ui_type;
@@ -195,6 +199,14 @@ namespace Rotor {
}
}
}
+ void init(Json::Value settings){
+ for (auto s:settings["input"].Members) {
+ if (vars.find(s.first)!=vars.end()){
+ vars[s.first]->init(s.second);
+ //printf("set %s to %s\n",s.first.c_str(),s.second.c_str());
+ }
+ }
+ }
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);