00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef CNTM_SIGNATUREINFO_H
00015 #define CNTM_SIGNATUREINFO_H
00016 #include <cstdlib>
00017 #include <boost/preprocessor/control/if.hpp>
00018 #include <boost/preprocessor/facilities/empty.hpp>
00019 #include <boost/preprocessor/repetition/enum.hpp>
00020 #include <boost/preprocessor/repetition/enum_params.hpp>
00021 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
00022 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
00023 #include <boost/preprocessor/repetition/repeat.hpp>
00024
00025 namespace Cntm
00026 {
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 template <typename SignatureT>
00057 struct SignatureInfo
00058 {
00059 };
00060
00061
00062 template <typename ArgT>
00063 struct SignatureArgInfo
00064 {
00065 typedef ArgT StoreType;
00066 };
00067
00068
00069 template <typename ArgT>
00070 struct SignatureArgInfo<ArgT&>
00071 {
00072
00073 typedef ArgT StoreType;
00074 };
00075
00076
00077 template <typename ArgT>
00078 struct SignatureArgInfo<const ArgT&>
00079 {
00080
00081 typedef ArgT StoreType;
00082 };
00083
00084
00085 template <typename ArgT>
00086 struct SignatureArgInfo<volatile ArgT&>
00087 {
00088
00089 typedef ArgT StoreType;
00090 };
00091
00092
00093 template <typename ArgT>
00094 struct SignatureArgInfo<const volatile ArgT&>
00095 {
00096
00097 typedef ArgT StoreType;
00098 };
00099
00100
00101 template <typename ResT>
00102 struct SignatureResult
00103 {
00104 static const bool noVoid = true;
00105
00106 ResT res;
00107
00108 SignatureResult(const ResT& Src): res(Src) {}
00109
00110 operator ResT& () { return res; }
00111 };
00112
00113 template <>
00114 struct SignatureResult<void>
00115 {
00116 static const bool noVoid = false;
00117 };
00118
00119
00120 #define CNTM_SIGNATURES_MAX_ARGS 17
00121
00122 #define CNTM_SIGNATURES_EMPTY
00123
00124
00125 #define CNTM_SIGNATURES_COMMON_INFO_ARG(z, n, _) \
00126 typedef ArgT##n ArgType##n; \
00127 typedef typename SignatureArgInfo < ArgT##n > ::StoreType StoreType##n;
00128
00129
00130 #define CNTM_SIGNATURES_COMMON_INFO_ARGS_ARG(z, n, _) \
00131 StoreType##n arg##n;
00132
00133
00134 #define CNTM_SIGNATURES_COMMON_INFO_ARGS_CTOR_ARG(z, n, _) \
00135 arg##n(Arg##n)
00136
00137 #define CNTM_SIGNATURES_COMMON_INFO_ARGS_CTOR_TEMPL0(z, n)
00138
00139 #define CNTM_SIGNATURES_COMMON_INFO_ARGS_CTOR_TEMPL(z, n) \
00140 BOOST_PP_IF(n, template <, CNTM_SIGNATURES_EMPTY) \
00141 BOOST_PP_ENUM_PARAMS_Z(z, n, typename SrcArgT) \
00142 BOOST_PP_IF(n, >, CNTM_SIGNATURES_EMPTY)
00143
00144
00145 #define CNTM_SIGNATURES_COMMON_INFO(z, n, _) \
00146 static const int argsCount = n; \
00147 typedef ResT (FuncSign)(BOOST_PP_ENUM_PARAMS_Z(z, n, ArgT)); \
00148 typedef SignatureInfo < FuncSign > FuncInfo; \
00149 typedef ResT ResType; \
00150 typedef SignatureResult < ResT > ResultStoreType; \
00151 BOOST_PP_REPEAT(n, CNTM_SIGNATURES_COMMON_INFO_ARG, CNTM_SIGNATURES_EMPTY) \
00152 template < typename ClassForMethodT > \
00153 struct Method \
00154 { \
00155 typedef ResT (ClassForMethodT::*Pointer)(BOOST_PP_ENUM_PARAMS_Z(z, n, ArgT)); \
00156 }; \
00157 struct Args \
00158 { \
00159 BOOST_PP_REPEAT_##z(n, CNTM_SIGNATURES_COMMON_INFO_ARGS_ARG, CNTM_SIGNATURES_EMPTY) \
00160 CNTM_SIGNATURES_COMMON_INFO_ARGS_CTOR_TEMPL(z, n) \
00161 Args(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, const SrcArgT, & Arg)) \
00162 BOOST_PP_IF(n, :, CNTM_SIGNATURES_EMPTY) \
00163 BOOST_PP_ENUM_##z(n, CNTM_SIGNATURES_COMMON_INFO_ARGS_CTOR_ARG, CNTM_SIGNATURES_EMPTY) {} \
00164 }; \
00165 private: \
00166 template < typename ClassForMethodT > \
00167 static ResultStoreType MethodCallImpl(SignatureResult<void>* VoidCast, ClassForMethodT* Object, \
00168 typename Method < ClassForMethodT > ::Pointer Method, Args* Args) \
00169 { \
00170 (Object->*Method)(BOOST_PP_ENUM_PARAMS_Z(z, n, Args->arg)); \
00171 return ResultStoreType(); \
00172 } \
00173 template < typename MethodResT, typename ClassForMethodT > \
00174 static ResultStoreType MethodCallImpl(SignatureResult<MethodResT>* NoVoidCast, ClassForMethodT* Object, \
00175 typename Method < ClassForMethodT > ::Pointer Method, Args* Args) \
00176 { \
00177 return (Object->*Method)(BOOST_PP_ENUM_PARAMS_Z(z, n, Args->arg)); \
00178 } \
00179 public: \
00180 template < typename ClassForMethodT > \
00181 static ResultStoreType MethodCall(ClassForMethodT* Object, \
00182 typename Method < ClassForMethodT > ::Pointer Method, Args* Args) \
00183 { \
00184 return MethodCallImpl((SignatureResult<ResType>*)NULL, Object, Method, Args); \
00185 } \
00186 template < typename ClassForMethodT > \
00187 static ResType MethodExec(ClassForMethodT* Object, \
00188 typename Method < ClassForMethodT > ::Pointer Method, Args* Args) \
00189 { \
00190 return (Object->*Method)(BOOST_PP_ENUM_PARAMS_Z(z, n, Args->arg)); \
00191 } \
00192 static ResType FuncExec(FuncSign* Function, Args* Args) \
00193 { \
00194 return (*Function)(BOOST_PP_ENUM_PARAMS_Z(z, n, Args->arg)); \
00195 }
00196
00197
00198 #define CNTM_SIGNATURES_FUNC_INFO(z, n, _) \
00199 template < typename ResT BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename ArgT) > \
00200 struct SignatureInfo < ResT (BOOST_PP_ENUM_PARAMS_Z(z, n, ArgT)) > \
00201 { \
00202 CNTM_SIGNATURES_COMMON_INFO(z, n, CNTM_SIGNATURES_EMPTY) \
00203 static const bool isMethod = false; \
00204 struct ClassType {}; \
00205 typedef FuncSign* Pointer; \
00206 static ResType Exec(ClassType* Object, Pointer Procedure, Args* Args) \
00207 { \
00208 return FuncExec(Procedure, Args); \
00209 } \
00210 };
00211
00212 #define CNTM_SIGNATURES_PFUNC_INFO(z, n, _) \
00213 template < typename ResT BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename ArgT) > \
00214 struct SignatureInfo < ResT (*)(BOOST_PP_ENUM_PARAMS_Z(z, n, ArgT)) > \
00215 { \
00216 CNTM_SIGNATURES_COMMON_INFO(z, n, CNTM_SIGNATURES_EMPTY) \
00217 static const bool isMethod = false; \
00218 struct ClassType {}; \
00219 typedef FuncSign* Pointer; \
00220 static ResType Exec(ClassType* Object, Pointer Procedure, Args* Args) \
00221 { \
00222 return FuncExec(Procedure, Args); \
00223 } \
00224 };
00225
00226 #define CNTM_SIGNATURES_METHOD_INFO(z, n, _) \
00227 template < typename ResT, typename ClassT BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename ArgT) > \
00228 struct SignatureInfo < ResT (ClassT::*)(BOOST_PP_ENUM_PARAMS_Z(z, n, ArgT)) > \
00229 { \
00230 CNTM_SIGNATURES_COMMON_INFO(z, n, CNTM_SIGNATURES_EMPTY) \
00231 static const bool isMethod = true; \
00232 typedef ClassT ClassType; \
00233 typedef typename Method < ClassT > ::Pointer Pointer; \
00234 static ResType Exec(ClassType* Object, Pointer Procedure, Args* Args) \
00235 { \
00236 return MethodExec(Object, Procedure, Args); \
00237 } \
00238 };
00239
00240 template <typename SignatureT>
00241 struct SignatureInfo;
00242
00243 BOOST_PP_REPEAT(CNTM_SIGNATURES_MAX_ARGS, CNTM_SIGNATURES_FUNC_INFO, CNTM_SIGNATURES_EMPTY)
00244
00245 BOOST_PP_REPEAT(CNTM_SIGNATURES_MAX_ARGS, CNTM_SIGNATURES_PFUNC_INFO, CNTM_SIGNATURES_EMPTY)
00246
00247 BOOST_PP_REPEAT(CNTM_SIGNATURES_MAX_ARGS, CNTM_SIGNATURES_METHOD_INFO, CNTM_SIGNATURES_EMPTY)
00248
00249 }
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 #endif //CNTM_SIGNATUREINFO_H