All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
signal_function.h
1 /* Copyright (C) MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: markus.ms.schneider@gmail.com
18  */
19 
20 #ifndef _SIGNAL_FUNCTION_H_
21 #define _SIGNAL_FUNCTION_H_
22 
23 #include "mbsim/functions/function.h"
24 #include "mbsimControl/signal_.h"
25 #include "mbsim/element.h"
26 #include "mbsim/functions/function.h"
27 
28 namespace MBSimControl {
29 
31  template<typename Sig>
33 
35  template<typename Ret, typename Arg>
36  class SignalFunction<Ret(Arg)> : public MBSim::Function<Ret(Arg)> {
37  public:
38  SignalFunction(Signal *ret_=NULL) : ret(ret_) {}
39 
40  void setReturnSignal(Signal *ret_);
41 
42  virtual Ret operator()(const Arg& a) {
43  return MBSim::FromVecV<Ret>::cast(ret->evalSignal());
44  }
45 
46  void init(MBSim::Element::InitStage stage);
47 
48  void initializeUsingXML(xercesc::DOMElement *element);
49 
50  MBSim::Element* getDependency() const { return ret; }
51 
52  protected:
53  std::string retString;
54  Signal *ret;
55  };
56 
57  template<typename Ret, typename Arg>
59  ret=ret_;
60  }
61 
62  template<typename Ret, typename Arg>
63  void SignalFunction<Ret(Arg)>::initializeUsingXML(xercesc::DOMElement *element) {
65  xercesc::DOMElement *e;
66  e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIMCONTROL%"returnSignal");
67  retString=MBXMLUtils::E(e)->getAttribute("ref");
68  }
69 
70  template<typename Ret, typename Arg>
71  void SignalFunction<Ret(Arg)>::init(MBSim::Element::InitStage stage) {
72  if(stage==MBSim::Element::resolveXMLPath) {
73  if(retString!="")
74  setReturnSignal(this->template getByPath<Signal>(retString));
76  }
77  else
79  }
80 
82  template<typename Ret, typename Arg1, typename Arg2>
83  class SignalFunction<Ret(Arg1,Arg2)> : public MBSim::Function<Ret(Arg1,Arg2)> {
84  public:
85  SignalFunction(Signal *ret_=NULL) : ret(ret_) {}
86 
87  void setReturnSignal(Signal *ret_);
88 
89  virtual Ret operator()(const Arg1& a1, const Arg2& a2) {
90  return MBSim::FromVecV<Ret>::cast(ret->evalSignal());
91  }
92 
93  void init(MBSim::Element::InitStage stage);
94 
95  void initializeUsingXML(xercesc::DOMElement *element);
96 
97  MBSim::Element* getDependency() const { return ret; }
98 
99  protected:
100  std::string retString;
101  Signal *ret;
102  };
103 
104  template<typename Ret, typename Arg1, typename Arg2>
106  ret=ret_;
107  }
108 
109  template<typename Ret, typename Arg1, typename Arg2>
110  void SignalFunction<Ret(Arg1, Arg2)>::initializeUsingXML(xercesc::DOMElement *element) {
112  xercesc::DOMElement *e;
113  e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIMCONTROL%"returnSignal");
114  retString=MBXMLUtils::E(e)->getAttribute("ref");
115  }
116 
117  template<typename Ret, typename Arg1, typename Arg2>
118  void SignalFunction<Ret(Arg1, Arg2)>::init(MBSim::Element::InitStage stage) {
119  if(stage==MBSim::Element::resolveXMLPath) {
120  if(retString!="")
121  setReturnSignal(this->template getByPath<Signal>(retString));
123  }
124  else
126  }
127 
128 }
129 
130 #endif
A function which get its return value from a signal.
Definition: signal_function.h:32
Signal.
Definition: signal_.h:37

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML