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->getSignal());
44  }
45 
46  void init(MBSim::Element::InitStage stage);
47 
48  void initializeUsingXML(xercesc::DOMElement *element);
49 
50  protected:
51  std::string retString;
52  Signal *ret;
53  };
54 
55  template<typename Ret, typename Arg>
57  ret=ret_;
58  }
59 
60  template<typename Ret, typename Arg>
61  void SignalFunction<Ret(Arg)>::initializeUsingXML(xercesc::DOMElement *element) {
62  MBSim::Function<Ret(Arg)>::initializeUsingXML(element);
63  xercesc::DOMElement *e;
64  e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIMCONTROL%"returnSignal");
65  retString=MBXMLUtils::E(e)->getAttribute("ref");
66  }
67 
68  template<typename Ret, typename Arg>
69  void SignalFunction<Ret(Arg)>::init(MBSim::Element::InitStage stage) {
70  if(stage==MBSim::Element::resolveXMLPath) {
71  if(retString!="")
72  setReturnSignal(this->template getByPath<Signal>(retString));
73  MBSim::Function<Ret(Arg)>::init(stage);
74  }
75  else
76  MBSim::Function<Ret(Arg)>::init(stage);
77  }
78 
80  template<typename Ret, typename Arg1, typename Arg2>
81  class SignalFunction<Ret(Arg1,Arg2)> : public MBSim::Function<Ret(Arg1,Arg2)> {
82  public:
83  SignalFunction(Signal *ret_=NULL) : ret(ret_) {}
84 
85  void setReturnSignal(Signal *ret_);
86 
87  virtual Ret operator()(const Arg1& a1, const Arg2& a2) {
88  return MBSim::FromVecV<Ret>::cast(ret->getSignal());
89  }
90 
91  void init(MBSim::Element::InitStage stage);
92 
93  void initializeUsingXML(xercesc::DOMElement *element);
94 
95  protected:
96  std::string retString;
97  Signal *ret;
98  };
99 
100  template<typename Ret, typename Arg1, typename Arg2>
102  ret=ret_;
103  }
104 
105  template<typename Ret, typename Arg1, typename Arg2>
106  void SignalFunction<Ret(Arg1, Arg2)>::initializeUsingXML(xercesc::DOMElement *element) {
107  MBSim::Function<Ret(Arg1,Arg2)>::initializeUsingXML(element);
108  xercesc::DOMElement *e;
109  e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIMCONTROL%"returnSignal");
110  retString=MBXMLUtils::E(e)->getAttribute("ref");
111  }
112 
113  template<typename Ret, typename Arg1, typename Arg2>
114  void SignalFunction<Ret(Arg1, Arg2)>::init(MBSim::Element::InitStage stage) {
115  if(stage==MBSim::Element::resolveXMLPath) {
116  if(retString!="")
117  setReturnSignal(this->template getByPath<Signal>(retString));
118  MBSim::Function<Ret(Arg1,Arg2)>::init(stage);
119  }
120  else
121  MBSim::Function<Ret(Arg1,Arg2)>::init(stage);
122  }
123 
124 }
125 
126 #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