OperationInterfacePartFused.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 OperationInterfacePartFused.hpp
3 
4  OperationInterfacePartFused.hpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
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_OPERATION_INTERFACE_PART_FUSED_HPP
40 #define ORO_OPERATION_INTERFACE_PART_FUSED_HPP
41 
42 
43 #include <boost/shared_ptr.hpp>
44 #include <boost/function_types/result_type.hpp>
45 #include <boost/function_types/parameter_types.hpp>
46 // Fusion behaviour changed at Boost 1.42
47 #include <boost/version.hpp>
48 #if BOOST_VERSION >= 104100
49 // our code goes up to 7 FUSION_MAX_VECTOR_SIZE defaults to 10
50 #ifndef BOOST_FUSION_UNFUSED_MAX_ARITY
51 #define BOOST_FUSION_UNFUSED_MAX_ARITY 7
52 #endif
53 #include <boost/functional/forward_adapter.hpp>
54 #include <boost/fusion/functional/generation/make_unfused.hpp>
55 #else
56 // our code goes up to 7 FUSION_MAX_VECTOR_SIZE defaults to 10
57 #ifndef BOOST_FUSION_UNFUSED_GENERIC_MAX_ARITY
58 #define BOOST_FUSION_UNFUSED_GENERIC_MAX_ARITY 7
59 #endif
60 #include <boost/fusion/include/make_unfused_generic.hpp>
61 #endif
62 
63 #include <vector>
64 #include <string>
65 
66 #include "DataSource.hpp"
67 #include "CreateSequence.hpp"
69 #include "../OperationInterfacePart.hpp"
70 #include "../FactoryExceptions.hpp"
71 #include "../Operation.hpp"
72 #include "../base/OperationCallerBase.hpp"
73 
79 namespace RTT
80 {
81  namespace internal {
82 
84  public:
85  static std::string description(base::OperationBase* ob);
86  static std::vector<ArgumentDescription> getArgumentList(base::OperationBase* ob, const int arity, std::vector<std::string> const& types);
87  };
88 
93  template<typename Signature>
95  : public OperationInterfacePart
96  {
97  protected:
98  typedef typename boost::function_traits<Signature>::result_type result_type;
104  public:
106  : op(o)
107  {
108  }
109 
110  virtual std::string getName() const {
111  return op->getName();
112  }
113 
114  virtual std::string description() const {
116  }
117 
118  virtual std::vector<ArgumentDescription> getArgumentList() const {
119  std::vector<std::string> types;
120  for (unsigned int i = 1; i <= OperationInterfacePartFused::arity(); ++i )
121  types.push_back( SequenceFactory::GetType(i) );
123  }
124 
125  std::string resultType() const
126  {
128  }
129 
130  unsigned int arity() const { return boost::function_traits<Signature>::arity; }
131 
132  const types::TypeInfo* getArgumentType(unsigned int arg) const
133  {
134  if (arg == 0 )
136  return SequenceFactory::GetTypeInfo(arg);
137  }
138 
139  unsigned int collectArity() const { return boost::function_traits< typename CollectType<Signature>::type >::arity; }
140 
141  const types::TypeInfo* getCollectType(unsigned int arg) const
142  {
143  return CollectSequenceFactory::GetTypeInfo(arg);
144  }
145 
147  const std::vector<base::DataSourceBase::shared_ptr>& args, ExecutionEngine* caller) const
148  {
149  // convert our args and signature into a boost::fusion Sequence.
150  if ( args.size() != OperationInterfacePartFused::arity() )
152  return new FusedMCallDataSource<Signature>(typename base::OperationCallerBase<Signature>::shared_ptr(op->getOperationCaller()->cloneI(caller)), SequenceFactory::sources(args.begin()) );
153  }
154 
155  virtual base::DataSourceBase::shared_ptr produceSend( const std::vector<base::DataSourceBase::shared_ptr>& args, ExecutionEngine* caller ) const {
156  // convert our args and signature into a boost::fusion Sequence.
158  return new FusedMSendDataSource<Signature>(typename base::OperationCallerBase<Signature>::shared_ptr(op->getOperationCaller()->cloneI(caller)), SequenceFactory::sources(args.begin()) );
159  }
160 
162  // Because of copy/clone,program script variables ('var') must begin unbound.
164  }
165 
166  virtual base::DataSourceBase::shared_ptr produceCollect( const std::vector<base::DataSourceBase::shared_ptr>& args, DataSource<bool>::shared_ptr blocking ) const {
167  const unsigned int carity = boost::mpl::size<typename FusedMCollectDataSource<Signature>::handle_and_arg_types>::value;
168  assert( carity == collectArity() + 1 ); // check for arity functions. (this is actually a compile time assert).
169  if ( args.size() != carity ) throw wrong_number_of_args_exception(carity, args.size() );
170  // we need to ask FusedMCollectDataSource what the arg types are, based on the collect signature.
172  }
173 
174 #ifdef ORO_SIGNALLING_OPERATIONS
175  virtual Handle produceSignal( base::ActionInterface* func, const std::vector<base::DataSourceBase::shared_ptr>& args, ExecutionEngine* subscriber) const
176  {
177  throw no_asynchronous_operation_exception("cannot use produceSignal on non-signalling operations");
178  }
179 #endif
180  boost::shared_ptr<base::DisposableInterface> getLocalOperation() const {
181  return op->getImplementation();
182  }
183  };
184 
185 
186 #ifdef ORO_SIGNALLING_OPERATIONS
187 
191  template<typename Signature>
192  class EventOperationInterfacePartFused
193  : public OperationInterfacePartFused<Signature>
194  {
195  typedef typename boost::function_traits<Signature>::result_type result_type;
200 
201  public:
202  EventOperationInterfacePartFused( Operation<Signature>* o)
204  {
205  }
206 
207 
208  virtual Handle produceSignal( base::ActionInterface* func, const std::vector<base::DataSourceBase::shared_ptr>& args, ExecutionEngine* subscriber) const {
209  base::OperationCallerInterface::shared_ptr impl = this->op->getOperationCaller();
210  if ( subscriber == impl->getMessageProcessor() )
211  subscriber = 0; // clear out to avoid dispatching
212  // convert our args and signature into a boost::fusion Sequence.
214  // note: in boost 1.41.0+ the function make_unfused() is available.
215 #if BOOST_VERSION >= 104100
216 #if __cplusplus > 199711L
217  auto invoke_fused = boost::bind(&FusedMSignal<Signature>::invoke,
218  boost::make_shared<FusedMSignal<Signature> >(func, SequenceFactory::assignable(args.begin()), subscriber),
219  _1
220  );
221  typedef typename boost::fusion::result_of::make_unfused< decltype(invoke_fused) >::type unfused_type;
222  return this->op->signals(boost::forward_adapter<unfused_type>(boost::fusion::make_unfused(invoke_fused)));
223 #else // __cplusplus > 199711L
224  return this->op->signals(
225  boost::fusion::make_unfused(boost::bind(&FusedMSignal<Signature>::invoke,
226  boost::make_shared<FusedMSignal<Signature> >(func, SequenceFactory::assignable(args.begin()), subscriber),
227  _1
228  )
229  )
230  );
231 #endif // __cplusplus > 199711L
232 #else // BOOST_VERSION >= 104100
233  return this->op->signals(
234  boost::fusion::make_unfused_generic(boost::bind(&FusedMSignal<Signature>::invoke,
235  boost::make_shared<FusedMSignal<Signature> >(func, SequenceFactory::assignable(args.begin()), subscriber),
236  _1
237  )
238  )
239  );
240 #endif // BOOST_VERSION >= 104100
241  }
242  };
243 #endif // ORO_SIGNALLING_OPERATIONS
244 
250  template<typename Signature>
252  : public OperationInterfacePart
253  {
254  typedef typename boost::function_traits<Signature>::result_type result_type;
260  public:
262  : op(o)
263  {
264  }
265 
266  virtual base::DataSourceBase::shared_ptr produceSend(const std::vector<base::DataSourceBase::shared_ptr>& args, ExecutionEngine* caller) const
267  { throw no_asynchronous_operation_exception("cannot use produceSend on synchronous operations"); }
268  virtual base::DataSourceBase::shared_ptr produceCollect(const std::vector<base::DataSourceBase::shared_ptr>& args, internal::DataSource<bool>::shared_ptr blocking) const
269  { throw no_asynchronous_operation_exception("cannot use produceCollect on synchronous operations"); }
270 #ifdef ORO_SIGNALLING_OPERATIONS
271  virtual Handle produceSignal( base::ActionInterface* func, const std::vector<base::DataSourceBase::shared_ptr>& args, ExecutionEngine* subscriber) const
272  { throw no_asynchronous_operation_exception("cannot use produceSignal on synchronous operations"); }
273 #endif
275  { throw no_asynchronous_operation_exception("cannot use produceHandle on synchronous operations"); }
276 
277  virtual std::string getName() const {
278  return op->getName();
279  }
280  virtual std::string description() const {
282  }
283 
284  virtual std::vector<ArgumentDescription> getArgumentList() const {
285  std::vector<std::string> types;
286  for (unsigned int i = 1; i <= SynchronousOperationInterfacePartFused::arity(); ++i )
287  types.push_back( SequenceFactory::GetType(i) );
289  }
290 
291  std::string resultType() const
292  {
294  }
295 
296  unsigned int arity() const { return boost::function_traits<Signature>::arity; }
297 
298  const types::TypeInfo* getArgumentType(unsigned int arg) const
299  {
300  if (arg == 0 )
302  return SequenceFactory::GetTypeInfo(arg);
303  }
304 
305  unsigned int collectArity() const { return boost::function_traits< typename CollectType<Signature>::type >::arity; }
306 
307  const types::TypeInfo* getCollectType(unsigned int arg) const
308  {
309  return CollectSequenceFactory::GetTypeInfo(arg);
310  }
311 
313  const std::vector<base::DataSourceBase::shared_ptr>& args, ExecutionEngine* caller) const
314  {
315  // convert our args and signature into a boost::fusion Sequence.
316  if ( args.size() != SynchronousOperationInterfacePartFused::arity() )
318  return new FusedMCallDataSource<Signature>(typename base::OperationCallerBase<Signature>::shared_ptr(op->getOperationCaller()->cloneI(caller)), SequenceFactory::sources(args.begin()) );
319  }
320 
321  boost::shared_ptr<base::DisposableInterface> getLocalOperation() const {
322  return op->getImplementation();
323  }
324  };
325 
334  template<typename Signature,typename ObjT>
336  : public OperationInterfacePart
337  {
340  typedef typename boost::function_traits<Signature>::result_type result_type;
342  // the datasource that stores a weak pointer is itself stored by a shared_ptr.
343  typename DataSource<boost::shared_ptr<ObjT> >::shared_ptr mwp;
344  public:
345  OperationInterfacePartFusedDS( DataSource< boost::shared_ptr<ObjT> >* wp, Operation<Signature>* o)
346  : op( o ), mwp(wp)
347  {
348  }
349 
350  typedef std::vector<base::DataSourceBase::shared_ptr> ArgList;
351 
352  std::string resultType() const
353  {
355  }
356 
357  unsigned int arity() const { return boost::function_traits<Signature>::arity - 1;/*lie about the hidden member pointer */ }
358 
359  const types::TypeInfo* getArgumentType(unsigned int arg) const
360  {
361  if (arg == 0 )
363  return SequenceFactory::GetTypeInfo(arg);
364  }
365 
366  unsigned int collectArity() const { return boost::function_traits< typename CollectType<Signature>::type >::arity; }
367 
368  const types::TypeInfo* getCollectType(unsigned int arg) const
369  {
370  return CollectSequenceFactory::GetTypeInfo(arg);
371  }
372 
373  virtual std::string getName() const {
374  return op->getName();
375  }
376 
377  virtual std::string description() const {
378  return op->getDescriptions().front();
379  }
380 
381  virtual std::vector<ArgumentDescription> getArgumentList() const {
382  std::vector<std::string> descr = op->getDescriptions();
383  std::vector<ArgumentDescription> ret;
384  descr.resize( 1 + arity() * 2 );
385  for (unsigned int i =1; i < descr.size(); i +=2 )
386  ret.push_back(ArgumentDescription(descr[i],descr[i+1], SequenceFactory::GetType((i-1)/2+2)) );
387  return ret;
388  }
389 
390  base::DataSourceBase::shared_ptr produce(ArgList const& args, ExecutionEngine* caller) const
391  {
392  if ( args.size() != arity() ) throw wrong_number_of_args_exception(arity(), args.size() );
393  // the user won't give the necessary object argument, so we glue it in front.
394  ArgList a2;
395  a2.reserve(args.size()+1);
396  a2.push_back(mwp);
397  a2.insert(a2.end(), args.begin(), args.end());
398  // convert our args and signature into a boost::fusion Sequence.
399  return new FusedMCallDataSource<Signature>(typename base::OperationCallerBase<Signature>::shared_ptr(op->getOperationCaller()->cloneI(caller)), SequenceFactory::sources(a2.begin()) );
400  }
401 
402  virtual base::DataSourceBase::shared_ptr produceSend( const std::vector<base::DataSourceBase::shared_ptr>& args, ExecutionEngine* caller ) const {
403  if ( args.size() != arity() ) throw wrong_number_of_args_exception(arity(), args.size() );
404  // the user won't give the necessary object argument, so we glue it in front.
405  ArgList a2;
406  a2.reserve(args.size()+1);
407  a2.push_back(mwp);
408  a2.insert(a2.end(), args.begin(), args.end());
409  // convert our args and signature into a boost::fusion Sequence.
410  return new FusedMSendDataSource<Signature>(typename base::OperationCallerBase<Signature>::shared_ptr(op->getOperationCaller()->cloneI(caller)), SequenceFactory::sources(a2.begin()) );
411  }
412 
414  // Because of copy/clone,value objects must begin unbound.
416  }
417 
418  virtual base::DataSourceBase::shared_ptr produceCollect( const std::vector<base::DataSourceBase::shared_ptr>& args, DataSource<bool>::shared_ptr blocking ) const {
419  const unsigned int carity = boost::mpl::size<typename FusedMCollectDataSource<Signature>::handle_and_arg_types>::value;
420  assert( carity == collectArity() + 1 ); // check for arity functions. (this is actually a compile time assert).
421  if ( args.size() != carity ) throw wrong_number_of_args_exception(carity, args.size() );
422  // we need to ask FusedMCollectDataSource what the arg types are, based on the collect signature.
424  }
425 #ifdef ORO_SIGNALLING_OPERATIONS
426  virtual Handle produceSignal( base::ActionInterface* func, const std::vector<base::DataSourceBase::shared_ptr>& args, ExecutionEngine* subscriber) const {
427  if ( args.size() != arity() ) throw wrong_number_of_args_exception(arity(), args.size() );
429  if ( subscriber == impl->getMessageProcessor() )
430  subscriber = 0; // clear out to avoid dispatching
431  // the user won't give the necessary object argument, so we glue it in front.
432  ArgList a2;
433  a2.reserve(args.size()+1);
434  a2.push_back(mwp);
435  a2.insert(a2.end(), args.begin(), args.end());
436  // note: in boost 1.41.0+ the function make_unfused() is available.
437 #if BOOST_VERSION >= 104100
438 #if __cplusplus > 199711L
439  auto invoke_fused = boost::bind(&FusedMSignal<Signature>::invoke,
440  boost::make_shared<FusedMSignal<Signature> >(func, SequenceFactory::assignable(args.begin()), subscriber),
441  _1
442  );
443  typedef typename boost::fusion::result_of::make_unfused< decltype(invoke_fused) >::type unfused_type;
444  return this->op->signals(boost::forward_adapter<unfused_type>(boost::fusion::make_unfused(invoke_fused)));
445 #else // __cplusplus > 199711L
446  return this->op->signals(
447  boost::fusion::make_unfused(boost::bind(&FusedMSignal<Signature>::invoke,
448  boost::make_shared<FusedMSignal<Signature> >(func, SequenceFactory::assignable(args.begin()), subscriber),
449  _1
450  )
451  )
452  );
453 #endif // __cplusplus > 199711L
454 #else // BOOST_VERSION >= 104100
455  return this->op->signals(
456  boost::fusion::make_unfused_generic(boost::bind(&FusedMSignal<Signature>::invoke,
457  boost::make_shared<FusedMSignal<Signature> >(func, SequenceFactory::assignable(args.begin()), subscriber),
458  _1
459  )
460  )
461  );
462 #endif // BOOST_VERSION >= 104100
463  }
464 #endif // ORO_SIGNALLING_OPERATIONS
465 
466  boost::shared_ptr<base::DisposableInterface> getLocalOperation() const {
467  return this->op->getImplementation();
468  }
469  };
470  }
471 }
472 
473 #endif
virtual std::vector< ArgumentDescription > getArgumentList() const
virtual base::OperationCallerBase< Signature >::shared_ptr getOperationCaller()
Definition: Operation.hpp:229
std::vector< base::DataSourceBase::shared_ptr > ArgList
virtual base::DataSourceBase::shared_ptr produceSend(const std::vector< base::DataSourceBase::shared_ptr > &args, ExecutionEngine *caller) const
create_sequence< typename boost::function_types::parameter_types< Signature >::type > SequenceFactory
The factory for converting data sources to C++ types in call()
const types::TypeInfo * getArgumentType(unsigned int arg) const
virtual base::DataSourceBase::shared_ptr produceHandle() const
const types::TypeInfo * getArgumentType(unsigned int arg) const
const types::TypeInfo * getCollectType(unsigned int arg) const
OperationInterfacePartFusedDS(DataSource< boost::shared_ptr< ObjT > > *wp, Operation< Signature > *o)
boost::shared_ptr< OperationCallerInterface > shared_ptr
const types::TypeInfo * getCollectType(unsigned int arg) const
const types::TypeInfo * getArgumentType(unsigned int arg) const
const std::vector< std::string > & getDescriptions()
boost::shared_ptr< OperationCallerBase< F > > shared_ptr
virtual std::vector< ArgumentDescription > getArgumentList() const
virtual base::DataSourceBase::shared_ptr produceHandle() const
Description of one Argument of a Command.
create_sequence< typename boost::function_types::parameter_types< Signature >::type > SequenceFactory
boost::function_traits< Signature >::result_type result_type
Based on the software pattern &#39;command&#39;, this interface allows execution of action objects...
base::DataSourceBase::shared_ptr produce(const std::vector< base::DataSourceBase::shared_ptr > &args, ExecutionEngine *caller) const
boost::function_traits< Signature >::result_type result_type
const types::TypeInfo * getCollectType(unsigned int arg) const
virtual base::DisposableInterface::shared_ptr getImplementation()
Definition: Operation.hpp:226
boost::shared_ptr< base::DisposableInterface > getLocalOperation() const
virtual std::vector< ArgumentDescription > getArgumentList() const
static std::vector< ArgumentDescription > getArgumentList(base::OperationBase *ob, const int arity, std::vector< std::string > const &types)
boost::intrusive_ptr< DataSource< T > > shared_ptr
Definition: DataSource.hpp:115
static std::string description(base::OperationBase *ob)
static const types::TypeInfo * getTypeInfo()
virtual base::DataSourceBase::shared_ptr produceCollect(const std::vector< base::DataSourceBase::shared_ptr > &args, DataSource< bool >::shared_ptr blocking) const
DataSource< boost::shared_ptr< ObjT > >::shared_ptr mwp
virtual base::DataSourceBase::shared_ptr produceHandle() const
base::DataSourceBase::shared_ptr produce(ArgList const &args, ExecutionEngine *caller) const
boost::shared_ptr< base::DisposableInterface > getLocalOperation() const
create_sequence< typename boost::function_types::parameter_types< typename CollectType< Signature >::type >::type > CollectSequenceFactory
The factory for converting data sources to C++ types in collect(). This includes SendHandle.
static const std::string & getQualifier()
create_sequence< typename boost::function_types::parameter_types< Signature >::type > SequenceFactory
The factory for converting data sources to C++ types in call()
base::DataSourceBase::shared_ptr produce(const std::vector< base::DataSourceBase::shared_ptr > &args, ExecutionEngine *caller) const
virtual base::DataSourceBase::shared_ptr produceSend(const std::vector< base::DataSourceBase::shared_ptr > &args, ExecutionEngine *caller) const
virtual base::DataSourceBase::shared_ptr produceCollect(const std::vector< base::DataSourceBase::shared_ptr > &args, DataSource< bool >::shared_ptr blocking) const
static const std::string & getType()
create_sequence< typename boost::function_types::parameter_types< typename CollectType< Signature >::type >::type > CollectSequenceFactory
boost::intrusive_ptr< DataSourceBase > shared_ptr
create_sequence< typename boost::function_types::parameter_types< typename CollectType< Signature >::type >::type > CollectSequenceFactory
The factory for converting data sources to C++ types in collect(). This includes SendHandle.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
virtual base::DataSourceBase::shared_ptr produceCollect(const std::vector< base::DataSourceBase::shared_ptr > &args, internal::DataSource< bool >::shared_ptr blocking) const
boost::shared_ptr< base::DisposableInterface > getLocalOperation() const
const std::string & getName()
The Handle holds the information, and allows manipulation, of a connection between a internal::Signal...
Definition: Handle.hpp:66
boost::function_traits< Signature >::result_type result_type
virtual base::DataSourceBase::shared_ptr produceSend(const std::vector< base::DataSourceBase::shared_ptr > &args, ExecutionEngine *caller) const


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:34