Orocos Real-Time Toolkit  2.8.3
OperatorTypes.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jun 26 13:25:56 CEST 2006 OperatorTypes.hpp
3 
4  OperatorTypes.hpp - description
5  -------------------
6  begin : Mon June 26 2006
7  copyright : (C) 2006 Peter Soetens
8  email : peter.soetens@fmtc.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef ORO_CORELIB_OPERATOP_TYPES_HPP
40 #define ORO_CORELIB_OPERATOP_TYPES_HPP
41 
42 #include "Operators.hpp"
43 #include "../internal/DataSources.hpp"
44 #include <boost/shared_ptr.hpp>
45 
46 namespace RTT
47 {
48  namespace types {
49 
54  template<typename function>
56  : public UnaryOp
57  {
60  const char* mop;
61  function fun;
62  public:
63  UnaryOperator( const char* op, function f )
64  : mop( op ), fun( f )
65  {
66  }
68  {
69  if ( op != mop ) return 0;
72  boost::dynamic_pointer_cast< internal::DataSource<arg_t> >( dsb ); // do not call convert(a) here ! Would always succeed.
73  if ( ! arg ) return 0;
74  return new internal::UnaryDataSource<function>( arg, fun );
75  }
76  };
77 
78 
83  template<typename function>
85  : public BinaryOp
86  {
90  const char* mop;
91  function fun;
92  public:
93  BinaryOperator( const char* op, function f )
94  : mop( op ), fun( f )
95  {
96  }
99  {
100  // operation (+,-,...) and first argument type must match.
101  if ( op != mop || a->getTypeInfo() != internal::DataSourceTypeInfo<arg1_t>::getTypeInfo() ) return 0;
102  // Logger::log() << Logger::Debug << "BinaryOperator: "<< op << Logger::nl;
105  boost::dynamic_pointer_cast< internal::DataSource<arg1_t> >( dsb ); // first argument must be exact match.
108  // Logger::log() << "arg1 : "<< arg1 <<" second arg: "<<arg2<<"..." << Logger::endl;
109  // Logger::log() << "arg1 was: "<< typeid(arg1).name() <<" a was: "<<typeid(a).name()<<"..." << Logger::endl;
110  if ( !arg1 || ! arg2 ) return 0;
111  // Logger::log() << "success !"<< Logger::endl;
112  return new internal::BinaryDataSource<function>( arg1, arg2, fun );
113  }
114 
115  bool isExactMatch(const std::string& op, base::DataSourceBase* a,
116  base::DataSourceBase* b ) {
117  return op == mop
120  }
121  };
122 
126  template<typename function>
128  newUnaryOperator( const char* op, function f )
129  {
130  return new UnaryOperator<function>( op, f );
131  }
132 
136  template<typename function>
138  newBinaryOperator( const char* op, function f )
139  {
140  return new BinaryOperator<function>( op, f );
141  }
142 
143 }}
144 #endif
DataSource is a base class representing a generic way to read data of type T.
Definition: DataSource.hpp:94
A DataSource which returns the return value of a unary function.
UnaryOperator contains information on some unary operator that operates on one arg of a certain type...
Definition: Operators.hpp:65
base::DataSourceBase::shared_ptr convert(base::DataSourceBase::shared_ptr arg) const
Automatic conversion: convert a internal::DataSource to this type.
Definition: TypeInfo.cpp:118
internal::DataSource< result_t > * build(const std::string &op, base::DataSourceBase *a, base::DataSourceBase *b)
If op is the operator you are responsible for, and if the argument internal::DataSource&#39;s are of the ...
UnaryOperator(const char *op, function f)
The base class for all internal data representations.
virtual const types::TypeInfo * getTypeInfo() const =0
Return the Orocos type info object.
BinaryOperator(const char *op, function f)
An operator which reads a single internal::DataSource and returns a modified result.
bool isExactMatch(const std::string &op, base::DataSourceBase *a, base::DataSourceBase *b)
Returns true if this binary operator matches op, and a and b are the exact types this operator expect...
A generic binary composite DataSource.
BinaryOperator< function > * newBinaryOperator(const char *op, function f)
helper function to create a new BinaryOperator
static const types::TypeInfo * getTypeInfo()
Return the typeinfo object.
UnaryOperator< function > * newUnaryOperator(const char *op, function f)
helper function to create a new UnaryOperator
boost::intrusive_ptr< DataSource< T > > shared_ptr
Definition: DataSource.hpp:115
internal::DataSource< result_t > * build(const std::string &op, base::DataSourceBase *a)
If op is the operator you are responsible for, and if the argument internal::DataSource is of the cor...
An operator which reads a two DataSources and returns a modified result.
boost::remove_const< typename boost::remove_reference< T >::type >::type type
Definition: mystd.hpp:63
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
This file contains operator information objects, These objects contain information on how to apply on...