From 6ae7506f595d45e752ffd0cebb6392c707db2d3c Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 20 Jan 2014 15:39:23 +0000 Subject: making json loader --- NT/src/rotor.h | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'NT/src/rotor.h') diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 040435b..4d73050 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -1,6 +1,14 @@ #ifndef ROTOR_H #define ROTOR_H +/* +ROTORD rewrite + +TJR-Jan-2014 + +NB when plugging in to framework - convert all cerr messages to logged +*/ + #define ENABLE_TYPENAME(A) template<> struct TypeName { static const char *Get() { return #A; }}; #include @@ -22,19 +30,19 @@ struct TypeName }; template <> -struct TypeName { +struct TypeName { static const char* Get() { return "int"; } }; template <> -struct TypeName { +struct TypeName { static const char* Get() { return "number"; } }; template <> -struct TypeName { +struct TypeName { static const char* Get() { return "string"; } @@ -154,16 +162,16 @@ namespace Rotor { } return false; } - void add(std::string _name="",bool _connectable=true,int num=1){ + void add(std::string _name="",bool _connectable=true,int num=1){ for (int i=0;i(_name,_connectable)); } - bool connect(int which,Node* target){ + bool connect(uint32_t which,Node* target){ if (values.size()>which){ return values[which].connect(target); } return false; } - const T& get(int which,const Frame_parameters &frame){ + const T& get(uint32_t which,const Frame_parameters &frame){ if (values.size()>which){ return values[which].get(frame); } @@ -205,6 +213,7 @@ namespace Rotor { Json::Value to_json(); virtual Node* clone(Json::Value &_settings)=0; virtual std::string get_output_type()=0; + std::unordered_map vars; protected: std::string type; std::string id; @@ -212,18 +221,17 @@ namespace Rotor { std::string description; std::string title; std::string ui_type; - std::unordered_map vars; }; template class Node_type : public Node { public: virtual const NT& get_output(const Frame_parameters &frame)=0; - void init(Json::Value settings){ - if (settings["vars"]!=nullptr){ + void init(Json::Value settings){ + if (!settings["vars"].empty()){ for ( uint32_t i = 0; i < settings["vars"].size(); ++i ) { vars[settings["vars"][i]["name"].asString()]->init(settings["vars"][i]); } } - if (settings["id"]!=nullptr) id=settings["id"].asString(); + if (!settings["id"].empty()) id=settings["id"].asString(); } std::string get_output_type(){return TypeName::Get();}; template Variable_type* create_inlet(std::string name){ @@ -239,7 +247,7 @@ namespace Rotor { return (dynamic_cast*>(vars[name])); } }; - + } #endif //ROTOR_H -- cgit v1.2.3