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 #include "mbsim/utils/utils.h"
28 
29 namespace MBSimControl {
30 
32  template<typename Sig>
34 
36  template<typename Ret, typename Arg>
37  class SignalFunction<Ret(Arg)> : public MBSim::Function<Ret(Arg)> {
38  public:
39  SignalFunction(Signal *ret_=nullptr) : ret(ret_) {}
40 
41  void setReturnSignal(Signal *ret_);
42 
43  std::pair<int, int> getRetSize() const override { return std::make_pair(ret->getSignalSize(),1); }
44 
45  Ret operator()(const Arg& a) override {
46  return MBSim::FromVecV<Ret>::cast(ret->evalSignal());
47  }
48 
49  void init(MBSim::Element::InitStage stage, const MBSim::InitConfigSet &config) override;
50 
51  void initializeUsingXML(xercesc::DOMElement *element) override;
52 
53  MBSim::Element* getDependency() const override { return ret; }
54 
55  protected:
56  std::string retString;
57  Signal *ret;
58  };
59 
60  template<typename Ret, typename Arg>
62  ret=ret_;
63  }
64 
65  template<typename Ret, typename Arg>
66  void SignalFunction<Ret(Arg)>::initializeUsingXML(xercesc::DOMElement *element) {
68  xercesc::DOMElement *e;
69  e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIMCONTROL%"returnSignal");
70  retString=MBXMLUtils::E(e)->getAttribute("ref");
71  }
72 
73  template<typename Ret, typename Arg>
74  void SignalFunction<Ret(Arg)>::init(MBSim::Element::InitStage stage, const MBSim::InitConfigSet &config) {
75  if(stage==MBSim::Element::resolveStringRef) {
76  if(not retString.empty())
77  setReturnSignal(this->template getByPath<Signal>(retString));
78  MBSim::Function<Ret(Arg)>::init(stage, config);
79  }
80  else
81  MBSim::Function<Ret(Arg)>::init(stage, config);
82  }
83 
85  template<typename Ret, typename Arg1, typename Arg2>
86  class SignalFunction<Ret(Arg1,Arg2)> : public MBSim::Function<Ret(Arg1,Arg2)> {
87  public:
88  SignalFunction(Signal *ret_=nullptr) : ret(ret_) {}
89 
90  void setReturnSignal(Signal *ret_);
91 
92  std::pair<int, int> getRetSize() const override { return std::make_pair(ret->getSignalSize(),1); }
93 
94  Ret operator()(const Arg1& a1, const Arg2& a2) override {
95  return MBSim::FromVecV<Ret>::cast(ret->evalSignal());
96  }
97 
98  void init(MBSim::Element::InitStage stage, const MBSim::InitConfigSet &config) override;
99 
100  void initializeUsingXML(xercesc::DOMElement *element) override;
101 
102  MBSim::Element* getDependency() const override { return ret; }
103 
104  protected:
105  std::string retString;
106  Signal *ret;
107  };
108 
109  template<typename Ret, typename Arg1, typename Arg2>
111  ret=ret_;
112  }
113 
114  template<typename Ret, typename Arg1, typename Arg2>
115  void SignalFunction<Ret(Arg1, Arg2)>::initializeUsingXML(xercesc::DOMElement *element) {
117  xercesc::DOMElement *e;
118  e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIMCONTROL%"returnSignal");
119  retString=MBXMLUtils::E(e)->getAttribute("ref");
120  }
121 
122  template<typename Ret, typename Arg1, typename Arg2>
123  void SignalFunction<Ret(Arg1, Arg2)>::init(MBSim::Element::InitStage stage, const MBSim::InitConfigSet &config) {
124  if(stage==MBSim::Element::resolveStringRef) {
125  if(not retString.empty())
126  setReturnSignal(this->template getByPath<Signal>(retString));
128  }
129  else
131  }
132 
133 }
134 
135 #endif
A function which get its return value from a signal.
Definition: signal_function.h:33
Signal.
Definition: signal_.h:38

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Home