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
internal::remove_cr< typename function::second_argument_type >::type arg2_t
base::DataSourceBase::shared_ptr convert(base::DataSourceBase::shared_ptr arg) const
Definition: TypeInfo.cpp:118
internal::DataSource< result_t > * build(const std::string &op, base::DataSourceBase *a, base::DataSourceBase *b)
UnaryOperator(const char *op, function f)
The base class for all internal data representations.
virtual const types::TypeInfo * getTypeInfo() const =0
BinaryOperator(const char *op, function f)
internal::remove_cr< typename function::first_argument_type >::type arg1_t
bool isExactMatch(const std::string &op, base::DataSourceBase *a, base::DataSourceBase *b)
BinaryOperator< function > * newBinaryOperator(const char *op, function f)
internal::remove_cr< typename function::result_type >::type result_t
UnaryOperator< function > * newUnaryOperator(const char *op, function f)
boost::intrusive_ptr< DataSource< T > > shared_ptr
Definition: DataSource.hpp:115
internal::DataSource< result_t > * build(const std::string &op, base::DataSourceBase *a)
internal::remove_cr< typename function::argument_type >::type arg_t
static const types::TypeInfo * getTypeInfo()
boost::remove_const< typename boost::remove_reference< T >::type >::type type
Definition: mystd.hpp:63
boost::intrusive_ptr< DataSourceBase > shared_ptr
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
internal::remove_cr< typename function::result_type >::type result_t


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:26