summaryrefslogtreecommitdiff
path: root/NT/src/rotor.h
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2014-01-24 17:00:22 +0000
committerTim Redfern <tim@eclectronics.org>2014-01-24 17:00:22 +0000
commit1f2bc21fd5ee9bff4fce190d7bb0ee4462e76e87 (patch)
treee42440db80a363c503e1e0b552631adbb194c245 /NT/src/rotor.h
parent913bb43738c7d7391cd990ff1fc3f261afdf78ee (diff)
logging in nodes and text_render proof of concept
Diffstat (limited to 'NT/src/rotor.h')
-rw-r--r--NT/src/rotor.h34
1 files changed, 23 insertions, 11 deletions
diff --git a/NT/src/rotor.h b/NT/src/rotor.h
index 5023a95..4a9eb70 100644
--- a/NT/src/rotor.h
+++ b/NT/src/rotor.h
@@ -7,6 +7,8 @@ ROTORD rewrite
TJR-Jan-2014
NB when plugging in to framework - convert all cerr messages to logged
+
+What next?
*/
#define ENABLE_TYPENAME(A) template<> struct TypeName<A> { static const char *Get() { return #A; }};
@@ -119,14 +121,15 @@ namespace Rotor {
virtual void init(Json::Value s)=0;
virtual bool connect(Node* target)=0;
virtual std::string get_type()=0;
- virtual void create_connection(std::unordered_map<std::string,Node*> &nodes)=0;
+ virtual bool create_connection(std::unordered_map<std::string,Node*> &nodes)=0;
bool is_connected(){
if (connection) return true;
return false;
}
std::string get_connection_id();
- std::string name;
+ std::string get_name();
protected:
+ std::string name;
Node* connection;
bool connectable;
std::string input;
@@ -144,16 +147,13 @@ namespace Rotor {
name=s["name"].asString();
input=s["input"].asString();
}
- void create_connection(std::unordered_map<std::string,Node*> &nodes){
+ bool create_connection(std::unordered_map<std::string,Node*> &nodes){
for (auto node:nodes){
if (node.first==input){
- if (connect(node.second)) {
- if (connection) std::cerr<<"connected '"<<TypeName<T>::Get()<<"' input to '"<<(dynamic_cast<Node_type<T>*>(connection))->get_type()<<"' "<<input<<std::endl;
- //else std::cerr<<"connection disappeared"<<std::endl;
- }
- //else std::cerr<<"could not connect '"<<TypeName<T>::Get()<<"'' input to '"<<input<<"'"<<std::endl;
+ if (connect(node.second)) return true;
}
}
+ return false;
}
Json::Value to_json();
std::string get_type(){ //need this to output node templates
@@ -199,11 +199,15 @@ namespace Rotor {
}
}
}
- void create_connection(std::unordered_map<std::string,Node*> &nodes){
+ bool create_connection(std::unordered_map<std::string,Node*> &nodes){
+ bool success=true;
//for (auto v:values){ //weirdly does not work even though it seems to! maybe it returns a copy of of the object?
// v.create_connection(nodes);
//}
- for (uint32_t i=0;i<values.size();i++) values[i].create_connection(nodes);
+ for (uint32_t i=0;i<values.size();i++) {
+ if (!values[i].create_connection(nodes)) success=false;
+ }
+ return success;
}
Json::Value to_json();
std::string get_type(){
@@ -271,7 +275,12 @@ namespace Rotor {
virtual Node* clone(Json::Value &_settings)=0;
virtual std::string get_output_type()=0;
void create_connections(std::unordered_map<std::string,Node*> &nodes){
- for (auto var:vars) var.second->create_connection(nodes);
+ Logger& logger = Logger::get(log_id);
+ for (auto var:vars) {
+ if (var.second->create_connection(nodes)) {
+ logger.information("Connected input '"+var.second->get_name()+"' of node '"+id+"' to node "+var.second->get_connection_id());
+ }
+ }
}
protected:
std::unordered_map<std::string,Variable*> vars;
@@ -281,6 +290,7 @@ namespace Rotor {
std::string description;
std::string title;
std::string ui_type;
+ std::string log_id;
};
template <class NT> class Node_type : public Node {
public:
@@ -288,10 +298,12 @@ namespace Rotor {
void init(Json::Value settings){
if (!settings["vars"].empty()){
for ( uint32_t i = 0; i < settings["vars"].size(); ++i ) {
+ if (!settings["id"].empty()) settings["vars"][i]["log_id"]=settings["log_id"].asString();
vars[settings["vars"][i]["name"].asString()]->init(settings["vars"][i]);
}
}
if (!settings["id"].empty()) id=settings["id"].asString();
+ if (!settings["log_id"].empty()) log_id=settings["log_id"].asString();
}
std::string get_output_type(){return TypeName<NT>::Get();};
template <class IT> Variable_type<IT>* create_inlet(std::string name){