summaryrefslogtreecommitdiff
path: root/NT
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2014-01-06 17:39:21 +0000
committerTim Redfern <tim@eclectronics.org>2014-01-06 17:39:21 +0000
commita940710de90c5bc2b9a3e74f19d60c769ab76643 (patch)
treece3740f465effe29ef2ee15ef13901f019273cd8 /NT
parent815d1149f9fb6be2c1bc05fb04f574eb928e050e (diff)
thinking out multi inlets
Diffstat (limited to 'NT')
-rw-r--r--NT/src/nodes.h1
-rw-r--r--NT/src/rotor.cpp47
-rw-r--r--NT/src/rotor.h57
3 files changed, 53 insertions, 52 deletions
diff --git a/NT/src/nodes.h b/NT/src/nodes.h
index 8ce7cdd..a32408e 100644
--- a/NT/src/nodes.h
+++ b/NT/src/nodes.h
@@ -3,7 +3,6 @@
#include "rotor.h"
-
using namespace std;
namespace Rotor{
diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp
index 597ded6..677fae0 100644
--- a/NT/src/rotor.cpp
+++ b/NT/src/rotor.cpp
@@ -5,53 +5,10 @@
#include "factory.h"
using namespace std;
-
-namespace Rotor{
- template <class T>
- void Rotor::Variable_type<T>::init(std::string s){
- std::istringstream cur(s);
- cur >> value;
- }
-
- template <class T>
- bool Rotor::Variable_type<T>::connect(Node* target){
- if (connectable){
- if (dynamic_cast<Node_type<T>*>(target)){
- connection=target;
- return true;
- }
- }
- return false;
- }
- template <class T>
- const T& Rotor::Variable_type<T>::get(const Frame_parameters &frame){
- if (connection){
- return (dynamic_cast<Node_type<T>*>(connection))->get_output(frame);
- }
- return value;
- }
- bool Node::connect(string v,Node *t){
- auto var=vars.find(v);
- if (var!=vars.end()){
- if ((*var).second->connect(t)){
- return true;
- }
- }
- return false;
- }
- template <class NT>
- void Node_type<NT>::init(map<string,string> settings){
- for (auto s:settings) {
- 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());
- }
- };
- }
-}
-
using namespace Rotor;
+//factory generates linker errors if rotor.h implementation is seperated: why?
+
int main(){
Node_factory f;
map<string,string> settings={{"type","time"}};
diff --git a/NT/src/rotor.h b/NT/src/rotor.h
index 49e978f..c83fe63 100644
--- a/NT/src/rotor.h
+++ b/NT/src/rotor.h
@@ -56,11 +56,37 @@ namespace Rotor {
template <class T> class Variable_type : public Variable {
public:
Variable_type(bool _c){connectable=_c;};
- void init(std::string s);
- bool connect(Node* target);
- const T& get(const Frame_parameters &frame);
+ void init(std::string s){
+ std::istringstream cur(s);
+ cur >> value;
+ }
+ bool connect(Node* target){
+ if (connectable){
+ if (dynamic_cast<Node_type<T>*>(target)){
+ connection=target;
+ return true;
+ }
+ }
+ return false;
+ }
+ const T& get(const Frame_parameters &frame){
+ if (connection){
+ return (dynamic_cast<Node_type<T>*>(connection))->get_output(frame);
+ }
+ return value;
+ }
T value;
};
+ //don't forget the dupliicate inlets
+ //it needs to be a property of a var
+ //vars need to be:
+ //std::unordered_map<std::string,std::pair<bool,std::vector<Variable*>>>
+ //??
+ //or could it be that a var has properties
+ //var needs to be a class?
+ //or multi var could be a subclass of var?
+ //with an extra accessor const T& get(int which,const Frame_parameters &frame)
+ //in Node we could have create_multi_inlet() and add_multi_inlet()
class Node { //base type for node pointers
public:
virtual ~Node(){
@@ -68,16 +94,34 @@ namespace Rotor {
delete v.second;
}
}
- bool connect(std::string v,Node *t);
+ bool connect(std::string v,Node *t){
+ auto var=vars.find(v);
+ if (var!=vars.end()){
+ if ((*var).second->connect(t)){
+ return true;
+ }
+ }
+ return false;
+ }
virtual Node* clone(std::map<std::string,std::string> &_settings)=0;
std::string type;
+ std::string type;
+ std::string type;
+ std::string type;
protected:
std::unordered_map<std::string,Variable*> vars;
};
template <class NT> class Node_type : public Node {
public:
virtual const NT& get_output(const Frame_parameters &frame)=0;
- void init(std::map<std::string,std::string> settings);
+ void init(std::map<std::string,std::string> settings){
+ for (auto s:settings) {
+ 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());
+ }
+ }
+ }
template <class IT> Variable_type<IT>* create_inlet(std::string name){
vars[name]=new Variable_type<IT>(true);
return (dynamic_cast<Variable_type<IT>*>(vars[name]));
@@ -87,6 +131,7 @@ namespace Rotor {
return (dynamic_cast<Variable_type<IT>*>(vars[name]));
}
};
+
}
-#endif //ROTOR_H \ No newline at end of file
+#endif //ROTOR_H