summaryrefslogtreecommitdiff
path: root/NT/src/rotor.h
diff options
context:
space:
mode:
Diffstat (limited to 'NT/src/rotor.h')
-rw-r--r--NT/src/rotor.h46
1 files changed, 44 insertions, 2 deletions
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<A> { static const char *Get() { return #A; }};
+
#include <string>
#include <sstream>
#include <iostream>
@@ -8,7 +10,29 @@
#include <vector>
#include <unordered_map>
#include <json/json.h>
+#include <typeinfo>
+
+template <typename T>
+struct TypeName
+{
+ static const char* Get()
+ {
+ return typeid(T).name();
+ }
+};
+template <>
+struct TypeName<int> {
+ static const char* Get() {
+ return "int";
+ }
+};
+template <>
+struct TypeName<double> {
+ 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<T>::Get();
}
bool connect(Node* target){
if (connectable){
@@ -89,6 +113,22 @@ namespace Rotor {
template <class T> 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<T>::Get();
+ }
+ bool connect(Node* target){
+ if (connectable){
+ if (dynamic_cast<Node_type<T>*>(target)){
+ connection=target;
+ return true;
+ }
+ }
+ return false;
+ }
void add(int num=1){
for (int i=0;i<num;i++) values.push_back(T());
}
@@ -133,14 +173,15 @@ namespace Rotor {
}
return false;
}
+ Json::Value list_json();
virtual Node* clone(std::map<std::string,std::string> &_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<std::string,Variable*> vars;
};
template <class NT> class Node_type : public Node {
@@ -154,6 +195,7 @@ namespace Rotor {
}
}
}
+ std::string output_type(){return TypeName<NT>::Get();};
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]));