|
mbsimcontrol
4.0.0
|
00001 /* Copyright (C) MBSim Development Team 00002 * 00003 * This library is free software; you can redistribute it and/or 00004 * modify it under the terms of the GNU Lesser General Public 00005 * License as published by the Free Software Foundation; either 00006 * version 2.1 of the License, or (at your option) any later version. 00007 * 00008 * This library is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Lesser General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public 00014 * License along with this library; if not, write to the Free Software 00015 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00016 * 00017 * Contact: markus.ms.schneider@gmail.com 00018 */ 00019 00020 #ifndef _SIGNAL_FUNCTION_H_ 00021 #define _SIGNAL_FUNCTION_H_ 00022 00023 #include "mbsim/functions/function.h" 00024 #include "mbsimControl/signal_.h" 00025 #include "mbsim/element.h" 00026 #include "mbsim/functions/function.h" 00027 00028 namespace MBSimControl { 00029 00031 template<typename Sig> 00032 class SignalFunction; 00033 00035 template<typename Ret, typename Arg1, typename Arg2> 00036 class SignalFunction<Ret(Arg1,Arg2)> : public MBSim::Function<Ret(Arg1,Arg2)> { 00037 public: 00038 SignalFunction() : ret(NULL) {} 00039 00040 void setReturnSignal(Signal *ret_); 00041 00042 virtual Ret operator()(const Arg1& a1, const Arg2& a2) { 00043 return ret->getSignal()(0); 00044 } 00045 00046 void init(MBSim::Element::InitStage stage); 00047 00048 void initializeUsingXML(xercesc::DOMElement *element); 00049 00050 protected: 00051 std::string retString; 00052 Signal *ret; 00053 }; 00054 00055 template<typename Ret, typename Arg1, typename Arg2> 00056 void SignalFunction<Ret(Arg1, Arg2)>::setReturnSignal(Signal *ret_) { 00057 ret=ret_; 00058 } 00059 00060 template<typename Ret, typename Arg1, typename Arg2> 00061 void SignalFunction<Ret(Arg1, Arg2)>::initializeUsingXML(xercesc::DOMElement *element) { 00062 MBSim::Function<Ret(Arg1,Arg2)>::initializeUsingXML(element); 00063 xercesc::DOMElement *e; 00064 e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIMCONTROL%"returnSignal"); 00065 retString=MBXMLUtils::E(e)->getAttribute("ref"); 00066 } 00067 00068 template<typename Ret, typename Arg1, typename Arg2> 00069 void SignalFunction<Ret(Arg1, Arg2)>::init(MBSim::Element::InitStage stage) { 00070 if(stage==MBSim::Element::resolveXMLPath) { 00071 if(retString!="") 00072 setReturnSignal(this->template getByPath<Signal>(retString)); 00073 MBSim::Function<Ret(Arg1,Arg2)>::init(stage); 00074 } 00075 } 00076 00077 } 00078 00079 #endif
1.8.0