DataSourceStorage.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: FMTC do nov 2 13:06:13 CET 2006 DataSourceStorage.hpp
3 
4  DataSourceStorage.hpp - description
5  -------------------
6  begin : do november 02 2006
7  copyright : (C) 2006 FMTC
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_TASK_DATASOURCE_STORAGE_HPP
40 #define ORO_TASK_DATASOURCE_STORAGE_HPP
41 
42 #include <boost/function.hpp>
43 #include <boost/bind.hpp>
44 #include <boost/mem_fn.hpp>
45 #include <boost/function_types/function_type.hpp>
46 #include <boost/function_types/function_arity.hpp>
47 #include "DataSources.hpp"
48 #include "BindStorage.hpp"
49 
50 namespace RTT
51 {
52  namespace internal
53  {
60  template<class T>
61  struct DSRStore {
62  T arg;
63  DSRStore() : arg() {}
64 
65  T& result() { return arg; }
66  operator T&() { return arg; }
67  };
68 
69  template<class T>
70  struct DSRStore<T&>
71  {
72  typedef typename boost::remove_const<T>::type result_type;
73  result_type arg;
74  DSRStore() : arg() {}
75  result_type& result() { return arg; } // non const return
76  operator result_type&() { return arg; }
77  };
78 
79  template<>
80  struct DSRStore<void> {
81  DSRStore() {}
82  void result() { return; }
83  };
84 
85  template<>
86  struct is_arg_return<DSRStore<void> > : public mpl::false_
87  {};
88 
89  template<class T>
90  struct is_arg_return<DSRStore<T> > : public mpl::true_
91  {};
92 
93 
96  template<class R>
98  {
99  typedef typename remove_cr<R>::type ds_type;
102 
104  : result( new ReferenceDataSource<ds_type>(retn.result()) )
105  {
106  }
107 
108  template<class ContainerT>
109  void initRet(ContainerT& cc) {
110  cc.ret(base::DataSourceBase::shared_ptr(result));
111  }
112 
113  R getResult() {
114  return retn.result();
115  }
116  };
117 
118  template<>
120  {
121  typedef void result_type;
124  {
125  }
126 
127  template<class ContainerT>
128  void initRet(ContainerT& ) {}
129 
130  void getResult() {}
131  };
132 
135  template<class R>
136  struct DataSourceResultStorage<R const&>
137  {
138  typedef R const& result_type;
139  typedef R ds_type;
142 
144  : result( new ReferenceDataSource<ds_type>( retn.result() ) )
145  {
146  }
147 
148  template<class ContainerT>
149  void initRet(ContainerT& cc) {
150  cc.ret(base::DataSourceBase::shared_ptr(result));
151  }
152 
153  result_type getResult() {
154  return result->rvalue();
155  }
156  };
157 
164  template<class A>
166  {
167  typedef typename remove_cr<A>::type ds_type;
168  typedef AStore<A&> Store;
172  : value( new ValueDataSource<ds_type>() )
173  {}
174  // We store the copy of 'a' in the data source, such that
175  // that copy is always valid memory (refcounted). If we
176  // would store it in 'arg' and use a LateReferenceDataSource,
177  // we would loose/corrupt the data if this object is destroyed.
178  // This is acceptable for ref/constref cases, but not for
179  // value cases, which are often living on the stack and by
180  // definition short lived.
181  void newarg(A a) { arg( value->set() ); value->set(a); }
182  };
183 
185  template<class A>
187  {
188  typedef AStore<A&> Store;
190  typedef typename remove_cr<A>::type ds_type;
193  : value( new LateReferenceDataSource<ds_type>() )
194  {}
195  void newarg(A& a) { arg(a); value->setPointer(&arg.get()); }
196  };
197 
199  template<class A>
200  struct DataSourceArgStorage<A const&>
201  {
204  // without const&:
207  : value( new LateConstReferenceDataSource<A>() )
208  {}
209  void newarg(A const& a) { arg(a); value->setPointer(&arg.get());}
210  };
211 
212  template<int, class T>
214 
218  template<class DataType>
219  struct DataSourceStorageImpl<0, DataType>
220  : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
221  {
222  typedef typename boost::function_traits<DataType>::result_type result_type;
225  template<class ContainerT>
226  void initArgs(ContainerT& ) {}
227  };
228 
232  template<class DataType>
233  struct DataSourceStorageImpl<1, DataType>
234  : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
235  {
236  typedef typename boost::function_traits<DataType>::result_type result_type;
237  typedef typename boost::function_traits<DataType>::arg1_type arg1_type;
240 
243 
244  template<class ContainerT>
245  void initArgs(ContainerT& cc) {
246  cc.arg( base::DataSourceBase::shared_ptr(ma1.value.get()) );
247  }
248 
249  void store(arg1_type a1) {
250  ma1.newarg(a1);
251  }
252  };
253 
254  template<class DataType>
255  struct DataSourceStorageImpl<2, DataType>
256  : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
257  {
258  typedef typename boost::function_traits<DataType>::result_type result_type;
259  typedef typename boost::function_traits<DataType>::arg1_type arg1_type;
260  typedef typename boost::function_traits<DataType>::arg2_type arg2_type;
265 
268 
269  template<class ContainerT>
270  void initArgs(ContainerT& cc) {
273  }
274  void store(arg1_type a1, arg2_type a2) {
275  ma1.newarg(a1);
276  ma2.newarg(a2);
277  }
278  };
279 
280  template<class DataType>
281  struct DataSourceStorageImpl<3, DataType>
282  : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
283  {
284  typedef typename boost::function_traits<DataType>::result_type result_type;
285  typedef typename boost::function_traits<DataType>::arg1_type arg1_type;
286  typedef typename boost::function_traits<DataType>::arg2_type arg2_type;
287  typedef typename boost::function_traits<DataType>::arg3_type arg3_type;
294 
297 
298  template<class ContainerT>
299  void initArgs(ContainerT& cc) {
303  }
304  void store(arg1_type a1, arg2_type a2, arg3_type a3) {
305  ma1.newarg(a1);
306  ma2.newarg(a2);
307  ma3.newarg(a3);
308  }
309  };
310 
311  template<class DataType>
312  struct DataSourceStorageImpl<4, DataType>
313  : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
314  {
315  typedef typename boost::function_traits<DataType>::result_type result_type;
316  typedef typename boost::function_traits<DataType>::arg1_type arg1_type;
317  typedef typename boost::function_traits<DataType>::arg2_type arg2_type;
318  typedef typename boost::function_traits<DataType>::arg3_type arg3_type;
319  typedef typename boost::function_traits<DataType>::arg4_type arg4_type;
328 
331 
332  template<class ContainerT>
333  void initArgs(ContainerT& cc) {
338  }
339  void store(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4) {
340  ma1.newarg(a1);
341  ma2.newarg(a2);
342  ma3.newarg(a3);
343  ma4.newarg(a4);
344  }
345  };
346 
347  template<class DataType>
348  struct DataSourceStorageImpl<5, DataType>
349  : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
350  {
351  typedef typename boost::function_traits<DataType>::result_type result_type;
352  typedef typename boost::function_traits<DataType>::arg1_type arg1_type;
353  typedef typename boost::function_traits<DataType>::arg2_type arg2_type;
354  typedef typename boost::function_traits<DataType>::arg3_type arg3_type;
355  typedef typename boost::function_traits<DataType>::arg4_type arg4_type;
356  typedef typename boost::function_traits<DataType>::arg5_type arg5_type;
367 
370 
371  template<class ContainerT>
372  void initArgs(ContainerT& cc) {
378  }
379  void store(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5) {
380  ma1.newarg(a1);
381  ma2.newarg(a2);
382  ma3.newarg(a3);
383  ma4.newarg(a4);
384  ma5.newarg(a5);
385  }
386  };
387 
388  template<class DataType>
389  struct DataSourceStorageImpl<6, DataType>
390  : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
391  {
392  typedef typename boost::function_traits<DataType>::result_type result_type;
393  typedef typename boost::function_traits<DataType>::arg1_type arg1_type;
394  typedef typename boost::function_traits<DataType>::arg2_type arg2_type;
395  typedef typename boost::function_traits<DataType>::arg3_type arg3_type;
396  typedef typename boost::function_traits<DataType>::arg4_type arg4_type;
397  typedef typename boost::function_traits<DataType>::arg5_type arg5_type;
398  typedef typename boost::function_traits<DataType>::arg6_type arg6_type;
411 
414 
415  template<class ContainerT>
416  void initArgs(ContainerT& cc) {
423  }
424  void store(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5, arg6_type a6) {
425  ma1.newarg(a1);
426  ma2.newarg(a2);
427  ma3.newarg(a3);
428  ma4.newarg(a4);
429  ma5.newarg(a5);
430  ma6.newarg(a6);
431  }
432  };
433 
434  template<class DataType>
435  struct DataSourceStorageImpl<7, DataType>
436  : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
437  {
438  typedef typename boost::function_traits<DataType>::result_type result_type;
439  typedef typename boost::function_traits<DataType>::arg1_type arg1_type;
440  typedef typename boost::function_traits<DataType>::arg2_type arg2_type;
441  typedef typename boost::function_traits<DataType>::arg3_type arg3_type;
442  typedef typename boost::function_traits<DataType>::arg4_type arg4_type;
443  typedef typename boost::function_traits<DataType>::arg5_type arg5_type;
444  typedef typename boost::function_traits<DataType>::arg6_type arg6_type;
445  typedef typename boost::function_traits<DataType>::arg7_type arg7_type;
460 
463 
464  template<class ContainerT>
465  void initArgs(ContainerT& cc) {
473  }
474  void store(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5, arg6_type a6, arg7_type a7) {
475  ma1.newarg(a1);
476  ma2.newarg(a2);
477  ma3.newarg(a3);
478  ma4.newarg(a4);
479  ma5.newarg(a5);
480  ma6.newarg(a6);
481  ma7.newarg(a7);
482  }
483  };
484 
491  template<class DataType>
493  : public DataSourceStorageImpl<boost::function_traits<DataType>::arity, DataType>
494  {
495  };
496  }
497 }
498 #endif
void setPointer(typename AssignableDataSource< T >::value_t *ptr)
ReferenceDataSource< ds_type >::shared_ptr result
boost::function_traits< DataType >::result_type result_type
boost::function_traits< DataType >::arg5_type arg5_type
DataSourceArgStorage< arg3_type >::Store AStore3
DataSourceArgStorage< arg6_type >::Store AStore6
boost::function_traits< DataType >::arg7_type arg7_type
DataSourceArgStorage< arg1_type >::Store AStore1
boost::function_traits< DataType >::arg3_type arg3_type
boost::function_traits< DataType >::arg2_type arg2_type
DataSourceArgStorage< arg3_type >::Store AStore3
DataSourceArgStorage< arg3_type >::Store AStore3
DataSourceArgStorage< arg2_type >::Store AStore2
boost::function_traits< DataType >::arg3_type arg3_type
DataSourceStorageImpl(const DataSourceStorageImpl &orig)
boost::remove_const< T >::type result_type
boost::function_traits< DataType >::arg1_type arg1_type
LateConstReferenceDataSource< A >::shared_ptr value
DataSourceArgStorage< arg4_type >::Store AStore4
DataSourceArgStorage< arg7_type >::Store AStore7
DataSourceArgStorage< arg6_type >::Store AStore6
void store(arg1_type a1, arg2_type a2, arg3_type a3)
boost::function_traits< DataType >::arg4_type arg4_type
boost::function_traits< DataType >::arg4_type arg4_type
void set(typename AssignableDataSource< T >::param_t t)
boost::function_traits< DataType >::arg2_type arg2_type
DataSourceStorageImpl(const DataSourceStorageImpl &orig)
boost::function_traits< DataType >::result_type result_type
void store(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5, arg6_type a6)
LateReferenceDataSource< ds_type >::shared_ptr value
DataSourceArgStorage< arg2_type >::Store AStore2
boost::function_traits< DataType >::arg1_type arg1_type
DataSourceArgStorage< arg3_type >::Store AStore3
DataSourceArgStorage< arg2_type >::Store AStore2
boost::function_traits< DataType >::arg1_type arg1_type
DataSourceArgStorage< arg1_type >::Store AStore1
boost::function_traits< DataType >::result_type result_type
boost::function_traits< DataType >::arg4_type arg4_type
boost::function_traits< DataType >::arg1_type arg1_type
DataSourceArgStorage< arg1_type >::Store AStore1
boost::function_traits< DataType >::result_type result_type
boost::function_traits< DataType >::arg1_type arg1_type
AssignableDataSource< T >::const_reference_t rvalue() const
void store(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5, arg6_type a6, arg7_type a7)
DataSourceArgStorage< arg1_type >::Store AStore1
DataSourceArgStorage< arg1_type >::Store AStore1
boost::function_traits< DataType >::arg6_type arg6_type
DataSourceArgStorage< arg2_type >::Store AStore2
boost::function_traits< DataType >::result_type result_type
DataSourceArgStorage< arg4_type >::Store AStore4
boost::function_traits< DataType >::arg2_type arg2_type
DataSourceArgStorage< arg1_type >::Store AStore1
DataSourceStorageImpl(const DataSourceStorageImpl &orig)
boost::function_traits< DataType >::arg5_type arg5_type
void store(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4)
DataSourceArgStorage< arg4_type >::Store AStore4
DataSourceStorageImpl(const DataSourceStorageImpl &orig)
DataSourceArgStorage< arg3_type >::Store AStore3
boost::function_traits< DataType >::arg2_type arg2_type
boost::function_traits< DataType >::result_type result_type
boost::function_traits< DataType >::arg6_type arg6_type
DataSourceStorageImpl(const DataSourceStorageImpl &orig)
DataSourceArgStorage< arg5_type >::Store AStore5
void store(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5)
DataSource< T >::result_t get() const
Definition: DataSources.hpp:78
DataSourceArgStorage< arg4_type >::Store AStore4
boost::function_traits< DataType >::result_type result_type
boost::function_traits< DataType >::arg3_type arg3_type
void setPointer(const typename AssignableDataSource< T >::value_t *ptr)
boost::function_traits< DataType >::arg4_type arg4_type
boost::function_traits< DataType >::arg1_type arg1_type
boost::remove_const< typename boost::remove_reference< T >::type >::type type
Definition: mystd.hpp:63
ValueDataSource< ds_type >::shared_ptr value
boost::function_traits< DataType >::arg2_type arg2_type
DataSourceStorageImpl(const DataSourceStorageImpl &orig)
boost::intrusive_ptr< DataSourceBase > shared_ptr
DataSourceStorageImpl(const DataSourceStorageImpl &orig)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
DataSourceArgStorage< arg5_type >::Store AStore5
DataSourceStorageImpl(const DataSourceStorageImpl &orig)
DataSourceArgStorage< arg1_type >::Store AStore1
boost::function_traits< DataType >::arg3_type arg3_type
DataSourceArgStorage< arg2_type >::Store AStore2
DataSourceArgStorage< arg2_type >::Store AStore2
boost::function_traits< DataType >::result_type result_type
boost::function_traits< DataType >::arg1_type arg1_type
boost::function_traits< DataType >::arg5_type arg5_type
ReferenceDataSource< ds_type >::shared_ptr result
boost::function_traits< DataType >::arg3_type arg3_type
boost::function_traits< DataType >::arg2_type arg2_type
DataSourceArgStorage< arg5_type >::Store AStore5


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