From 52710ced0e723117afa2d40f3b21e1fa2d1ad2ad Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 13 Jan 2014 16:49:20 +0000 Subject: TypeNames --- NT/src/rotor.h | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'NT/src/rotor.h') diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 0b728ac..d261954 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -1,6 +1,8 @@ #ifndef ROTOR_H #define ROTOR_H +#define ENABLE_TYPENAME(A) template<> struct TypeName { static const char *Get() { return #A; }}; + #include #include #include @@ -8,7 +10,29 @@ #include #include #include +#include + +template +struct TypeName +{ + static const char* Get() + { + return typeid(T).name(); + } +}; +template <> +struct TypeName { + static const char* Get() { + return "int"; + } +}; +template <> +struct TypeName { + static const char* Get() { + return "double"; + } +}; namespace Rotor { @@ -62,7 +86,7 @@ namespace Rotor { cur >> value; } std::string get_type(){ //need this to output node templates - return "unknown"; + return TypeName::Get(); } bool connect(Node* target){ if (connectable){ @@ -89,6 +113,22 @@ namespace Rotor { template class Variable_array_type: public Variable_array { public: Variable_array_type(){}; + void init(std::string s){ + std::istringstream cur(s); + cur >> value; + } + std::string get_type(){ //need this to output node templates + return TypeName::Get(); + } + bool connect(Node* target){ + if (connectable){ + if (dynamic_cast*>(target)){ + connection=target; + return true; + } + } + return false; + } void add(int num=1){ for (int i=0;i &_settings)=0; + virtual std::string output_type()=0; std::string node_type; std::string node_id; std::string id; std::string description; std::string title; std::string ui_type; - std::string output_type; std::unordered_map vars; }; template class Node_type : public Node { @@ -154,6 +195,7 @@ namespace Rotor { } } } + std::string output_type(){return TypeName::Get();}; template Variable_type* create_inlet(std::string name){ vars[name]=new Variable_type(true); return (dynamic_cast*>(vars[name])); -- cgit v1.2.3