Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47891-01

coherence/lang/TypedMethod.hpp

00001 /*
00002 * TypedMethod.hpp
00003 *
00004 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
00005 *
00006 * Oracle is a registered trademarks of Oracle Corporation and/or its
00007 * affiliates.
00008 *
00009 * This software is the confidential and proprietary information of Oracle
00010 * Corporation. You shall not disclose such confidential and proprietary
00011 * information and shall use it only in accordance with the terms of the
00012 * license agreement you entered into with Oracle.
00013 *
00014 * This notice may not be removed or altered.
00015 */
00016 #ifndef COH_TYPED_METHOD_HPP
00017 #define COH_TYPED_METHOD_HPP
00018 
00019 #include "coherence/lang/compatibility.hpp"
00020 
00021 #include "coherence/lang/BoxHandle.hpp"
00022 #include "coherence/lang/IllegalArgumentException.hpp"
00023 #include "coherence/lang/Method.hpp"
00024 #include "coherence/lang/SystemClassLoader.hpp"
00025 #include "coherence/lang/class_spec.hpp"
00026 
00027 #include "coherence/lang/Boolean.hpp"
00028 #include "coherence/lang/Octet.hpp"
00029 #include "coherence/lang/Character16.hpp"
00030 #include "coherence/lang/Integer16.hpp"
00031 #include "coherence/lang/Integer32.hpp"
00032 #include "coherence/lang/Integer64.hpp"
00033 #include "coherence/lang/Size32.hpp"
00034 #include "coherence/lang/Size64.hpp"
00035 #include "coherence/lang/Float32.hpp"
00036 #include "coherence/lang/Float64.hpp"
00037 #include "coherence/lang/String.hpp"
00038 
00039 
00040 COH_OPEN_NAMESPACE2(coherence,lang)
00041 
00042 namespace
00043     {
00044     // ----- internal helpers -----------------------------------------------
00045 
00046     // the following templates are used by TypedMethod to produce specialized
00047     // variants of methods in order to account for "void" parameters
00048 
00049     /**
00050     * @internal
00051     */
00052     template<class T>
00053     class coh_TypedMethodHelper
00054         {
00055         public:
00056 
00057             /**
00058             * @internal
00059             */
00060             static Method::ClassView getMethodArgumentType();
00061 
00062             /**
00063             * @internal
00064             */
00065             static int32_t getMethodModifiers();
00066         };
00067 
00068     template<class T> Method::ClassView coh_TypedMethodHelper<T>::getMethodArgumentType()
00069         {
00070         return SystemClassLoader::getInstance()->loadByType(typeid(typename T::ValueType));
00071         }
00072 
00073     template<> Method::ClassView coh_TypedMethodHelper<void>::getMethodArgumentType()
00074         {
00075         return NULL;
00076         }
00077 
00078     template<class T> int32_t coh_TypedMethodHelper<T>::getMethodModifiers()
00079         {
00080         return Method::modifier_instance |
00081                      (constness<typename T::ValueType>::applied
00082                      ? Method::modifier_const
00083                      : Method::modifier_mutable);
00084         }
00085 
00086     template<> int32_t coh_TypedMethodHelper<void>::getMethodModifiers()
00087         {
00088         return Method::modifier_static;
00089         }
00090 
00091     /**
00092     * @internal
00093     */
00094     template<class H, class P, class R, class A1, class A2, class A3, class A4,
00095              class A5, class A6, class A7, class A8>
00096     class coh_invoker
00097         {
00098         public:
00099             static Object::Holder invoke(Object::Holder oh, P p, ObjectArray::View va)
00100                 {
00101                 COH_ENSURE_PARAM_RELATION(va->length, ==, 3);
00102                 return R((*cast<H>(oh).*(p))(cast<A1>(va[0]), cast<A2>(va[1]),
00103                         cast<A3>(va[2]), cast<A4>(va[3]), cast<A5>(va[4]),
00104                         cast<A6>(va[5]), cast<A7>(va[6]), cast<A8>(va[7])));
00105                 }
00106         };
00107     }
00108 
00109 /**
00110  * TypedMethod provides a template based implementation for building Methods
00111  * which delegate to member function pointers.
00112  *
00113  * Rather then making direct use of this class it is recommended to utilize
00114  * the following helper macros.  For each of these methods there are nine
00115  * variants suffixed 0..8 which indicate the number of arguments the method
00116  * takes.
00117  *
00118  * - COH_CONSTRUCTOR     defines a Method representing a constructor
00119  * - COH_METHOD          defines a Method representing an instance method
00120  * - COH_STATIC_METHOD   defines a Method representing a static method
00121  * - COH_MANAGED_METHOD  defines a Method representing an instance on a
00122  *                       Managed<> class
00123  *
00124  * - COH_OVERLOADED_CONSTRUCTOR    defines an overloaded constructor
00125  * - COH_OVERLOADED_METHOD         defines an overloaded instance method
00126  * - COH_OVERLOADED_STATIC_METHOD  defines an overloaded static method
00127  *
00128  * Additionally the following macros will create setter and getter Methods
00129  * for a "property".
00130  *
00131  * - COH_PROPERTY          defines setter/getter for a object property
00132  * - COH_BOX_PROPERTY      defines a setter/getter for a value type property
00133  * - COH_MANAGED_PROPERTY  defines a setter/getter for a value type on a
00134  *                         Managed<> class
00135  *
00136  * These macros output Method objects which can then be registered with
00137  * their corresponding Class object.  This registration can either be
00138  * performed as part of the Class registration, or it can be done in multiple
00139  * COH_REGISTER_METHOD blocks, allowing the Method definition to reside
00140  * next to the actual method implementation.
00141  *
00142  * @code
00143  * // Person.hpp
00144  * class Person
00145  *      : public class_spec<Person>
00146  *      {
00147  *      friend class factory<Person>;
00148  *
00149  *      protected:
00150  *          Person(String::View vsName = String::null_string, int32_t nAge = 0);
00151  *
00152  *      public:
00153  *          virtual void setName(String::View vsName);
00154  *          virtual String::View getName() const;
00155  *
00156  *          virtual void setAge(int32_t nAge);
00157  *          virtual int32_t getAge() const;
00158  *      ...
00159  *      };
00160  * @endcode
00161  *
00162  * @code
00163  * // Person.cpp - using single class registration block
00164  *
00165  * COH_REGISTER_CLASS(TypedClass<Person>::create()
00166  *      ->declare(COH_CONSTRUCTOR2(Person, String::View, BoxHandle<const Integer32>))
00167  *      ->declare(COH_PROPERTY(Person, Name, String::View))
00168  *      ->declare(COH_BOX_PROPERTY(Person, Age, Integer32::View));
00169  * @endcode
00170  *
00171  * @code
00172  * // Person.cpp - using multi method registration blocks
00173  *
00174  * COH_REGISTER_TYPED_CLASS(Person);
00175  *
00176  * Person::Person(String::View vsName, int32_t nAge)
00177  *    {
00178  *    ...
00179  *    }
00180  * COH_REGISTER_METHOD(Person, COH_CONSTRUCTOR2(Person, String::View, BoxHandle<const Integer32>));
00181  *
00182  * void Person::setName(String::View vsName)
00183  *     {
00184  *     ...
00185  *     }
00186  * COH_REGISTER_METHOD(Person, COH_METHOD1(void, Person::Handle, setName, String::View));
00187  *
00188  * String::View Person::getName() const
00189  *     {
00190  *     ...
00191  *     }
00192  * COH_REGISTER_METHOD(Person, COH_METHOD0(String::View, Person::View, getName));
00193  *
00194  * void Person::setAge(int32_t nAge)
00195  *     {
00196  *     ...
00197  *     }
00198  * COH_REGISTER_METHOD(Person, COH_METHOD1(void, Person::Handle, setName, BoxHandle<const Integer32>));
00199  *
00200  * int32_t Person::getAge() const
00201  *     {
00202  *     ...
00203  *     }
00204  * COH_REGISTER_METHOD(Person, COH_METHOD0(BoxHandle<const Integer32>, Person::View, getName));
00205  * @endcode
00206  *
00207  * @author mf 2011.02.28
00208  *
00209  * @since Coherence 3.7.1
00210  */
00211 template<class P, class R, class C, class H, P M,
00212     class A1 = void, class A2 = void, class A3 = void, class A4 = void,
00213     class A5 = void, class A6 = void, class A7 = void, class A8 = void>
00214 class TypedMethod
00215     : public class_spec<TypedMethod<P, R, C, H, M, A1, A2, A3, A4, A5, A6, A7, A8>,
00216           extends<Method> >
00217     {
00218     friend class factory<TypedMethod<P, R, C, H, M, A1, A2, A3, A4, A5, A6, A7, A8> >;
00219 
00220     // ----- constructors ---------------------------------------------------
00221 
00222     protected:
00223         /**
00224          * Construct a TypedMethod.
00225          *
00226          * @param vsName  the method name
00227          */
00228         TypedMethod(String::View vsName)
00229             : class_spec<TypedMethod<P, R, C, H, M, A1, A2, A3, A4, A5, A6, A7, A8>,
00230               extends<Method> >(vsName)
00231             {
00232             }
00233 
00234 
00235     // ----- Method interface -----------------------------------------------
00236 
00237     public:
00238         /**
00239          * {@inheritDoc}
00240          */
00241         virtual int32_t getModifiers() const
00242             {
00243             return coh_TypedMethodHelper<H>::getMethodModifiers();
00244             }
00245 
00246         /**
00247          * {@inheritDoc}
00248          */
00249         virtual ObjectArray::View getParameterTypes() const
00250             {
00251             ObjectArray::Handle ha =
00252                     typeid(A1) == typeid(void) ? ObjectArray::create(0)
00253                   : typeid(A2) == typeid(void) ? ObjectArray::create(1)
00254                   : typeid(A3) == typeid(void) ? ObjectArray::create(2)
00255                   : typeid(A4) == typeid(void) ? ObjectArray::create(3)
00256                   : typeid(A5) == typeid(void) ? ObjectArray::create(4)
00257                   : typeid(A6) == typeid(void) ? ObjectArray::create(5)
00258                   : typeid(A7) == typeid(void) ? ObjectArray::create(6)
00259                   : typeid(A8) == typeid(void) ? ObjectArray::create(7)
00260                   :                              ObjectArray::create(8);
00261 
00262             switch (ha->length)
00263                 {
00264                 case 8:
00265                     ha[7] = coh_TypedMethodHelper<A8>::getMethodArgumentType();
00266                 case 7:
00267                     ha[6] = coh_TypedMethodHelper<A7>::getMethodArgumentType();
00268                 case 6:
00269                     ha[5] = coh_TypedMethodHelper<A6>::getMethodArgumentType();
00270                 case 5:
00271                     ha[4] = coh_TypedMethodHelper<A5>::getMethodArgumentType();
00272                 case 4:
00273                     ha[3] = coh_TypedMethodHelper<A4>::getMethodArgumentType();
00274                 case 3:
00275                     ha[2] = coh_TypedMethodHelper<A3>::getMethodArgumentType();
00276                 case 2:
00277                     ha[1] = coh_TypedMethodHelper<A2>::getMethodArgumentType();
00278                 case 1:
00279                     ha[0] = coh_TypedMethodHelper<A1>::getMethodArgumentType();
00280                 case 0:
00281                     break;
00282                 default:
00283                     coh_throw_illegal_state("unsupported method parameter count");
00284                 }
00285 
00286             return ha;
00287             }
00288 
00289         /**
00290          * {@inheritDoc}
00291          */
00292         virtual Method::ClassView getReturnType() const
00293             {
00294             return coh_TypedMethodHelper<R>::getMethodArgumentType();
00295             }
00296 
00297         /**
00298          * {@inheritDoc}
00299          */
00300         virtual Method::ClassView getDeclaringClass() const
00301             {
00302             return SystemClassLoader::getInstance()->loadByType(typeid(C));
00303             }
00304 
00305         /**
00306          * {@inheritDoc}
00307          */
00308         virtual Object::Holder invoke(Object::Holder oh, ObjectArray::View vaArgs) const
00309             {
00310             if (typeid(H) == typeid(void) && oh != NULL &&
00311                     !instanceof<typename C::View>(oh))
00312                 {
00313                 coh_throw_illegal_argument("oh must be NULL or of correct type");
00314                 }
00315             return coh_invoker<H, P, R, A1, A2, A3, A4, A5, A6, A7, A8>::invoke(oh, M, vaArgs);
00316             }
00317     };
00318 
00319 // ----- coh_invoker specializations ----------------------------------------
00320 
00321 namespace
00322     {
00323     // the following macros create specialized variants of the coh_invoker in
00324     // order to support 1-7 parameters
00325     #define COH_INVOKER(N, HH, RR, AA1, AA2, AA3, AA4, AA5, AA6, AA7, AA8, EXEC) \
00326         class coh_invoker<HH, P, RR, AA1, AA2, AA3, AA4, AA5, AA6, AA7, AA8> \
00327             { \
00328             public: \
00329                 static Object::Holder invoke(Object::Holder oh, P p, ObjectArray::View va) \
00330                     { \
00331                     if (!(N == 0 && va == NULL)) \
00332                         { \
00333                         COH_ENSURE_PARAM_RELATION(va->length, ==, N); \
00334                         } \
00335                     Object::Holder ohSunProWantsItToGetUsed = oh; \
00336                     Object::Holder r; \
00337                     EXEC; \
00338                     return r; \
00339                     } \
00340             }
00341 
00342     #define COH_A0
00343     #define COH_A1 COH_A0, class A1
00344     #define COH_A2 COH_A1, class A2
00345     #define COH_A3 COH_A2, class A3
00346     #define COH_A4 COH_A3, class A4
00347     #define COH_A5 COH_A4, class A5
00348     #define COH_A6 COH_A5, class A6
00349     #define COH_A7 COH_A6, class A7
00350 
00351     #define COH_DEF_METHOD_TEMPLATE(N, RT) template<class H, class P, class RT COH_A##N>
00352     #define COH_DEF_METHOD_TEMPLATE_VOID(N) template<class H, class P COH_A##N>
00353     #define COH_DEF_STATIC_METHOD_TEMPLATE(N, RT) template<class P, class RT COH_A##N>
00354     #define COH_DEF_STATIC_METHOD_TEMPLATE_VOID(N) template<class P COH_A##N>
00355 
00356     #define COH_DEF_ARGS0
00357     #define COH_DEF_ARGS1 COH_DEF_ARGS0  cast<A1>(va[0])
00358     #define COH_DEF_ARGS2 COH_DEF_ARGS1, cast<A2>(va[1])
00359     #define COH_DEF_ARGS3 COH_DEF_ARGS2, cast<A3>(va[2])
00360     #define COH_DEF_ARGS4 COH_DEF_ARGS3, cast<A4>(va[3])
00361     #define COH_DEF_ARGS5 COH_DEF_ARGS4, cast<A5>(va[4])
00362     #define COH_DEF_ARGS6 COH_DEF_ARGS5, cast<A6>(va[5])
00363     #define COH_DEF_ARGS7 COH_DEF_ARGS6, cast<A7>(va[6])
00364 
00365     #define COH_INSTANCE_METHOD *cast<H>(oh).*(p)
00366     #define COH_STATIC_METHOD *(p)
00367 
00368     #define COH_DEF_EXEC(N, MS, RS) RS((MS)(COH_DEF_ARGS##N));
00369 
00370     #define COH_DEF_INVOKER0(RT, HH, MS, RS) COH_INVOKER(0, HH, RT, void, void, void, void, void, void, void, void, COH_DEF_EXEC(0, MS, RS))
00371     #define COH_DEF_INVOKER1(RT, HH, MS, RS) COH_INVOKER(1, HH, RT, A1, void, void, void, void, void, void, void, COH_DEF_EXEC(1, MS, RS))
00372     #define COH_DEF_INVOKER2(RT, HH, MS, RS) COH_INVOKER(2, HH, RT, A1, A2, void, void, void, void, void, void, COH_DEF_EXEC(2, MS, RS))
00373     #define COH_DEF_INVOKER3(RT, HH, MS, RS) COH_INVOKER(3, HH, RT, A1, A2, A3, void, void, void, void, void, COH_DEF_EXEC(3, MS, RS))
00374     #define COH_DEF_INVOKER4(RT, HH, MS, RS) COH_INVOKER(4, HH, RT, A1, A2, A3, A4, void, void, void, void, COH_DEF_EXEC(4, MS, RS))
00375     #define COH_DEF_INVOKER5(RT, HH, MS, RS) COH_INVOKER(5, HH, RT, A1, A2, A3, A4, A5, void, void, void, COH_DEF_EXEC(5, MS, RS))
00376     #define COH_DEF_INVOKER6(RT, HH, MS, RS) COH_INVOKER(6, HH, RT, A1, A2, A3, A4, A5, A6, void, void, COH_DEF_EXEC(6, MS, RS))
00377     #define COH_DEF_INVOKER7(RT, HH, MS, RS) COH_INVOKER(7, HH, RT, A1, A2, A3, A4, A5, A6, A7, void, COH_DEF_EXEC(7, MS, RS))
00378 
00379     #define COH_DEF_METHOD(N) \
00380         COH_DEF_METHOD_TEMPLATE(N, R) COH_DEF_INVOKER##N(R, H, COH_INSTANCE_METHOD, r = R); \
00381         COH_DEF_METHOD_TEMPLATE_VOID(N) COH_DEF_INVOKER##N(void, H, COH_INSTANCE_METHOD, ;); \
00382         COH_DEF_STATIC_METHOD_TEMPLATE(N, R) COH_DEF_INVOKER##N(R, void, COH_STATIC_METHOD, r = R); \
00383         COH_DEF_STATIC_METHOD_TEMPLATE_VOID(N) COH_DEF_INVOKER##N(void, void, COH_STATIC_METHOD, ;)
00384 
00385     COH_DEF_METHOD(0);
00386     COH_DEF_METHOD(1);
00387     COH_DEF_METHOD(2);
00388     COH_DEF_METHOD(3);
00389     COH_DEF_METHOD(4);
00390     COH_DEF_METHOD(5);
00391     COH_DEF_METHOD(6);
00392     COH_DEF_METHOD(7);
00393 
00394     #undef COH_DEF_METHOD
00395     #undef COH_DEF_INVOKER0
00396     #undef COH_DEF_INVOKER1
00397     #undef COH_DEF_INVOKER2
00398     #undef COH_DEF_INVOKER3
00399     #undef COH_DEF_INVOKER4
00400     #undef COH_DEF_INVOKER5
00401     #undef COH_DEF_INVOKER6
00402     #undef COH_DEF_INVOKER7
00403     #undef COH_DEF_EXEC
00404     #undef COH_STATIC_METHOD
00405     #undef COH_INSTANCE_METHOD
00406 
00407     #undef COH_DEF_ARGS0
00408     #undef COH_DEF_ARGS1
00409     #undef COH_DEF_ARGS2
00410     #undef COH_DEF_ARGS3
00411     #undef COH_DEF_ARGS4
00412     #undef COH_DEF_ARGS5
00413     #undef COH_DEF_ARGS6
00414     #undef COH_DEF_ARGS7
00415 
00416     #undef COH_DEF_METHOD_TEMPLATE
00417     #undef COH_DEF_METHOD_TEMPLATE_VOID
00418     #undef COH_DEF_STATIC_METHOD_TEMPLATE
00419     #undef COH_DEF_STATIC_METHOD_TEMPLATE_VOID
00420 
00421     #undef COH_A0
00422     #undef COH_A1
00423     #undef COH_A2
00424     #undef COH_A3
00425     #undef COH_A4
00426     #undef COH_A5
00427     #undef COH_A6
00428     #undef COH_A7
00429 
00430     #undef COH_INVOKER
00431 
00432     /**
00433     * @internal
00434     */
00435     template<class C, class H>
00436     class coh_type_info
00437         {
00438         public: typedef H type;
00439         };
00440 
00441     /**
00442     * @internal
00443     */
00444     template<class C>
00445     class coh_type_info<C, BoxHandle<C> >
00446         {
00447         public: typedef typename C::BoxedType type;
00448         };
00449 
00450     /**
00451     * @internal
00452     */
00453     template<class C>
00454     class coh_type_info<C, BoxHandle<const C> >
00455         {
00456         public: typedef typename C::BoxedType type;
00457         };
00458 
00459     // for compilers (SunPro) which have trouble with the above partial
00460     // specializations we provide more specific versions
00461     #define COH_BOX_TYPE_INFO(T) \
00462         template<> \
00463         class coh_type_info<T, BoxHandle<T> > \
00464             { \
00465             public: typedef T::BoxedType type; \
00466             }; \
00467         template<> \
00468         class coh_type_info<const T, BoxHandle<const T> > \
00469             { \
00470             public: typedef T::BoxedType type; \
00471             }
00472 
00473     COH_BOX_TYPE_INFO(Boolean);
00474     COH_BOX_TYPE_INFO(Octet);
00475     COH_BOX_TYPE_INFO(Character16);
00476     COH_BOX_TYPE_INFO(Integer16);
00477     COH_BOX_TYPE_INFO(Integer32);
00478     COH_BOX_TYPE_INFO(Integer64);
00479     COH_BOX_TYPE_INFO(Size32);
00480     COH_BOX_TYPE_INFO(Size64);
00481     COH_BOX_TYPE_INFO(Float32);
00482     COH_BOX_TYPE_INFO(Float64);
00483     COH_BOX_TYPE_INFO(String);
00484 
00485     /**
00486     * @internal
00487     */
00488     template<class H>
00489     class coh_handle_info
00490         {
00491         public: typedef typename coh_type_info<typename H::ValueType, H>::type type;
00492         };
00493 
00494     /**
00495     * @internal
00496     */
00497     template<>
00498     class coh_handle_info<void>
00499         {
00500         public: typedef void type;
00501         };
00502     }
00503 
00504 // the following templates will compute a function pointer signature, similar
00505 // what the non-standard __typeof__ operator would do
00506 
00507 /**
00508 * @internal
00509 */
00510 template<int N, class R, class C, class H, class A1 = void, class A2 = void,
00511     class A3 = void, class A4 = void, class A5 = void,
00512     class A6 = void, class A7 = void, class A8 = void>
00513 class coh_signature_info \
00514     { \
00515     public: typedef void signature;
00516     };
00517 
00518 #define COH_SIG_INFON(N, RS, CS, HS, AS, TS) \
00519 template<class R, class C, class A1, class A2, \
00520     class A3, class A4, class A5, \
00521     class A6, class A7, class A8> \
00522 class coh_signature_info<N, R, C, HS, A1, A2, A3, A4, A5, A6, A7, A8> \
00523     { \
00524     public: typedef typename coh_handle_info<RS>::type (CS signature)AS TS \
00525     }
00526 
00527 
00528 #define COH_ARG_TYPE0
00529 #define COH_ARG_TYPE1 COH_ARG_TYPE0  typename coh_handle_info<A1>::type
00530 #define COH_ARG_TYPE2 COH_ARG_TYPE1, typename coh_handle_info<A2>::type
00531 #define COH_ARG_TYPE3 COH_ARG_TYPE2, typename coh_handle_info<A3>::type
00532 #define COH_ARG_TYPE4 COH_ARG_TYPE3, typename coh_handle_info<A4>::type
00533 #define COH_ARG_TYPE5 COH_ARG_TYPE4, typename coh_handle_info<A5>::type
00534 #define COH_ARG_TYPE6 COH_ARG_TYPE5, typename coh_handle_info<A6>::type
00535 #define COH_ARG_TYPE7 COH_ARG_TYPE6, typename coh_handle_info<A7>::type
00536 #define COH_ARG_TYPE8 COH_ARG_TYPE7, typename coh_handle_info<A8>::type
00537 
00538 #define COH_SIG_INFO(N) \
00539 COH_SIG_INFON(N, R,    *, void              ,(COH_ARG_TYPE##N), ;); \
00540 COH_SIG_INFON(N, R, C::*, typename C::Handle,(COH_ARG_TYPE##N), ;); \
00541 COH_SIG_INFON(N, R, C::*, typename C::View  ,(COH_ARG_TYPE##N), const;)
00542 
00543 COH_SIG_INFO(0);
00544 COH_SIG_INFO(1);
00545 COH_SIG_INFO(2);
00546 COH_SIG_INFO(3);
00547 COH_SIG_INFO(4);
00548 COH_SIG_INFO(5);
00549 COH_SIG_INFO(6);
00550 COH_SIG_INFO(7);
00551 COH_SIG_INFO(8);
00552 
00553 #undef COH_SIG_INFO
00554 #undef COH_SIG_INFON
00555 #undef COH_ARG_TYPE0
00556 #undef COH_ARG_TYPE1
00557 #undef COH_ARG_TYPE2
00558 #undef COH_ARG_TYPE3
00559 #undef COH_ARG_TYPE4
00560 #undef COH_ARG_TYPE5
00561 #undef COH_ARG_TYPE6
00562 #undef COH_ARG_TYPE7
00563 #undef COH_ARG_TYPE8
00564 
00565 COH_CLOSE_NAMESPACE2
00566 
00567 
00568 // ----- helper macros ------------------------------------------------------
00569 
00570 /**
00571  * Declare an overloaded static Method based on a description of its signature.
00572  *
00573  * This OVERLOADED macro is only necessary when a class or interface declares
00574  * multiple methods of the same name, otherwise the COH_DECLARE_STATIC_METHOD
00575  * is a better choice of macros.  An additional use case for this macro variant
00576  * is to handle the case where defining a static Method for a Managed<T> class
00577  * where the method is not actually declared on T, but on some super class of T.
00578  *
00579  * For both R, and A1..A8 the value should be a handle type, for instance
00580  * String::View or Map::Handle.  If the underlying method returns a value
00581  * type instead, then a BoxHandle<> needs to be supplied for the corresponding
00582  * Object type.  For instance BoxHandle<const Integer32> in place of int32_t.
00583  *
00584  * @param S       the method signature
00585  * @param R       the method return type
00586  * @param C       the target class to call on
00587  * @param M       the method name
00588  * @param A1..A8  the argument types
00589  */
00590 #define COH_OVERLOADED_STATIC_METHOD8(S, R, C, M, A1, A2, A3, A4, A5, A6, A7, A8) \
00591         coherence::lang::TypedMethod<S, \
00592                R, C, void, &C::M, A1, A2, A3, A4, A5, A6, A7, A8>::create(#M)
00593 #define COH_OVERLOADED_STATIC_METHOD7(S, R, C, M, A1, A2, A3, A4, A5, A6, A7) \
00594         COH_OVERLOADED_STATIC_METHOD8(S, R, C, M, A1, A2, A3, A4, A5, A6, A7, void)
00595 #define COH_OVERLOADED_STATIC_METHOD6(S, R, C, M, A1, A2, A3, A4, A5, A6) \
00596         COH_OVERLOADED_STATIC_METHOD7(S, R, C, M, A1, A2, A3, A4, A5, A6, void)
00597 #define COH_OVERLOADED_STATIC_METHOD5(S, R, C, M, A1, A2, A3, A4, A5) \
00598         COH_OVERLOADED_STATIC_METHOD6(S, R, C, M, A1, A2, A3, A4, A5, void)
00599 #define COH_OVERLOADED_STATIC_METHOD4(S, R, C, M, A1, A2, A3, A4) \
00600         COH_OVERLOADED_STATIC_METHOD5(S, R, C, M, A1, A2, A3, A4, void)
00601 #define COH_OVERLOADED_STATIC_METHOD3(S, R, C, M, A1, A2, A3) \
00602         COH_OVERLOADED_STATIC_METHOD4(S, R, C, M, A1, A2, A3, void)
00603 #define COH_OVERLOADED_STATIC_METHOD2(S, R, C, M, A1, A2) \
00604         COH_OVERLOADED_STATIC_METHOD3(S, R, C, M, A1, A2, void)
00605 #define COH_OVERLOADED_STATIC_METHOD1(S, R, C, M, A) \
00606         COH_OVERLOADED_STATIC_METHOD2(S, R, C, M, A, void)
00607 #define COH_OVERLOADED_STATIC_METHOD0(S, R, C, M) \
00608         COH_OVERLOADED_STATIC_METHOD1(S, R, C, M, void)
00609 
00610 /**
00611  * Declare a static Method based on a description of its signature.
00612  *
00613  * For both R, and A1..A8 the value should be a handle type, for instance
00614  * String::View or Map::Handle.  If the underlying method returns a value
00615  * type instead, then a BoxHandle<> needs to be supplied for the corresponding
00616  * Object type.  For instance BoxHandle<const Integer32> in place of in32_t.
00617  *
00618  * @param R       the method return type
00619  * @param H       the target handle type to call on
00620  * @param M       the method name
00621  * @param A1..A8  the argument types
00622  */
00623 #define COH_STATIC_METHOD(N, R, C, M, A1, A2, A3, A4, A5, A6, A7, A8) \
00624         coherence::lang::TypedMethod<coh_signature_info<N, R, C, void, A1, A2, \
00625             A3, A4, A5, A6, A7, A8>::signature, R, C, void, \
00626             &C::M, A1, A2, A3, A4, A5, A6, A7, A8>::create(#M)
00627 #define COH_STATIC_METHOD8(R, C, M, A1, A2, A3, A4, A5, A6, A7, A8) \
00628         COH_STATIC_METHOD(8, R, C, M, A1, A2, A3, A4, A5, A6, A7, A8)
00629 #define COH_STATIC_METHOD7(R, C, M, A1, A2, A3, A4, A5, A6, A7) \
00630         COH_STATIC_METHOD(7, R, C, M, A1, A2, A3, A4, A5, A6, A7, void)
00631 #define COH_STATIC_METHOD6(R, C, M, A1, A2, A3, A4, A5, A6) \
00632         COH_STATIC_METHOD(6, R, C, M, A1, A2, A3, A4, A5, A6, void, void)
00633 #define COH_STATIC_METHOD5(R, C, M, A1, A2, A3, A4, A5) \
00634         COH_STATIC_METHOD(5, R, C, M, A1, A2, A3, A4, A5, void, void, void)
00635 #define COH_STATIC_METHOD4(R, C, M, A1, A2, A3, A4) \
00636         COH_STATIC_METHOD(4, R, C, M, A1, A2, A3, A4, void, void, void, void)
00637 #define COH_STATIC_METHOD3(R, C, M, A1, A2, A3) \
00638         COH_STATIC_METHOD(3, R, C, M, A1, A2, A3, void, void, void, void, void)
00639 #define COH_STATIC_METHOD2(R, C, M, A1, A2) \
00640         COH_STATIC_METHOD(2, R, C, M, A1, A2, void, void, void, void, void, void)
00641 #define COH_STATIC_METHOD1(R, C, M, A) \
00642         COH_STATIC_METHOD(1, R, C, M, A, void, void, void, void, void, void, void)
00643 #define COH_STATIC_METHOD0(R, C, M) \
00644         COH_STATIC_METHOD(0, R, C, M, void, void, void, void, void, void, void, void)
00645 
00646 /**
00647  * Declare a constructor Method based on a description of its signature.
00648  *
00649  * For both R, and A1..A8 the value should be a handle type, for instance
00650  * String::View or Map::Handle.  If the underlying method returns a value
00651  * type instead, then a BoxHandle<> needs to be supplied for the corresponding
00652  * Object type.  For instance BoxHandle<const Integer32> in place of in32_t.
00653  *
00654  * @param R       the method return type
00655  * @param H       the target handle type to call on
00656  * @param M       the method name
00657  * @param A1..A8  the argument types
00658  */
00659 #define COH_CONSTRUCTOR8(C, A1, A2, A3, A4, A5, A6, A7, A8) \
00660         COH_OVERLOADED_STATIC_METHOD8(C::Handle (*)(const A1&, const A2&, \
00661             const A3&, const A4&, const A5&, const A6&, const A7&, const A8&), \
00662             C::Handle, C, create, A1, A2, A3, A4, A5, A6, A7, A8)
00663 #define COH_CONSTRUCTOR7(C, A1, A2, A3, A4, A5, A6, A7) \
00664         COH_OVERLOADED_STATIC_METHOD7(C::Handle (*)(const A1&, const A2&, \
00665             const A3&, const A4&, const A5&, const A6&, const A7&), \
00666             C::Handle, C, create, A1, A2, A3, A4, A5, A6, A7)
00667 #define COH_CONSTRUCTOR6(C, A1, A2, A3, A4, A5, A6) \
00668         COH_OVERLOADED_STATIC_METHOD6(C::Handle (*)(const A1&, const A2&, \
00669             const A3&, const A4&, const A5&, const A6&), \
00670             C::Handle, C, create, A1, A2, A3, A4, A5, A6)
00671 #define COH_CONSTRUCTOR5(C, A1, A2, A3, A4, A5) \
00672         COH_OVERLOADED_STATIC_METHOD5(C::Handle (*)(const A1&, const A2&, \
00673             const A3&, const A4&, const A5&), \
00674             C::Handle, C, create, A1, A2, A3, A4, A5)
00675 #define COH_CONSTRUCTOR4(C, A1, A2, A3, A4) \
00676         COH_OVERLOADED_STATIC_METHOD4(C::Handle (*)(const A1&, const A2&, \
00677             const A3&, const A4&), \
00678             C::Handle, C, create, A1, A2, A3, A4)
00679 #define COH_CONSTRUCTOR3(C, A1, A2, A3) \
00680         COH_OVERLOADED_STATIC_METHOD3(C::Handle (*)(const A1&, const A2&, \
00681             const A3&), \
00682             C::Handle, C, create, A1, A2, A3)
00683 #define COH_CONSTRUCTOR2(C, A1, A2) \
00684         COH_OVERLOADED_STATIC_METHOD2(C::Handle (*)(const A1&, const A2&), \
00685             C::Handle, C, create, A1, A2)
00686 #define COH_CONSTRUCTOR1(C, A1) \
00687         COH_OVERLOADED_STATIC_METHOD1(C::Handle (*)(const A1&), \
00688             C::Handle, C, create, A1)
00689 #define COH_CONSTRUCTOR0(C) \
00690         COH_OVERLOADED_STATIC_METHOD1(C::Handle (*)(), C::Handle, C, create)
00691 
00692 /**
00693  * Declare an overloaded Method based on a description of its signature.
00694  *
00695  * This OVERLOADED macro is only necessary when a class or interface declares
00696  * multiple methods of the same name, otherwise the COH_DECLARE_METHOD is
00697  * a better choice of macros.
00698  *
00699  * For both R, and A1..A8 the value should be a handle type, for instance
00700  * String::View or Map::Handle.  If the underlying method returns a value
00701  * type instead, then a BoxHandle<> needs to be supplied for the corresponding
00702  * Object type.  For instance BoxHandle<const Integer32> in place of int32_t.
00703  *
00704  * @param S       the method signature
00705  * @param R       the method return type
00706  * @param H       the target handle type to call on
00707  * @param M       the method name
00708  * @param A1..A8  the argument types
00709  */
00710 #define COH_OVERLOADED_METHOD8(S, R, H, M, A1, A2, A3, A4, A5, A6, A7, A8) \
00711         coherence::lang::TypedMethod<S, \
00712                R, H::ValueType, H, &H::ValueType::M, A1, A2, A3, A4, A5, A6, A7, A8>::create(#M)
00713 #define COH_OVERLOADED_METHOD7(S, R, H, M, A1, A2, A3, A4, A5, A6, A7) \
00714         COH_OVERLOADED_METHOD8(S, R, H, M, A1, A2, A3, A4, A5, A6, A7, void)
00715 #define COH_OVERLOADED_METHOD6(S, R, H, M, A1, A2, A3, A4, A5, A6) \
00716         COH_OVERLOADED_METHOD7(S, R, H, M, A1, A2, A3, A4, A5, A6, void)
00717 #define COH_OVERLOADED_METHOD5(S, R, H, M, A1, A2, A3, A4, A5) \
00718         COH_OVERLOADED_METHOD6(S, R, H, M, A1, A2, A3, A4, A5, void)
00719 #define COH_OVERLOADED_METHOD4(S, R, H, M, A1, A2, A3, A4) \
00720         COH_OVERLOADED_METHOD5(S, R, H, M, A1, A2, A3, A4, void)
00721 #define COH_OVERLOADED_METHOD3(S, R, H, M, A1, A2, A3) \
00722         COH_OVERLOADED_METHOD4(S, R, H, M, A1, A2, A3, void)
00723 #define COH_OVERLOADED_METHOD2(S, R, H, M, A1, A2) \
00724         COH_OVERLOADED_METHOD3(S, R, H, M, A1, A2, void)
00725 #define COH_OVERLOADED_METHOD1(S, R, H, M, A) \
00726         COH_OVERLOADED_METHOD2(S, R, H, M, A, void)
00727 #define COH_OVERLOADED_METHOD0(S, R, H, M) \
00728         COH_OVERLOADED_METHOD1(S, R, H, M, void)
00729 
00730 /**
00731  * Declare a Method based on a description of its signature.
00732  *
00733  * For both R, and A1..A8 the value should be a handle type, for instance
00734  * String::View or Map::Handle.  If the underlying method returns a value
00735  * type instead, then a BoxHandle<> needs to be supplied for the corresponding
00736  * Object type.  For instance BoxHandle<const Integer32> in place of in32_t.
00737  *
00738  * @param R       the method return type
00739  * @param H       the target handle type to call on
00740  * @param M       the method name
00741  * @param A1..A8  the argument types
00742  */
00743 #define COH_METHOD(N, R, H, M, A1, A2, A3, A4, A5, A6, A7, A8) \
00744         coherence::lang::TypedMethod<coh_signature_info<N, R, H::ValueType, H, A1, A2, \
00745             A3, A4, A5, A6, A7, A8>::signature, R, H::ValueType, H, \
00746             &H::ValueType::M, A1, A2, A3, A4, A5, A6, A7, A8>::create(#M)
00747 #define COH_METHOD8(R, H, M, A1, A2, A3, A4, A5, A6, A7, A8) \
00748         COH_METHOD(8, R, H, M, A1, A2, A3, A4, A5, A6, A7, A8)
00749 #define COH_METHOD7(R, H, M, A1, A2, A3, A4, A5, A6, A7) \
00750         COH_METHOD(7, R, H, M, A1, A2, A3, A4, A5, A6, A7, void)
00751 #define COH_METHOD6(R, H, M, A1, A2, A3, A4, A5, A6) \
00752         COH_METHOD(6, R, H, M, A1, A2, A3, A4, A5, A6, void, void)
00753 #define COH_METHOD5(R, H, M, A1, A2, A3, A4, A5) \
00754         COH_METHOD(5, R, H, M, A1, A2, A3, A4, A5, void, void, void)
00755 #define COH_METHOD4(R, H, M, A1, A2, A3, A4) \
00756         COH_METHOD(4, R, H, M, A1, A2, A3, A4, void, void, void, void)
00757 #define COH_METHOD3(R, H, M, A1, A2, A3) \
00758         COH_METHOD(3, R, H, M, A1, A2, A3, void, void, void, void, void)
00759 #define COH_METHOD2(R, H, M, A1, A2) \
00760         COH_METHOD(2, R, H, M, A1, A2, void, void, void, void, void, void)
00761 #define COH_METHOD1(R, H, M, A) \
00762         COH_METHOD(1, R, H, M, A, void, void, void, void, void, void, void)
00763 #define COH_METHOD0(R, H, M) \
00764         COH_METHOD(0, R, H, M, void, void, void, void, void, void, void, void)
00765 
00766 /**
00767  * Declare a Method for a Managed<> class based on a description of its
00768  * signature.
00769  *
00770  * For both R, and A1..A8 the value should be a handle type, for instance
00771  * String::View or Map::Handle.  If the underlying method returns a value
00772  * type instead, then a BoxHandle<> needs to be supplied for the corresponding
00773  * Object type.  For instance BoxHandle<const Integer32> in place of in32_t.
00774  *
00775  * @param S       the method signature
00776  * @param R       the method return type
00777  * @param H       the target handle type to call on
00778  * @param M       the method name
00779  * @param A1..A8  the argument types
00780  */
00781 #define COH_MANAGED_METHOD8(S, R, H, M, A1, A2, A3, A4, A5, A6, A7, A8) \
00782         coherence::lang::TypedMethod<S, R, H::ValueType, H, \
00783             &H::ValueType::BoxedType::M, A1, A2, A3, A4, A5, A6, A7, A8>::create(#M)
00784 #define COH_MANAGED_METHOD7(S, R, H, M, A1, A2, A3, A4, A5, A6, A7) \
00785         COH_MANAGED_METHOD8(S, R, H, M, A1, A2, A3, A4, A5, A6, A7, void)
00786 #define COH_MANAGED_METHOD6(S, R, H, M, A1, A2, A3, A4, A5, A6) \
00787         COH_MANAGED_METHOD7(S, R, H, M, A1, A2, A3, A4, A5, A6, void)
00788 #define COH_MANAGED_METHOD5(S, R, H, M, A1, A2, A3, A4, A5) \
00789         COH_MANAGED_METHOD6(S, R, H, M, A1, A2, A3, A4, A5, void)
00790 #define COH_MANAGED_METHOD4(S, R, H, M, A1, A2, A3, A4) \
00791         COH_MANAGED_METHOD5(S, R, H, M, A1, A2, A3, A4, void)
00792 #define COH_MANAGED_METHOD3(S, R, H, M, A1, A2, A3) \
00793         COH_MANAGED_METHOD4(S, R, H, M, A1, A2, A3, void)
00794 #define COH_MANAGED_METHOD2(S, R, H, M, A1, A2) \
00795         COH_MANAGED_METHOD3(S, R, H, M, A1, A2, void)
00796 #define COH_MANAGED_METHOD1(S, R, H, M, A) \
00797         COH_MANAGED_METHOD2(S, R, H, M, A, void)
00798 #define COH_MANAGED_METHOD0(S, R, H, M) \
00799         COH_MANAGED_METHOD1(S, R, H, M, void)
00800 
00801 /**
00802 * Helper macro for creating getter and setter methods for a property.
00803 *
00804 * @param C  the class to call the method on, i.e. Address
00805 * @param P  the property to access, i.e. State
00806 * @param V  the return object type, i.e. String::View
00807 */
00808 #define COH_PROPERTY(C, P, V) \
00809         COH_METHOD0(V, C::View, get##P)) \
00810       ->declare(COH_METHOD1(void, C::Handle, set##P, V)
00811 
00812 /**
00813 * Helper macro for creating getter and setter methods for a boxable property.
00814 *
00815 * @param C  the class to call the method on, i.e. Address
00816 * @param P  the property to access, i.e. State
00817 * @param V  the return object type, i.e. String::View
00818 */
00819 #define COH_BOX_PROPERTY(C, P, V) \
00820         COH_METHOD0(coherence::lang::BoxHandle<V::ValueType >, C::View, get##P)) \
00821       ->declare(COH_METHOD1(void, C::Handle, set##P, coherence::lang::BoxHandle<V::ValueType >)
00822 
00823 /**
00824 * Helper macro for creating getter and setter methods for a boxable property
00825 * on a Managed<> object.
00826 *
00827 * @param C  the class to call the method on, i.e. Address
00828 * @param P  the property to access, i.e. Zip
00829 * @param V  the return object type, i.e. Integer32::View
00830 */
00831 #define COH_MANAGED_PROPERTY(C, P, V) \
00832         COH_MANAGED_METHOD0(V::ValueType::BoxedType (C::*)() const, coherence::lang::BoxHandle<V::ValueType >, coherence::lang::Managed<C >::View, get##P)) \
00833       ->declare(COH_MANAGED_METHOD1(void (C::*)(V::ValueType::BoxedType), void, coherence::lang::Managed<C >::Handle, set##P, coherence::lang::BoxHandle<V::ValueType >)
00834 
00835 #endif // COH_TYPED_METHOD_HPP
Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.