stlab.adobe.com Adobe Systems Incorporated

function_traits.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://opensource.adobe.com/licenses.html)
00005 */
00006 
00007 /**************************************************************************************************/
00008 
00009 #ifndef ADOBE_FUNCTION_TRAITS_HPP
00010 #define ADOBE_FUNCTION_TRAITS_HPP
00011 
00012 #include <adobe/config.hpp>
00013 
00014 #include <boost/function.hpp>
00015 
00016 /**************************************************************************************************/
00017 
00018 namespace adobe {
00019 
00020 /**************************************************************************************************/
00027 /**************************************************************************************************/
00028 
00029 template <typename T>
00030 struct function_traits;
00031 
00032 /**************************************************************************************************/
00033 
00034 template <typename R>
00035 struct function_traits<R()>
00036 {
00037     enum { arity = 0 };
00038 
00039     typedef R result_type;
00040 
00041     typedef R(function_type)();
00042     typedef R(&param_type)();
00043 };
00044 
00045 template <typename R,
00046           typename A1>
00047 struct function_traits<R(A1)> :
00048     public function_traits<R()>
00049 {
00050     enum { arity = 1 };
00051 
00052     typedef A1 first_argument_type;
00053     typedef A1 arg1_type;
00054 
00055     typedef R(function_type)(A1);
00056     typedef R(&param_type)(A1);
00057 };
00058 
00059 template <typename R,
00060           typename A1, typename A2>
00061 struct function_traits<R(A1, A2)> :
00062     public function_traits<R(A1)>
00063 {
00064     enum { arity = 2 };
00065 
00066     typedef A1 second_argument_type;
00067     typedef A2 arg2_type;
00068 
00069     typedef R(function_type)(A1, A2);
00070     typedef R(&param_type)(A1, A2);
00071 };
00072 
00073 template <typename R,
00074           typename A1, typename A2, typename A3>
00075 struct function_traits<R(A1, A2, A3)> :
00076     public function_traits<R(A1, A2)>
00077 {
00078     enum { arity = 3 };
00079 
00080     typedef A3 third_argument_type;
00081     typedef A3 arg3_type;
00082 
00083     typedef R(function_type)(A1, A2, A3);
00084     typedef R(&param_type)(A1, A2, A3);
00085 };
00086 
00087 template <typename R,
00088           typename A1, typename A2, typename A3, typename A4>
00089 struct function_traits<R(A1, A2, A3, A4)> :
00090     public function_traits<R(A1, A2, A3)>
00091 {
00092     enum { arity = 4 };
00093 
00094     typedef A4 fourth_argument_type;
00095     typedef A4 arg4_type;
00096 
00097     typedef R(function_type)(A1, A2, A3, A4);
00098     typedef R(&param_type)(A1, A2, A3, A4);
00099 };
00100 
00101 template <typename R,
00102           typename A1, typename A2, typename A3, typename A4, typename A5>
00103 struct function_traits<R(A1, A2, A3, A4, A5)> :
00104     public function_traits<R(A1, A2, A3, A4)>
00105 {
00106     enum { arity = 5 };
00107 
00108     typedef A5 fifth_argument_type;
00109     typedef A5 arg5_type;
00110 
00111     typedef R(function_type)(A1, A2, A3, A4, A5);
00112     typedef R(&param_type)(A1, A2, A3, A4, A5);
00113 };
00114 
00115 template <typename R,
00116           typename A1, typename A2, typename A3, typename A4, typename A5,
00117           typename A6>
00118 struct function_traits<R(A1, A2, A3, A4, A5, A6)> :
00119     public function_traits<R(A1, A2, A3, A4, A5)>
00120 {
00121     enum { arity = 6 };
00122 
00123     typedef A6 sixth_argument_type;
00124     typedef A6 arg6_type;
00125 
00126     typedef R(function_type)(A1, A2, A3, A4, A5, A6);
00127     typedef R(&param_type)(A1, A2, A3, A4, A5, A6);
00128 };
00129 
00130 template <typename R,
00131           typename A1, typename A2, typename A3, typename A4, typename A5,
00132           typename A6, typename A7>
00133 struct function_traits<R(A1, A2, A3, A4, A5, A6, A7)> :
00134     public function_traits<R(A1, A2, A3, A4, A5, A6)>
00135 {
00136     enum { arity = 7 };
00137 
00138     typedef A7 seventh_argument_type;
00139     typedef A7 arg7_type;
00140 
00141     typedef R(function_type)(A1, A2, A3, A4, A5, A6, A7);
00142     typedef R(&param_type)(A1, A2, A3, A4, A5, A6, A7);
00143 };
00144 
00145 /**************************************************************************************************/
00146 
00147 template <typename R>
00148 struct function_traits<R(*)()> :
00149     public function_traits<R()>
00150 {
00151     typedef R(*function_type)();
00152     typedef R(*param_type)();
00153 };
00154 
00155 template <typename R,
00156           typename A1>
00157 struct function_traits<R(*)(A1)> :
00158     public function_traits<R(A1)>
00159 {
00160     typedef R(*function_type)(A1);
00161     typedef R(*param_type)(A1);
00162 };
00163 
00164 template <typename R,
00165           typename A1, typename A2>
00166 struct function_traits<R(*)(A1, A2)> :
00167     public function_traits<R(A1, A2)>
00168 {
00169     typedef R(*function_type)(A1, A2);
00170     typedef R(*param_type)(A1, A2);
00171 };
00172 
00173 template <typename R,
00174           typename A1, typename A2, typename A3>
00175 struct function_traits<R(*)(A1, A2, A3)> :
00176     public function_traits<R(A1, A2, A3)>
00177 {
00178     typedef R(*function_type)(A1, A2, A3);
00179     typedef R(*param_type)(A1, A2, A3);
00180 };
00181 
00182 template <typename R,
00183           typename A1, typename A2, typename A3, typename A4>
00184 struct function_traits<R(*)(A1, A2, A3, A4)> :
00185     public function_traits<R(A1, A2, A3, A4)>
00186 {
00187     typedef R(*function_type)(A1, A2, A3, A4);
00188     typedef R(*param_type)(A1, A2, A3, A4);
00189 };
00190 
00191 template <typename R,
00192           typename A1, typename A2, typename A3, typename A4, typename A5>
00193 struct function_traits<R(*)(A1, A2, A3, A4, A5)> :
00194     public function_traits<R(A1, A2, A3, A4, A5)>
00195 {
00196     typedef R(*function_type)(A1, A2, A3, A4, A5);
00197     typedef R(*param_type)(A1, A2, A3, A4, A5);
00198 };
00199 
00200 template <typename R,
00201           typename A1, typename A2, typename A3, typename A4, typename A5,
00202           typename A6>
00203 struct function_traits<R(*)(A1, A2, A3, A4, A5, A6)> :
00204     public function_traits<R(A1, A2, A3, A4, A5, A6)>
00205 {
00206     typedef R(*function_type)(A1, A2, A3, A4, A5, A6);
00207     typedef R(*param_type)(A1, A2, A3, A4, A5, A6);
00208 };
00209 
00210 template <typename R,
00211           typename A1, typename A2, typename A3, typename A4, typename A5,
00212           typename A6, typename A7>
00213 struct function_traits<R(*)(A1, A2, A3, A4, A5, A6, A7)> :
00214     public function_traits<R(A1, A2, A3, A4, A5, A6, A7)>
00215 {
00216     typedef R(*function_type)(A1, A2, A3, A4, A5, A6, A7);
00217     typedef R(*param_type)(A1, A2, A3, A4, A5, A6, A7);
00218 };
00219 
00220 /**************************************************************************************************/
00221 
00222 template <typename R>
00223 struct function_traits<R(&)()> :
00224     public function_traits<R()>
00225 {
00226     typedef R(&function_type)();
00227     typedef R(&param_type)();
00228 };
00229 
00230 template <typename R,
00231           typename A1>
00232 struct function_traits<R(&)(A1)> :
00233     public function_traits<R(A1)>
00234 {
00235     typedef R(&function_type)(A1);
00236     typedef R(&param_type)(A1);
00237 };
00238 
00239 template <typename R,
00240           typename A1, typename A2>
00241 struct function_traits<R(&)(A1, A2)> :
00242     public function_traits<R(A1, A2)>
00243 {
00244     typedef R(&function_type)(A1, A2);
00245     typedef R(&param_type)(A1, A2);
00246 };
00247 
00248 template <typename R,
00249           typename A1, typename A2, typename A3>
00250 struct function_traits<R(&)(A1, A2, A3)> :
00251     public function_traits<R(A1, A2, A3)>
00252 {
00253     typedef R(&function_type)(A1, A2, A3);
00254     typedef R(&param_type)(A1, A2, A3);
00255 };
00256 
00257 template <typename R,
00258           typename A1, typename A2, typename A3, typename A4>
00259 struct function_traits<R(&)(A1, A2, A3, A4)> :
00260     public function_traits<R(A1, A2, A3, A4)>
00261 {
00262     typedef R(&function_type)(A1, A2, A3, A4);
00263     typedef R(&param_type)(A1, A2, A3, A4);
00264 };
00265 
00266 template <typename R,
00267           typename A1, typename A2, typename A3, typename A4, typename A5>
00268 struct function_traits<R(&)(A1, A2, A3, A4, A5)> :
00269     public function_traits<R(A1, A2, A3, A4, A5)>
00270 {
00271     typedef R(&function_type)(A1, A2, A3, A4, A5);
00272     typedef R(&param_type)(A1, A2, A3, A4, A5);
00273 };
00274 
00275 template <typename R,
00276           typename A1, typename A2, typename A3, typename A4, typename A5,
00277           typename A6>
00278 struct function_traits<R(&)(A1, A2, A3, A4, A5, A6)> :
00279     public function_traits<R(A1, A2, A3, A4, A5, A6)>
00280 {
00281     typedef R(&function_type)(A1, A2, A3, A4, A5, A6);
00282     typedef R(&param_type)(A1, A2, A3, A4, A5, A6);
00283 };
00284 
00285 template <typename R,
00286           typename A1, typename A2, typename A3, typename A4, typename A5,
00287           typename A6, typename A7>
00288 struct function_traits<R(&)(A1, A2, A3, A4, A5, A6, A7)> :
00289     public function_traits<R(A1, A2, A3, A4, A5, A6, A7)>
00290 {
00291     typedef R(&function_type)(A1, A2, A3, A4, A5, A6, A7);
00292     typedef R(&param_type)(A1, A2, A3, A4, A5, A6, A7);
00293 };
00294 
00295 /**************************************************************************************************/
00296 
00297 template <typename R,
00298           typename A1>
00299 struct function_traits<R(A1::*)()>
00300 {
00301     enum { arity = 1 };
00302 
00303     typedef R result_type;
00304 
00305     typedef R(A1::*function_type)();
00306     typedef R(A1::*param_type)();
00307 
00308     typedef A1* arg1_type;
00309     typedef A1* first_argument_type;
00310 };
00311 
00312 template <typename R,
00313           typename A1, typename A2>
00314 struct function_traits<R(A1::*)(A2)> :
00315     public function_traits<R(A1::*)()>
00316 {
00317     enum { arity = 2 };
00318 
00319     typedef R(A1::*function_type)(A2);
00320     typedef R(A1::*param_type)(A2);
00321 
00322     typedef A2 arg2_type;
00323     typedef A2 second_argument_type;
00324 };
00325 
00326 template <typename R,
00327           typename A1, typename A2, typename A3>
00328 struct function_traits<R(A1::*)(A2, A3)> :
00329     public function_traits<R(A1::*)(A2)>
00330 {
00331     enum { arity = 3 };
00332 
00333     typedef R(A1::*function_type)(A2, A3);
00334     typedef R(A1::*param_type)(A2, A3);
00335 
00336     typedef A3 arg3_type;
00337     typedef A3 third_argument_type;
00338 };
00339 
00340 template <typename R,
00341           typename A1, typename A2, typename A3, typename A4>
00342 struct function_traits<R(A1::*)(A2, A3, A4)> :
00343     public function_traits<R(A1::*)(A2, A3)>
00344 {
00345     enum { arity = 4 };
00346 
00347     typedef R(A1::*function_type)(A2, A3, A4);
00348     typedef R(A1::*param_type)(A2, A3, A4);
00349 
00350     typedef A4 arg4_type;
00351     typedef A4 fourth_argument_type;
00352 };
00353 
00354 template <typename R,
00355           typename A1, typename A2, typename A3, typename A4, typename A5>
00356 struct function_traits<R(A1::*)(A2, A3, A4, A5)> :
00357     public function_traits<R(A1::*)(A2, A3, A4)>
00358 {
00359     enum { arity = 5 };
00360 
00361     typedef R(A1::*function_type)(A2, A3, A4, A5);
00362     typedef R(A1::*param_type)(A2, A3, A4, A5);
00363 
00364     typedef A5 arg5_type;
00365     typedef A5 fifth_argument_type;
00366 };
00367 
00368 template <typename R,
00369           typename A1, typename A2, typename A3, typename A4, typename A5,
00370           typename A6>
00371 struct function_traits<R(A1::*)(A2, A3, A4, A5, A6)> :
00372     public function_traits<R(A1::*)(A2, A3, A4, A5)>
00373 {
00374     enum { arity = 6 };
00375 
00376     typedef R(A1::*function_type)(A2, A3, A4, A5, A6);
00377     typedef R(A1::*param_type)(A2, A3, A4, A5, A6);
00378 
00379     typedef A6 arg6_type;
00380     typedef A6 sixth_argument_type;
00381 };
00382 
00383 template <typename R,
00384           typename A1, typename A2, typename A3, typename A4, typename A5,
00385           typename A6, typename A7>
00386 struct function_traits<R(A1::*)(A2, A3, A4, A5, A6, A7)> :
00387     public function_traits<R(A1::*)(A2, A3, A4, A5, A6)>
00388 {
00389     enum { arity = 7 };
00390 
00391     typedef R(A1::*function_type)(A2, A3, A4, A5, A6, A7);
00392     typedef R(A1::*param_type)(A2, A3, A4, A5, A6, A7);
00393 
00394     typedef A7 arg7_type;
00395     typedef A7 seventh_argument_type;
00396 };
00397 
00398 /**************************************************************************************************/
00399 
00400 template <typename R,
00401           typename A1>
00402 struct function_traits<R(A1::*)() const> :
00403     public function_traits<R(A1::*)()>
00404 {
00405     typedef R(A1::*function_type)() const;
00406     typedef R(A1::*param_type)() const;
00407 };
00408 
00409 template <typename R,
00410           typename A1, typename A2>
00411 struct function_traits<R(A1::*)(A2) const> :
00412     public function_traits<R(A1::*)(A2)>
00413 {
00414     typedef R(A1::*function_type)(A2) const;
00415     typedef R(A1::*param_type)(A2) const;
00416 };
00417 
00418 template <typename R,
00419           typename A1, typename A2, typename A3>
00420 struct function_traits<R(A1::*)(A2, A3) const> :
00421     public function_traits<R(A1::*)(A2, A3)>
00422 {
00423     typedef R(A1::*function_type)(A2, A3) const;
00424     typedef R(A1::*param_type)(A2, A3) const;
00425 };
00426 
00427 template <typename R,
00428           typename A1, typename A2, typename A3, typename A4>
00429 struct function_traits<R(A1::*)(A2, A3, A4) const> :
00430     public function_traits<R(A1::*)(A2, A3, A4)>
00431 {
00432     typedef R(A1::*function_type)(A2, A3, A4) const;
00433     typedef R(A1::*param_type)(A2, A3, A4) const;
00434 };
00435 
00436 template <typename R,
00437           typename A1, typename A2, typename A3, typename A4, typename A5>
00438 struct function_traits<R(A1::*)(A2, A3, A4, A5) const> :
00439     public function_traits<R(A1::*)(A2, A3, A4, A5)>
00440 {
00441     typedef R(A1::*function_type)(A2, A3, A4, A5) const;
00442     typedef R(A1::*param_type)(A2, A3, A4, A5) const;
00443 };
00444 
00445 template <typename R,
00446           typename A1, typename A2, typename A3, typename A4, typename A5,
00447           typename A6>
00448 struct function_traits<R(A1::*)(A2, A3, A4, A5, A6) const> :
00449     public function_traits<R(A1::*)(A2, A3, A4, A5, A6)>
00450 {
00451     typedef R(A1::*function_type)(A2, A3, A4, A5, A6) const;
00452     typedef R(A1::*param_type)(A2, A3, A4, A5, A6) const;
00453 };
00454 
00455 template <typename R,
00456           typename A1, typename A2, typename A3, typename A4, typename A5,
00457           typename A6, typename A7>
00458 struct function_traits<R(A1::*)(A2, A3, A4, A5, A6, A7) const> :
00459     public function_traits<R(A1::*)(A2, A3, A4, A5, A6, A7)>
00460 {
00461     typedef R(A1::*function_type)(A2, A3, A4, A5, A6, A7) const;
00462     typedef R(A1::*param_type)(A2, A3, A4, A5, A6, A7) const;
00463 };
00464 
00465 /**************************************************************************************************/
00466 
00467 template <typename F>
00468 struct function_traits<boost::function<F> > :
00469     public function_traits<F>
00470 {
00471     typedef boost::function<F>        function_type;
00472     typedef const boost::function<F>& param_type;
00473 };
00474 
00475 /**************************************************************************************************/
00476 
00477 } // namespace adobe
00478 
00479 /**************************************************************************************************/
00480 
00481 #endif
00482 
00483 /**************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google