Orocos Real-Time Toolkit  2.6.0
ReturnSignature.hpp
00001 /***************************************************************************
00002   tag: The SourceWorks  Tue Sep 7 00:55:18 CEST 2010  ReturnSignature.hpp
00003 
00004                         ReturnSignature.hpp -  description
00005                            -------------------
00006     begin                : Tue September 07 2010
00007     copyright            : (C) 2010 The SourceWorks
00008     email                : peter@thesourceworks.com
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 
00039 #ifndef ORO_RETURN_SIGNATURE_HPP
00040 #define ORO_RETURN_SIGNATURE_HPP
00041 
00042 #include <boost/type_traits.hpp>
00043 #include "NA.hpp"
00044 #include "../rtt-fwd.hpp"
00045 
00046 namespace RTT
00047 {
00048     namespace internal
00049     {
00056         template<int, class Signature, class ToInvoke>
00057         struct ReturnSignature;
00058 
00059         template<class F, class ToInvoke>
00060         struct ReturnSignature<0,F,ToInvoke>
00061         {
00062             typedef typename boost::function_traits<F>::result_type result_type;
00063 
00064             ReturnSignature() : impl() {}
00065             ReturnSignature(ToInvoke implementation) : impl(implementation) {}
00066             ~ReturnSignature() {}
00067 
00068             result_type ret() {
00069                 if (impl)
00070                     return impl->ret();
00071                 return NA<result_type>::na();
00072             }
00073 
00074         protected:
00075             ToInvoke impl;
00076         };
00077 
00078         template<class F, class ToInvoke>
00079         struct ReturnSignature<1,F,ToInvoke>
00080         {
00081             typedef typename boost::function_traits<F>::result_type result_type;
00082             typedef typename boost::function_traits<F>::arg1_type arg1_type;
00083 
00084             ReturnSignature() : impl() {}
00085             ReturnSignature(ToInvoke implementation) : impl(implementation) {}
00086             ~ReturnSignature() {}
00087 
00088             result_type ret(arg1_type a1) {
00089                 if (impl)
00090                     return impl->ret( a1 );
00091                 return NA<result_type>::na();
00092             }
00093 
00094             result_type ret() {
00095                 if (impl)
00096                     return impl->ret();
00097                 return NA<result_type>::na();
00098             }
00099 
00100         protected:
00101             ToInvoke impl;
00102         };
00103 
00104         template<class F, class ToInvoke>
00105         struct ReturnSignature<2,F,ToInvoke>
00106         {
00107             typedef typename boost::function_traits<F>::result_type result_type;
00108             typedef typename boost::function_traits<F>::arg1_type arg1_type;
00109             typedef typename boost::function_traits<F>::arg2_type arg2_type;
00110 
00111             ReturnSignature() : impl() {}
00112             ReturnSignature(ToInvoke implementation) : impl(implementation) {}
00113             ~ReturnSignature() {}
00114 
00115             result_type ret(arg1_type a1, arg2_type a2) {
00116                 if (impl)
00117                     return impl->ret( a1,a2 );
00118                 return NA<result_type>::na();
00119             }
00120 
00121             result_type ret() {
00122                 if (impl)
00123                     return impl->ret();
00124                 return NA<result_type>::na();
00125             }
00126         protected:
00127             ToInvoke impl;
00128         };
00129 
00130         template<class F, class ToInvoke>
00131         struct ReturnSignature<3,F,ToInvoke>
00132         {
00133             typedef typename boost::function_traits<F>::result_type result_type;
00134             typedef typename boost::function_traits<F>::arg1_type arg1_type;
00135             typedef typename boost::function_traits<F>::arg2_type arg2_type;
00136             typedef typename boost::function_traits<F>::arg3_type arg3_type;
00137 
00138             ReturnSignature() : impl() {}
00139             ReturnSignature(ToInvoke implementation) : impl(implementation) {}
00140             ~ReturnSignature() { }
00141 
00142             result_type ret(arg1_type a1, arg2_type a2, arg3_type a3) {
00143                 if (impl)
00144                     return impl->ret( a1,a2,a3 );
00145                 return NA<result_type>::na();
00146             }
00147 
00148             result_type ret() {
00149                 if (impl)
00150                     return impl->ret();
00151                 return NA<result_type>::na();
00152             }
00153 
00154         protected:
00155             ToInvoke impl;
00156         };
00157 
00158         template<class F, class ToInvoke>
00159         struct ReturnSignature<4,F,ToInvoke>
00160         {
00161             typedef typename boost::function_traits<F>::result_type result_type;
00162             typedef typename boost::function_traits<F>::arg1_type arg1_type;
00163             typedef typename boost::function_traits<F>::arg2_type arg2_type;
00164             typedef typename boost::function_traits<F>::arg3_type arg3_type;
00165             typedef typename boost::function_traits<F>::arg4_type arg4_type;
00166 
00167             ReturnSignature() : impl() {}
00168             ReturnSignature(ToInvoke implementation) : impl(implementation) {}
00169             ~ReturnSignature() { }
00170 
00171             result_type ret(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4) {
00172                 if (impl)
00173                     return impl->ret( a1,a2,a3,a4 );
00174                 return NA<result_type>::na();
00175             }
00176 
00177             result_type ret() {
00178                 if (impl)
00179                     return impl->ret();
00180                 return NA<result_type>::na();
00181             }
00182         protected:
00183             ToInvoke impl;
00184         };
00185 
00186         template<class F, class ToInvoke>
00187         struct ReturnSignature<5,F,ToInvoke>
00188         {
00189             typedef typename boost::function_traits<F>::result_type result_type;
00190             typedef typename boost::function_traits<F>::arg1_type arg1_type;
00191             typedef typename boost::function_traits<F>::arg2_type arg2_type;
00192             typedef typename boost::function_traits<F>::arg3_type arg3_type;
00193             typedef typename boost::function_traits<F>::arg4_type arg4_type;
00194             typedef typename boost::function_traits<F>::arg5_type arg5_type;
00195 
00196             ReturnSignature() : impl() {}
00197             ReturnSignature(ToInvoke implementation) : impl(implementation) {}
00198             ~ReturnSignature() { }
00199 
00200             result_type ret(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5) {
00201                 if (impl)
00202                     return impl->ret( a1,a2,a3,a4,a5 );
00203                 return NA<result_type>::na();
00204             }
00205 
00206             result_type ret() {
00207                 if (impl)
00208                     return impl->ret();
00209                 return NA<result_type>::na();
00210             }
00211         protected:
00212             ToInvoke impl;
00213         };
00214 
00215         template<class F, class ToInvoke>
00216         struct ReturnSignature<6,F,ToInvoke>
00217         {
00218             typedef typename boost::function_traits<F>::result_type result_type;
00219             typedef typename boost::function_traits<F>::arg1_type arg1_type;
00220             typedef typename boost::function_traits<F>::arg2_type arg2_type;
00221             typedef typename boost::function_traits<F>::arg3_type arg3_type;
00222             typedef typename boost::function_traits<F>::arg4_type arg4_type;
00223             typedef typename boost::function_traits<F>::arg5_type arg5_type;
00224             typedef typename boost::function_traits<F>::arg6_type arg6_type;
00225 
00226             ReturnSignature() : impl() {}
00227             ReturnSignature(ToInvoke implementation) : impl(implementation) {}
00228             ~ReturnSignature() { }
00229 
00230             result_type ret(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5, arg6_type a6) {
00231                 if (impl)
00232                     return impl->ret( a1,a2,a3,a4,a5,a6 );
00233                 return NA<result_type>::na();
00234             }
00235 
00236             result_type ret() {
00237                 if (impl)
00238                     return impl->ret();
00239                 return NA<result_type>::na();
00240             }
00241         protected:
00242             ToInvoke impl;
00243         };
00244 
00245         template<class F, class ToInvoke>
00246         struct ReturnSignature<7,F,ToInvoke>
00247         {
00248             typedef typename boost::function_traits<F>::result_type result_type;
00249             typedef typename boost::function_traits<F>::arg1_type arg1_type;
00250             typedef typename boost::function_traits<F>::arg2_type arg2_type;
00251             typedef typename boost::function_traits<F>::arg3_type arg3_type;
00252             typedef typename boost::function_traits<F>::arg4_type arg4_type;
00253             typedef typename boost::function_traits<F>::arg5_type arg5_type;
00254             typedef typename boost::function_traits<F>::arg6_type arg6_type;
00255             typedef typename boost::function_traits<F>::arg7_type arg7_type;
00256 
00257             ReturnSignature() : impl() {}
00258             ReturnSignature(ToInvoke implementation) : impl(implementation) {}
00259             ~ReturnSignature() { }
00260 
00261             result_type ret(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4, arg5_type a5, arg6_type a6, arg7_type a7) {
00262                 if (impl)
00263                     return impl->ret( a1,a2,a3,a4,a5,a6,a7 );
00264                 return NA<result_type>::na();
00265             }
00266 
00267             result_type ret() {
00268                 if (impl)
00269                     return impl->ret();
00270                 return NA<result_type>::na();
00271             }
00272         protected:
00273             ToInvoke impl;
00274         };
00275 
00276     }
00277 }
00278 #endif