Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 13.98 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //--------------------------------------------------------------------------
  2.         //
  3.         // template class NeuroneFunction0
  4.         //
  5.         //--------------------------------------------------------------------------
  6.        
  7.         template <class Func, class Ret>
  8.         class NeuroneFunction0 : public Neurone {
  9.  
  10.                 Func func;
  11.                 Str def;
  12.                
  13.                 void onValueGet() {
  14.                         getOutput(0).setValue(TypeToVariable <Ret> (func()).value);
  15.                 }
  16.        
  17.         public:
  18.                
  19.                 NeuroneFunction0(const char *def_, Func func_, const char *ret_name) {
  20.                         def = def_;
  21.                         func = func_;
  22.                        
  23.                         Output *output = new Output(this);
  24.                         output->getVariable().setType <Ret> ();
  25.                         addOutput(ret_name, output);
  26.                         output->setOnGetValueAction(Common::Action::create(this, &NeuroneFunction0 <Func, Ret> ::onValueGet));
  27.            
  28.                 }
  29.  
  30.                 //
  31.                 virtual const char *getType() const {
  32.                         return def;
  33.                 }
  34.  
  35.  
  36.                 Neurone *clone() const {
  37.                         return new NeuroneFunction0 <Func, Ret> (def, func, getOutputName(0));
  38.                 }
  39.  
  40.         };
  41.        
  42.         template <class Func>
  43.         class NeuroneFunction0 <Func, void> : public Neurone {
  44.  
  45.                 Anandamide::Action *in;
  46.                 Anandamide::Event *out;
  47.                 Func func;
  48.                 Str def;
  49.                
  50.         public:
  51.                
  52.                 NeuroneFunction0(const char *def_, Func func_, const char *ret_name) {
  53.                         def = def_;
  54.                         func = func_;
  55.                         in = createAction(this, &NeuroneFunction0 <Func> ::run);
  56.                         out = new Event();
  57.                         addAction("in", in);
  58.                         addEvent("out", out);
  59.                 }
  60.  
  61.                 //
  62.                 virtual const char *getType() const {
  63.                         return def;
  64.                 }
  65.                
  66.                 void run() {
  67.                         func();
  68.                         out->run();
  69.                 }
  70.  
  71.                 Neurone *clone() const {
  72.                         return new NeuroneFunction0 <Func, void> (def, func, "");
  73.                 }
  74.  
  75.         };
  76.  
  77.         //--------------------------------------------------------------------------
  78.         //
  79.         // template class NeuroneFunction1
  80.         //
  81.         //--------------------------------------------------------------------------
  82.        
  83.         template <class Func, class Ret, class A0>
  84.         class NeuroneFunction1 : public Neurone {
  85.  
  86.                 Func func;
  87.                 Str def;
  88.                
  89.                 void onValueGet() {
  90.                         getOutput(0).setValue(TypeToVariable <Ret> (func(VariableToType <A0> (getInput(0).getValue()).value)).value);
  91.         }
  92.        
  93.         public:
  94.                
  95.                 NeuroneFunction1(const char *def_, Func func_, const char *ret_name, const char *a0_name) {
  96.                         def = def_;
  97.                         func = func_;
  98.  
  99.                         Output *output = new Output(this);
  100.                         output->getVariable().setType <Ret> ();
  101.                         addOutput(ret_name, output);
  102.                         output->setOnGetValueAction(Common::Action::create(this, &NeuroneFunction1 <Func, Ret, A0> ::onValueGet));
  103.  
  104.                         Input *input = new Input(Variable());
  105.                         input->getVariable().setType <A0> ();
  106.                         addInput(a0_name, input);
  107.                 }
  108.  
  109.                 //
  110.                 virtual const char *getType() const {
  111.                         return def;
  112.                 }
  113.  
  114.                 Neurone *clone() const {
  115.                         return new NeuroneFunction1 <Func, Ret, A0> (def, func, getOutputName(0), getInputName(0));
  116.                 }
  117.                
  118.  
  119.         };
  120.        
  121.         template <class Func, class A0>
  122.         class NeuroneFunction1 <Func, void, A0> : public Neurone {
  123.  
  124.                 Anandamide::Action *in;
  125.                 Anandamide::Event *out;
  126.                 Func func;
  127.                 Str def;
  128.                
  129.         public:
  130.                
  131.                 NeuroneFunction1(const char *def_, Func func_, const char *ret_name, const char *a0_name) {
  132.                         def = def_;
  133.                         func = func_;
  134.                         in = createAction(this, &NeuroneFunction1 <Func, void, A0> ::run);
  135.                         out = new Event();
  136.                         addAction("in", in);
  137.                         addEvent("out", out);
  138.                        
  139.                         Input *input = new Input(Variable());
  140.                         input->getVariable().setType <A0> ();
  141.                         addInput(a0_name, input);
  142.                 }
  143.  
  144.                 //
  145.                 virtual const char *getType() const {
  146.                         return def;
  147.                 }
  148.                
  149.                 void run() {
  150.                         func(VariableToType <A0> (getInput(0).getValue()).value);
  151.                         out->run();
  152.                 }
  153.  
  154.                 Neurone *clone() const {
  155.                         return new NeuroneFunction1 <Func, void, A0> (def, func, "", getInputName(0));
  156.                 }
  157.  
  158.         };
  159.  
  160.         //--------------------------------------------------------------------------
  161.         //
  162.         // template class NeuroneFunction2
  163.         //
  164.         //--------------------------------------------------------------------------
  165.        
  166.         template <class Func, class Ret, class A0, class A1>
  167.         class NeuroneFunction2 : public Neurone {
  168.  
  169.                 Func func;
  170.                 Str def;
  171.                
  172.                 void onValueGet() {
  173.                         getOutput(0).setValue(TypeToVariable <Ret> (
  174.                                 func(
  175.                                         VariableToType <A0> (getInput(0).getValue()).value,
  176.                                         VariableToType <A1> (getInput(1).getValue()).value
  177.                                 )
  178.                         ).value);
  179.         }
  180.        
  181.         public:
  182.                
  183.                 NeuroneFunction2(const char *def_, Func func_, const char *ret_name, const char *a0_name, const char *a1_name) {
  184.                         def = def_;
  185.                         func = func_;
  186.  
  187.                         Output *output = new Output(this);
  188.                         output->getVariable().setType <Ret> ();
  189.                         addOutput(ret_name, output);
  190.                         output->setOnGetValueAction(Common::Action::create(this, &NeuroneFunction2 <Func, Ret, A0, A1> ::onValueGet));
  191.  
  192.                         Input *input = new Input(Variable());
  193.                         input->getVariable().setType <A0> ();
  194.                         addInput(a0_name, input);
  195.  
  196.                         input = new Input(Variable());
  197.                         input->getVariable().setType <A1> ();
  198.                         addInput(a1_name, input);
  199.                        
  200.                 }
  201.  
  202.                 //
  203.                 virtual const char *getType() const {
  204.                         return def;
  205.                 }
  206.                
  207.                 Neurone *clone() const {
  208.                         return new NeuroneFunction2 <Func, Ret, A0, A1> (def, func, getOutputName(0), getInputName(0), getInputName(1));
  209.                 }
  210.                
  211.  
  212.         };
  213.        
  214.         template <class Func, class A0, class A1>
  215.         class NeuroneFunction2 <Func, void, A0, A1> : public Neurone {
  216.  
  217.                 Anandamide::Action *in;
  218.                 Anandamide::Event *out;
  219.                 Func func;
  220.                 Str def;
  221.                
  222.         public:
  223.                
  224.                 NeuroneFunction2(const char *def_, Func func_, const char *ret_name, const char *a0_name, const char *a1_name) {
  225.                         def = def_;
  226.                         func = func_;
  227.                         in = createAction(this, &NeuroneFunction2 <Func, void, A0, A1> ::run);
  228.                         out = new Event();
  229.                         addAction("in", in);
  230.                         addEvent("out", out);
  231.                        
  232.                         Input *input = new Input(Variable());
  233.                         input->getVariable().setType <A0> ();
  234.                         addInput(a0_name, input);
  235.  
  236.                         input = new Input(Variable());
  237.                         input->getVariable().setType <A1> ();
  238.                         addInput(a1_name, input);
  239.                        
  240.                 }
  241.  
  242.                 //
  243.                 virtual const char *getType() const {
  244.                         return def;
  245.                 }
  246.                
  247.                 void run() {
  248.                         func(
  249.                                 VariableToType <A0> (getInput(0).getValue()).value,
  250.                                 VariableToType <A1> (getInput(1).getValue()).value
  251.                         );
  252.                         out->run();
  253.                 }
  254.  
  255.                 Neurone *clone() const {
  256.                         return new NeuroneFunction2 <Func, void, A0, A1> (def, func, "", getInputName(0), getInputName(1));
  257.                 }
  258.  
  259.         };
  260.  
  261.         //--------------------------------------------------------------------------
  262.         //
  263.         // template class NeuroneFunction3
  264.         //
  265.         //--------------------------------------------------------------------------
  266.        
  267.         template <class Func, class Ret, class A0, class A1, class A2>
  268.         class NeuroneFunction3 : public Neurone {
  269.  
  270.                 Func func;
  271.                 Str def;
  272.                
  273.                 void onValueGet() {
  274.                         getOutput(0).setValue(TypeToVariable <Ret> (
  275.                                 func(
  276.                                         VariableToType <A0> (getInput(0).getValue()).value,
  277.                                         VariableToType <A1> (getInput(1).getValue()).value,
  278.                                         VariableToType <A2> (getInput(2).getValue()).value
  279.                                 )
  280.                         ).value);
  281.                 }
  282.        
  283.         public:
  284.                
  285.                 NeuroneFunction3(const char *def_, Func func_, const char *ret_name, const char *a0_name, const char *a1_name, const char *a2_name) {
  286.                         def = def_;
  287.                         func = func_;
  288.  
  289.                         Output *output = new Output(this);
  290.                         output->getVariable().setType <Ret> ();
  291.                         addOutput(ret_name, output);
  292.                         output->setOnGetValueAction(Common::Action::create(this, &NeuroneFunction3 <Func, Ret, A0, A1, A2> ::onValueGet));
  293.  
  294.                         Input *input = new Input(Variable());
  295.                         input->getVariable().setType <A0> ();
  296.                         addInput(a0_name, input);
  297.  
  298.                         input = new Input(Variable());
  299.                         input->getVariable().setType <A1> ();
  300.                         addInput(a1_name, input);
  301.                        
  302.                         input = new Input(Variable());
  303.                         input->getVariable().setType <A2> ();
  304.                         addInput(a2_name, input);
  305.                 }
  306.  
  307.                 //
  308.                 virtual const char *getType() const {
  309.                         return def;
  310.                 }
  311.                
  312.                 Neurone *clone() const {
  313.                         return new NeuroneFunction3 <Func, Ret, A0, A1, A2> (def, func, getOutputName(0), getInputName(0), getInputName(1), getInputName(2));
  314.                 }
  315.                
  316.  
  317.         };
  318.        
  319.         template <class Func, class A0, class A1, class A2>
  320.         class NeuroneFunction3 <Func, void, A0, A1, A2> : public Neurone {
  321.  
  322.                 Anandamide::Action *in;
  323.                 Anandamide::Event *out;
  324.                 Func func;
  325.                 Str def;
  326.                
  327.         public:
  328.                
  329.                 NeuroneFunction3(const char *def_, Func func_, const char *ret_name, const char *a0_name, const char *a1_name, const char *a2_name) {
  330.                         def = def_;
  331.                         func = func_;
  332.                         in = createAction(this, &NeuroneFunction3 <Func, void, A0, A1, A2> ::run);
  333.                         out = new Event();
  334.                         addAction("in", in);
  335.                         addEvent("out", out);
  336.                        
  337.                         Input *input = new Input(Variable());
  338.                         input->getVariable().setType <A0> ();
  339.                         addInput(a0_name, input);
  340.  
  341.                         input = new Input(Variable());
  342.                         input->getVariable().setType <A1> ();
  343.                         addInput(a1_name, input);
  344.  
  345.                         input = new Input(Variable());
  346.                         input->getVariable().setType <A2> ();
  347.                         addInput(a2_name, input);
  348.                        
  349.                        
  350.                 }
  351.  
  352.                 //
  353.                 virtual const char *getType() const {
  354.                         return def;
  355.                 }
  356.                
  357.                 void run() {
  358.                         func(
  359.                                 VariableToType <A0> (getInput(0).getValue()).value,
  360.                                 VariableToType <A1> (getInput(1).getValue()).value,
  361.                                 VariableToType <A2> (getInput(2).getValue()).value
  362.                         );
  363.                         out->run();
  364.                 }
  365.  
  366.                 Neurone *clone() const {
  367.                         return new NeuroneFunction3 <Func, void, A0, A1, A2> (def, func, "", getInputName(0), getInputName(1), getInputName(2));
  368.                 }
  369.  
  370.         };
  371.        
  372.         //--------------------------------------------------------------------------
  373.         //
  374.         // template class NeuroneFunction4
  375.         //
  376.         //--------------------------------------------------------------------------
  377.        
  378.         template <class Func, class Ret, class A0, class A1, class A2, class A3>
  379.         class NeuroneFunction4 : public Neurone {
  380.  
  381.                 Func func;
  382.                 Str def;
  383.                
  384.                 void onValueGet() {
  385.                         getOutput(0).setValue(TypeToVariable <Ret> (
  386.                                 func(
  387.                                         VariableToType <A0> (getInput(0).getValue()).value,
  388.                                         VariableToType <A1> (getInput(1).getValue()).value,
  389.                                         VariableToType <A2> (getInput(2).getValue()).value,
  390.                                         VariableToType <A3> (getInput(3).getValue()).value
  391.                                 )
  392.                         ).value);
  393.                 }
  394.        
  395.         public:
  396.                
  397.                 NeuroneFunction4(const char *def_, Func func_, const char *ret_name, const char *a0_name, const char *a1_name, const char *a2_name, const char *a3_name) {
  398.                         def = def_;
  399.                         func = func_;
  400.  
  401.                         Output *output = new Output(this);
  402.                         output->getVariable().setType <Ret> ();
  403.                         addOutput(ret_name, output);
  404.                         output->setOnGetValueAction(Common::Action::create(this, &NeuroneFunction4 <Func, Ret, A0, A1, A2, A3> ::onValueGet));
  405.  
  406.                         Input *input = new Input(Variable());
  407.                         input->getVariable().setType <A0> ();
  408.                         addInput(a0_name, input);
  409.  
  410.                         input = new Input(Variable());
  411.                         input->getVariable().setType <A1> ();
  412.                         addInput(a1_name, input);
  413.                        
  414.                         input = new Input(Variable());
  415.                         input->getVariable().setType <A2> ();
  416.                         addInput(a2_name, input);
  417.  
  418.                         input = new Input(Variable());
  419.                         input->getVariable().setType <A3> ();
  420.                         addInput(a3_name, input);
  421.                        
  422.                 }
  423.  
  424.                 //
  425.                 virtual const char *getType() const {
  426.                         return def;
  427.                 }
  428.                
  429.                 Neurone *clone() const {
  430.                         return new NeuroneFunction4 <Func, Ret, A0, A1, A2, A3> (def, func, getOutputName(0), getInputName(0), getInputName(1), getInputName(2), getInputName(3));
  431.                 }
  432.                
  433.  
  434.         };
  435.        
  436.         template <class Func, class A0, class A1, class A2, class A3>
  437.         class NeuroneFunction4 <Func, void, A0, A1, A2, A3> : public Neurone {
  438.  
  439.                 Anandamide::Action *in;
  440.                 Anandamide::Event *out;
  441.                 Func func;
  442.                 Str def;
  443.                
  444.         public:
  445.                
  446.                 NeuroneFunction4(const char *def_, Func func_, const char *ret_name, const char *a0_name, const char *a1_name, const char *a2_name, const char *a3_name) {
  447.                         def = def_;
  448.                         func = func_;
  449.                         in = createAction(this, &NeuroneFunction4 <Func, void, A0, A1, A2, A3> ::run);
  450.                         out = new Event();
  451.                         addAction("in", in);
  452.                         addEvent("out", out);
  453.                        
  454.                         Input *input = new Input(Variable());
  455.                         input->getVariable().setType <A0> ();
  456.                         addInput(a0_name, input);
  457.  
  458.                         input = new Input(Variable());
  459.                         input->getVariable().setType <A1> ();
  460.                         addInput(a1_name, input);
  461.  
  462.                         input = new Input(Variable());
  463.                         input->getVariable().setType <A2> ();
  464.                         addInput(a2_name, input);
  465.                        
  466.                         input = new Input(Variable());
  467.                         input->getVariable().setType <A3> ();
  468.                         addInput(a3_name, input);
  469.                        
  470.                 }
  471.  
  472.                 //
  473.                 virtual const char *getType() const {
  474.                         return def;
  475.                 }
  476.                
  477.                 void run() {
  478.                         func(
  479.                                 VariableToType <A0> (getInput(0).getValue()).value,
  480.                                 VariableToType <A1> (getInput(1).getValue()).value,
  481.                                 VariableToType <A2> (getInput(2).getValue()).value,
  482.                                 VariableToType <A3> (getInput(3).getValue()).value
  483.                         );
  484.                         out->run();
  485.                 }
  486.  
  487.                 Neurone *clone() const {
  488.                         return new NeuroneFunction4 <Func, void, A0, A1, A2, A3> (def, func, "", getInputName(0), getInputName(1), getInputName(2), getInputName(3));
  489.                 }
  490.  
  491.         };
  492.        
  493.  
  494.         static template <class Ret>
  495.         Neurone *makeNeuroneFunction0(const char *def, Ret (*func)(), const char *ret_name) {
  496.                 return new NeuroneFunction0 <Ret (*)(), Ret> (def, func, ret_name);
  497.         }
  498.        
  499.         static template <class Ret, class A0>
  500.         Neurone *makeNeuroneFunction1(const char *def, Ret (*func)(A0), const char *ret_name, const char *a0_name) {
  501.                 return new NeuroneFunction1 <Ret (*)(A0), Ret, A0> (def, func, ret_name, a0_name);
  502.         }
  503.  
  504.         static template <class Ret, class A0, class A1>
  505.         Neurone *makeNeuroneFunction2(const char *def, Ret (*func)(A0, A1), const char *ret_name, const char *a0_name, const char *a1_name) {
  506.                 return new NeuroneFunction2 <Ret (*)(A0, A1), Ret, A0, A1> (def, func, ret_name, a0_name, a1_name);
  507.         }
  508.  
  509.         static template <class Ret, class A0, class A1, class A2>
  510.         Neurone *makeNeuroneFunction3(const char *def, Ret (*func)(A0, A1, A2), const char *ret_name, const char *a0_name, const char *a1_name, const char *a2_name) {
  511.                 return new NeuroneFunction3 <Ret (*)(A0, A1, A2), Ret, A0, A1, A2> (def, func, ret_name, a0_name, a1_name, a2_name);
  512.         }
  513.  
  514.         static template <class Ret, class A0, class A1, class A2, class A3>
  515.         Neurone *makeNeuroneFunction4(const char *def, Ret (*func)(A0, A1, A2, A3), const char *ret_name, const char *a0_name, const char *a1_name, const char *a2_name, const char *a3_name) {
  516.                 return new NeuroneFunction4 <Ret (*)(A0, A1, A2, A3), Ret, A0, A1, A2, A3> (def, func, ret_name, a0_name, a1_name, a2_name, a3_name);
  517.         }