Orocos Real-Time Toolkit  2.8.3
CollectSignature.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 CollectSignature.hpp
3 
4  CollectSignature.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_COLLECT_SIGNATURE_HPP
40 #define ORO_COLLECT_SIGNATURE_HPP
41 
42 #include <boost/function_types/function_type.hpp>
43 #include <boost/function_types/function_arity.hpp>
44 #include <boost/function_types/result_type.hpp>
45 #include <boost/function_types/parameter_types.hpp>
46 #include <boost/mpl/vector.hpp>
47 #include <boost/mpl/remove_if.hpp>
48 #include <boost/mpl/push_front.hpp>
49 #include <boost/mpl/not.hpp>
50 #include <boost/mpl/logical.hpp>
51 #include <boost/mpl/if.hpp>
52 #include <boost/type_traits.hpp>
53 #include "../SendStatus.hpp"
54 
55 namespace RTT
56 {
57  namespace internal
58  {
59  namespace ft=boost::function_types;
60  namespace mpl=boost::mpl;
61  namespace tt=boost;
62 
74  template<class F>
75  struct CollectType
76  {
77  private:
78  // Decompose F into all components (ret, args,...):
79  // Remove first component and store in ret_type:
80  typedef typename ft::result_type<F>::type ret_type;
81  typedef typename ft::parameter_types<F>::type arg_type;
82  typedef typename tt::remove_const< typename tt::remove_reference<ret_type>::type >::type bare_ret_type;
83  typedef typename mpl::if_<
84  typename mpl::not_< typename tt::is_void<ret_type>::type >::type,
85  typename mpl::push_front< arg_type, typename tt::add_reference< bare_ret_type >::type >::type,
86  arg_type
87  >::type basic_sig;
88  // basic_sig now needs to be removed of all non-reference arguments.
89  // we first with removing all consts and const references:
90  // note about the lambda expression: we pass a struct, not a typenamed 'type'.
91  typedef typename mpl::remove_if< basic_sig, tt::is_const< tt::remove_reference<mpl::_1> > >::type no_const_sig;
92  // next we need to remove all non-reference values:
93  typedef typename mpl::remove_if< no_const_sig, mpl::not_<tt::is_reference<mpl::_1> > >::type no_value_sig;
94  // Finally, add ret_type as return value (first item in vector):
95  typedef typename mpl::push_front< no_value_sig, ret_type>::type fttype;
96  public:
97  // Form function type again from the mpl vector:
98  typedef typename ft::function_type<fttype>::type Ft;
99  // Type is a more standard way of result type.
100  typedef Ft type;
101  // The collect type signature as an mpl list
102  typedef fttype mpl_type;
103  };
104 
111  template<int, class Signature, class ToCollect>
113 
114  // This case is only present if the return value is void
115  // and all arguments are of in kind.
116  template<class F, class ToCollect>
117  struct CollectSignature<0,F,ToCollect>
118  {
119  typedef void result_type;
120  CollectSignature() : cimpl() {}
121  CollectSignature(ToCollect implementation) : cimpl(implementation) {}
123 
125  {
126  if (this->cimpl)
127  return this->cimpl->collect();
128  return SendFailure;
129  }
130 
132  {
133  if (this->cimpl)
134  return this->cimpl->collectIfDone();
135  return SendFailure;
136  }
137 
138  protected:
139  ToCollect cimpl;
140  };
141 
142  // Used when return non void with only in kind args OR return void
143  // and one out/inout arg.
144  template<class F, class ToCollect>
145  struct CollectSignature<1,F,ToCollect>
146  {
147  typedef typename boost::function_traits<F>::result_type result_type;
148  typedef typename boost::function_traits<F>::arg1_type arg1_type;
149 
150  CollectSignature() : cimpl() {}
151  CollectSignature(ToCollect implementation) : cimpl(implementation) {}
153 
157  SendStatus collect(arg1_type a1)
158  {
159  if (cimpl)
160  return cimpl->collect( a1 );
161  return SendFailure;
162  }
163 
164  SendStatus collectIfDone(arg1_type a1)
165  {
166  if (cimpl)
167  return cimpl->collectIfDone( a1 );
168  return SendFailure;
169  }
170  protected:
171  ToCollect cimpl;
172  };
173 
174  template<class F, class ToCollect>
175  struct CollectSignature<2,F,ToCollect>
176  {
177  typedef typename boost::function_traits<F>::arg1_type arg1_type;
178  typedef typename boost::function_traits<F>::arg2_type arg2_type;
179 
180  CollectSignature() : cimpl() {}
181  CollectSignature(ToCollect implementation) : cimpl(implementation) {}
183 
187  SendStatus collect(arg1_type t1, arg2_type t2)
188  {
189  if (cimpl)
190  return cimpl->collect(t1, t2);
191  return SendFailure;
192  }
193 
194  SendStatus collectIfDone(arg1_type t1, arg2_type t2)
195  {
196  if (cimpl)
197  return cimpl->collectIfDone(t1, t2);
198  return SendFailure;
199  }
200  protected:
201  ToCollect cimpl;
202  };
203 
204  template<class F, class ToCollect>
205  struct CollectSignature<3,F,ToCollect>
206  {
207  typedef typename boost::function_traits<F>::arg1_type arg1_type;
208  typedef typename boost::function_traits<F>::arg2_type arg2_type;
209  typedef typename boost::function_traits<F>::arg3_type arg3_type;
210 
211  CollectSignature() : cimpl() {}
212  CollectSignature(ToCollect implementation) : cimpl(implementation) {}
214 
218  SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3)
219  {
220  if (cimpl)
221  return cimpl->collect(t1, t2, t3);
222  return SendFailure;
223  }
224 
225  SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3)
226  {
227  if (cimpl)
228  return cimpl->collectIfDone(t1, t2, t3);
229  return SendFailure;
230  }
231  protected:
232  ToCollect cimpl;
233  };
234 
235  template<class F, class ToCollect>
236  struct CollectSignature<4,F,ToCollect>
237  {
238  typedef typename boost::function_traits<F>::arg1_type arg1_type;
239  typedef typename boost::function_traits<F>::arg2_type arg2_type;
240  typedef typename boost::function_traits<F>::arg3_type arg3_type;
241  typedef typename boost::function_traits<F>::arg4_type arg4_type;
242 
243  CollectSignature() : cimpl() {}
244  CollectSignature(ToCollect implementation) : cimpl(implementation) {}
246 
250  SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4)
251  {
252  if (cimpl)
253  return cimpl->collect(t1, t2, t3, t4);
254  return SendFailure;
255  }
256 
257  SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4)
258  {
259  if (cimpl)
260  return cimpl->collectIfDone(t1, t2, t3, t4);
261  return SendFailure;
262  }
263  protected:
264  ToCollect cimpl;
265  };
266 
267  template<class F, class ToCollect>
268  struct CollectSignature<5,F,ToCollect>
269  {
270  typedef typename boost::function_traits<F>::arg1_type arg1_type;
271  typedef typename boost::function_traits<F>::arg2_type arg2_type;
272  typedef typename boost::function_traits<F>::arg3_type arg3_type;
273  typedef typename boost::function_traits<F>::arg4_type arg4_type;
274  typedef typename boost::function_traits<F>::arg5_type arg5_type;
275 
276  CollectSignature() : cimpl() {}
277  CollectSignature(ToCollect implementation) : cimpl(implementation) {}
279 
283  SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5)
284  {
285  if (cimpl)
286  return cimpl->collect(t1, t2, t3, t4, t5);
287  return SendFailure;
288  }
289 
290  SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5)
291  {
292  if (cimpl)
293  return cimpl->collectIfDone(t1, t2, t3, t4, t5);
294  return SendFailure;
295  }
296  protected:
297  ToCollect cimpl;
298  };
299 
300  template<class F, class ToCollect>
301  struct CollectSignature<6,F,ToCollect>
302  {
303  typedef typename boost::function_traits<F>::arg1_type arg1_type;
304  typedef typename boost::function_traits<F>::arg2_type arg2_type;
305  typedef typename boost::function_traits<F>::arg3_type arg3_type;
306  typedef typename boost::function_traits<F>::arg4_type arg4_type;
307  typedef typename boost::function_traits<F>::arg5_type arg5_type;
308  typedef typename boost::function_traits<F>::arg6_type arg6_type;
309 
310  CollectSignature() : cimpl() {}
311  CollectSignature(ToCollect implementation) : cimpl(implementation) {}
313 
317  SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5, arg6_type t6)
318  {
319  if (cimpl)
320  return cimpl->collect(t1, t2, t3, t4, t5, t6);
321  return SendFailure;
322  }
323 
324  SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5, arg6_type t6)
325  {
326  if (cimpl)
327  return cimpl->collectIfDone(t1, t2, t3, t4, t5, t6);
328  return SendFailure;
329  }
330  protected:
331  ToCollect cimpl;
332  };
333 
334  }
335 }
336 #endif
boost::function_traits< F >::arg2_type arg2_type
boost::function_traits< F >::result_type result_type
SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3)
boost::function_traits< F >::arg4_type arg4_type
ft::function_type< fttype >::type Ft
SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5, arg6_type t6)
boost::function_traits< F >::arg1_type arg1_type
boost::function_traits< F >::arg2_type arg2_type
SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5)
Collect this operator if the method has four arguments.
boost::function_traits< F >::arg2_type arg2_type
boost::function_traits< F >::arg1_type arg1_type
boost::function_traits< F >::arg2_type arg2_type
SendStatus
Returns the status of a send() or collect() invocation.
Definition: SendStatus.hpp:53
boost::function_traits< F >::arg4_type arg4_type
SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5)
boost::function_traits< F >::arg3_type arg3_type
boost::function_traits< F >::arg2_type arg2_type
SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4)
boost::function_traits< F >::arg5_type arg5_type
boost::function_traits< F >::arg1_type arg1_type
SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4)
Collect this operator if the method has four arguments.
Returned when the result of the send() could not be collected.
Definition: SendStatus.hpp:55
SendStatus collectIfDone(arg1_type t1, arg2_type t2)
SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3)
Collect this operator if the method has three arguments.
SendStatus collect(arg1_type a1)
Collect this operator if the method has one argument.
boost::function_traits< F >::arg1_type arg1_type
boost::function_traits< F >::arg1_type arg1_type
boost::function_traits< F >::arg3_type arg3_type
boost::function_traits< F >::arg3_type arg3_type
boost::function_traits< F >::arg1_type arg1_type
boost::function_traits< F >::arg6_type arg6_type
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
SendStatus collect(arg1_type t1, arg2_type t2)
Collect this operator if the method has two arguments.
boost::function_traits< F >::arg3_type arg3_type
boost::function_traits< F >::arg5_type arg5_type
Used to implement collect(), given a Function Signature.
boost::function_traits< F >::arg4_type arg4_type
This helper struct decomposes F and creates Ft, as required by CollectBaseImpl.
SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5, arg6_type t6)
Collect this operator if the method has four arguments.