sot-core  4.11.6
Hierarchical task solver plug-in for dynamic-graph.
binary-op.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 #ifndef SOT_CORE_BINARYOP_HH
11 #define SOT_CORE_BINARYOP_HH
12 
13 /* --------------------------------------------------------------------- */
14 /* --- INCLUDE --------------------------------------------------------- */
15 /* --------------------------------------------------------------------- */
16 
17 /* Matrix */
18 #include <dynamic-graph/linear-algebra.h>
19 
20 /* SOT */
21 #include <dynamic-graph/all-signals.h>
22 #include <dynamic-graph/entity.h>
23 #include <sot/core/flags.hh>
25 #include <sot/core/pool.hh>
26 
27 /* STD */
28 #include <string>
29 
30 #include <boost/function.hpp>
31 
32 namespace dynamicgraph {
33 namespace sot {
34 
35 /* --------------------------------------------------------------------- */
36 /* --- CLASS ----------------------------------------------------------- */
37 /* --------------------------------------------------------------------- */
38 
39 template <typename Operator> class BinaryOp : public Entity {
40  Operator op;
41  typedef typename Operator::Tin1 Tin1;
42  typedef typename Operator::Tin2 Tin2;
43  typedef typename Operator::Tout Tout;
44  typedef BinaryOp<Operator> Self;
45 
46 public: /* --- CONSTRUCTION --- */
47  static std::string getTypeIn1Name(void) { return Operator::nameTypeIn1(); }
48  static std::string getTypeIn2Name(void) { return Operator::nameTypeIn2(); }
49  static std::string getTypeOutName(void) { return Operator::nameTypeOut(); }
50  static const std::string CLASS_NAME;
51  virtual const std::string &getClassName() const { return CLASS_NAME; }
52  std::string getDocString() const { return op.getDocString(); }
53 
54  BinaryOp(const std::string &name)
55  : Entity(name),
56  SIN1(NULL, BinaryOp::CLASS_NAME + "(" + name + ")::input(" +
57  getTypeIn1Name() + ")::sin1"),
58  SIN2(NULL, CLASS_NAME + "(" + name + ")::input(" + getTypeIn2Name() +
59  ")::sin2"),
60  SOUT(boost::bind(&Self::computeOperation, this, _1, _2), SIN1 << SIN2,
61  CLASS_NAME + "(" + name + ")::output(" + getTypeOutName() +
62  ")::sout") {
63  signalRegistration(SIN1 << SIN2 << SOUT);
64  op.addSpecificCommands(*this, commandMap);
65  }
66 
67  virtual ~BinaryOp(void){};
68 
69 public: /* --- SIGNAL --- */
70  SignalPtr<Tin1, int> SIN1;
71  SignalPtr<Tin2, int> SIN2;
72  SignalTimeDependent<Tout, int> SOUT;
73 
74 protected:
75  Tout &computeOperation(Tout &res, int time) {
76  const Tin1 &x1 = SIN1(time);
77  const Tin2 &x2 = SIN2(time);
78  op(x1, x2, res);
79  return res;
80  }
81 };
82 } // namespace sot
83 } // namespace dynamicgraph
84 
85 #endif // #ifndef SOT_CORE_BINARYOP_HH
dynamicgraph::sot::BinaryOp::BinaryOp
BinaryOp(const std::string &name)
Definition: binary-op.hh:54
dynamicgraph
Definition: abstract-sot-external-interface.hh:17
dynamicgraph::sot::BinaryOp::SIN2
SignalPtr< Tin2, int > SIN2
Definition: binary-op.hh:71
dynamicgraph::sot::BinaryOp::getTypeIn1Name
static std::string getTypeIn1Name(void)
Definition: binary-op.hh:47
dynamicgraph::sot::BinaryOp::getDocString
std::string getDocString() const
Definition: binary-op.hh:52
dynamicgraph::sot::BinaryOp
Definition: binary-op.hh:39
dynamicgraph::sot::BinaryOp::~BinaryOp
virtual ~BinaryOp(void)
Definition: binary-op.hh:67
flags.hh
pool.hh
dynamicgraph::sot::BinaryOp::getTypeOutName
static std::string getTypeOutName(void)
Definition: binary-op.hh:49
matrix-geometry.hh
dynamicgraph::sot::BinaryOp::getClassName
virtual const std::string & getClassName() const
Definition: binary-op.hh:51
dynamicgraph::sot::BinaryOp::CLASS_NAME
static const std::string CLASS_NAME
Definition: binary-op.hh:50
dynamicgraph::sot::BinaryOp::getTypeIn2Name
static std::string getTypeIn2Name(void)
Definition: binary-op.hh:48
dynamicgraph::sot::BinaryOp::SOUT
SignalTimeDependent< Tout, int > SOUT
Definition: binary-op.hh:72
dynamicgraph::sot::BinaryOp::SIN1
SignalPtr< Tin1, int > SIN1
Definition: binary-op.hh:67
dynamicgraph::sot::BinaryOp::computeOperation
Tout & computeOperation(Tout &res, int time)
Definition: binary-op.hh:75