All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
continued_function.h
1 /* Copyright (C) 2004-2016 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: martin.o.foerg@gmail.com
18  */
19 
20 #ifndef _CONTINUED_FUNCTION_H_
21 #define _CONTINUED_FUNCTION_H_
22 
23 #include "mbsim/functions/function.h"
24 
25 namespace MBSim {
26 
27  template<typename Sig> class ContinuedFunction;
28 
29  template<typename Ret, typename Arg>
30  class ContinuedFunction<Ret(Arg)> : public Function<Ret(Arg)> {
32  public:
33  ContinuedFunction() : f(NULL), rule(NULL) { }
34  ~ContinuedFunction() { delete f; delete rule; }
35  int getArgSize() const { return f->getArgSize(); }
36  Ret operator()(const Arg &x) { return (*f)((*rule)(x)); }
37  typename B::DRetDArg parDer(const Arg &x) { return f->parDer((*rule)(x)); }
38  typename B::DRetDArg parDerDirDer(const Arg &xDir, const Arg &x) { return f->parDerDirDer(xDir,(*rule)(x)); }
39  typename B::DDRetDDArg parDerParDer(const Arg &x) { return f->parDerParDer((*rule)(x)); }
40  void setFunction(Function<Ret(Arg)> *f_) {
41  f = f_;
42  f->setParent(this);
43  f->setName("Function");
44  }
45  void setContinuationRule(Function<Arg(Arg)> *rule_) {
46  rule = rule_;
47  rule->setParent(this);
48  rule->setName("ContinuationRule");
49  }
50  void initializeUsingXML(xercesc::DOMElement *element) {
51  xercesc::DOMElement *e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"function");
52  setFunction(ObjectFactory::createAndInit<Function<Ret(Arg)> >(e->getFirstElementChild()));
53  e=MBXMLUtils::E(element)->getFirstElementChildNamed(MBSIM%"continuationRule");
54  setContinuationRule(ObjectFactory::createAndInit<Function<Arg(Arg)> >(e->getFirstElementChild()));
55  }
56  void init(Element::InitStage stage) {
57  if(stage == Element::unknownStage) {
59 // Ret y0 = f(FromDouble<Arg>::cast(0));
60 // Ret y1 = f(FromDouble<Arg>::cast(T));
61  }
62  else
64  f->init(stage);
65  rule->init(stage);
66  }
67  private:
69  Function<Arg(Arg)> *rule;
70  };
71 
72 }
73 
74 #endif
Definition: continued_function.h:27
void init(Element::InitStage stage)
plots time series header
Definition: continued_function.h:56
InitStage
The stages of the initialization.
Definition: element.h:97
Definition: planar_contour.h:31
virtual void init(InitStage stage)
plots time series header
Definition: element.cc:70
Definition: element.h:104
static ContainerType * createAndInit(const xercesc::DOMElement *element)
Definition: objectfactory.h:87

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML