#include #include "rotor.h" #include "nodes.h" using namespace std; using namespace Rotor; template void Rotor::Variable_type::init(std::string s){ std::istringstream cur(s); cur >> value; } template bool Rotor::Variable_type::connect(Node* target){ if (connectable){ if (dynamic_cast*>(target)){ connection=target; return true; } } return false; } template const T& Rotor::Variable_type::get(const Frame_parameters &frame){ if (connection){ return (dynamic_cast*>(connection))->get_output(frame); } return value; } template void Node_type::init(map 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 bool Node_type::connect(string v,Node *t){ auto var=vars.find(v); if (var!=vars.end()){ if ((*var).second->connect(t)){ return true; } } return false; } template template Variable_type* Node_type::create_inlet(std::string name){ vars[name]=new Variable_type(true); return (dynamic_cast*>(vars[name])); } template template Variable_type* Node_type::create_attribute(std::string name){ vars[name]=new Variable_type(false); return (dynamic_cast*>(vars[name])); } int main(){ Rotor::time t; multiply m; map settings={{"value","2"}}; m.init(settings); if (!m.connect("inlet",&t)) printf("not connected...\n"); Rotor::print p; if (!p.connect("inlet",&m)) printf("not connected...\n"); for (double t=0;t<10.0;t+=0.765){ Frame_parameters f=Frame_parameters(t,25.0,10.0,640,360); printf("%04f %s\n",t,p.get_output(f).c_str()); } }