summaryrefslogtreecommitdiff
path: root/NT
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2014-01-15 16:38:45 +0000
committerTim Redfern <tim@eclectronics.org>2014-01-15 16:38:45 +0000
commit4f840c4ffee84df757bb593e8f3efe631235e521 (patch)
tree59577df1dec952e92d5cfbf06eb9d805e57dd72b /NT
parent874194d055d0c90a7874a06be95ca2e087616a9d (diff)
json loading
Diffstat (limited to 'NT')
-rw-r--r--NT/src/rotor.cpp4
-rw-r--r--NT/src/rotor.h24
2 files changed, 25 insertions, 3 deletions
diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp
index 96e4250..faea5f0 100644
--- a/NT/src/rotor.cpp
+++ b/NT/src/rotor.cpp
@@ -22,8 +22,8 @@ Json::Value Node::list_json(){
for (auto& var: vars) {
string type=var.second->get_type();
Json::Value newvar;
- newvar["type"]=type;
- newvar["name"]=name;
+ newvar["type"]=var.second->get_type();
+ newvar["name"]=var.second->name;
newvar["connectable"]=var.second->connectable?"yes":"no";
if (dynamic_cast<Variable_array*>(var.second)){
newvar["input"]=Json::arrayValue;
diff --git a/NT/src/rotor.h b/NT/src/rotor.h
index 30b4ba1..6fed8df 100644
--- a/NT/src/rotor.h
+++ b/NT/src/rotor.h
@@ -72,6 +72,7 @@ namespace Rotor {
public:
Variable(){connection=nullptr;};
virtual void init(std::string n,std::string s)=0;
+ virtual void init(Json::Value s)=0;
virtual ~Variable(){};
virtual bool connect(Node* target)=0;
virtual std::string get_type()=0;
@@ -87,6 +88,11 @@ namespace Rotor {
cur >> value;
name=n;
}
+ void init(Json::Value s){
+ std::istringstream cur(s["value"].asString());
+ cur >> value;
+ name=s["name"].asString();
+ }
std::string get_type(){ //need this to output node templates
return TypeName<T>::Get();
}
@@ -121,6 +127,11 @@ namespace Rotor {
cur >> value;
name=n;
}
+ void init(Json::Value s){
+ std::istringstream cur(s["value"].asString());
+ cur >> value;
+ name=s["name"].asString();
+ }
std::string get_type(){ //need this to output node templates
return TypeName<T>::Get();
}
@@ -199,13 +210,24 @@ namespace Rotor {
}
}
}
- void init(Json::Value settings){
+ void init(Json::Value settings){
+ if (settings["vars"]){
+ for ( uint32_t i = 0; i < settings["vars"].size(); ++i ) {
+ vars[settings["vars"][i]["name"].asString()]->init(settings["vars"][i]);
+ }
+ }
+
+ /*
+
+
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());
}
}
+ */
+ if (settings["id"]) id=settings["id"];
}
std::string output_type(){return TypeName<NT>::Get();};
template <class IT> Variable_type<IT>* create_inlet(std::string name){