From a31d487dd9474567bc12a0af7c9031350f1e192a Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sat, 11 Jan 2014 21:32:17 +0000 Subject: input array logic --- NT/src/factory.cpp | 14 ++++++++------ NT/src/nodes.h | 6 +++--- NT/src/rotor.h | 13 +++++++++---- 3 files changed, 20 insertions(+), 13 deletions(-) (limited to 'NT/src') diff --git a/NT/src/factory.cpp b/NT/src/factory.cpp index 6c1c825..3567f83 100644 --- a/NT/src/factory.cpp +++ b/NT/src/factory.cpp @@ -44,16 +44,18 @@ Json::Value Node_factory::list_node(Rotor::Node* _node){ string type=var.second->get_type(); Json::Value newvar; newvar["type"]=type; - if (type=="array"){ - newvar["array"]=Json::arrayValue; - for (auto& element: var.second->values) { - newvar["array"].append(newvalue); + newvar["connectable"]=var.second->connectable?"yes":"no"; + if (dynamic_cast(var.second)){ + newvar["input"]=Json::arrayValue; + for (auto& element: dynamic_cast(var.second)->values) { + Json::Value newvalue; + newvar["input"].append(newvalue); } } else { - newvar["connectable"]=var.second->connectable?"yes":"no"; - node["vars"].append(newvar); + newvar["input"]=Json::Value(); } + node["vars"].append(newvar); } } /* diff --git a/NT/src/nodes.h b/NT/src/nodes.h index da24292..f294756 100644 --- a/NT/src/nodes.h +++ b/NT/src/nodes.h @@ -27,7 +27,7 @@ namespace Rotor{ class Multiply: public Double_node { public: Multiply(){ - inlet=create_inlet("inlet"); + inlets=create_array("inlet"); value=create_inlet("value"); node_type="multiply"; } @@ -35,12 +35,12 @@ namespace Rotor{ init(settings); }; const double &get_output(const Frame_parameters &frame){ - result=inlet->get(frame)*value->get(frame); + result=inlets->get(0,frame)*value->get(frame); return result; } Multiply* clone(map &_settings) { return new Multiply(_settings);}; private: - Variable_type *inlet; + Variable_array_type *inlets; Variable_type *value; double result; }; diff --git a/NT/src/rotor.h b/NT/src/rotor.h index e64095c..0b728ac 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -81,9 +81,14 @@ namespace Rotor { } T value; }; - template class Variable_array: public Variable_type { + class Variable_array: public Variable { public: Variable_array(){}; + std::vector values; + }; + template class Variable_array_type: public Variable_array { + public: + Variable_array_type(){}; void add(int num=1){ for (int i=0;i(false); return (dynamic_cast*>(vars[name])); } - template Variable_array* create_array(std::string name){ - vars[name]=new Variable_array(); - return (dynamic_cast*>(vars[name])); + template Variable_array_type* create_array(std::string name){ + vars[name]=new Variable_array_type(); + return (dynamic_cast*>(vars[name])); } }; -- cgit v1.2.3