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

E26041-01

coherence/lang/lang_spec.hpp

00001 /*
00002 * lang_spec.hpp
00003 *
00004 * Copyright (c) 2000, 2013, 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_LANG_SPEC_HPP
00017 #define COH_LANG_SPEC_HPP
00018 
00019 #include "coherence/lang/compatibility.hpp"
00020 
00021 #include "coherence/lang/TypedHandle.hpp"
00022 #include "coherence/lang/TypedHolder.hpp"
00023 
00024 COH_OPEN_NAMESPACE2(coherence,lang)
00025 
00026 class Object;
00027 
00028 /**
00029 * @internal
00030 *
00031 * Definition of terminal class identifier.
00032 */
00033 template<class T = void> class COH_EXPORT_SPEC Void
00034     {
00035     protected:
00036         virtual ~Void()
00037             {}
00038 
00039     public:
00040         /**
00041         * @internal
00042         *
00043         * Perform an optimistic cast from this type to the specified
00044         * type.  This method is for use by the cast<T> operator.
00045         *
00046         * As this is an optimistic test it may produce false negatives, but
00047         * not false positives.  A negative result should be followed up with a
00048         * dynamic_cast.
00049         *
00050         * @param pInfo  the type to cast to
00051         *
00052         * @return NULL on failure, else the cast'd value represented as a
00053         *         void* which is suitable for direct casting to the
00054         *         corresponding type.
00055         */
00056         virtual void* _cast(const std::type_info* /*pInfo*/) const
00057             {
00058             return NULL;
00059             }
00060 
00061         /**
00062         * @internal
00063         */
00064         virtual size64_t sizeOf(bool /*fDeep*/ = false) const
00065             {
00066             return 0;
00067             }
00068     };
00069 
00070 /**
00071 * @internal
00072 *
00073 * Definition of class alias, used in Exceptions.
00074 */
00075 template<class T> class Alias
00076     {
00077     public:
00078         typedef typename T::alias alias;
00079     };
00080 
00081 /**
00082 * @internal
00083 *
00084 * Terminal Alias.
00085 */
00086 template<> class Alias<Void<> >
00087     {
00088     public:
00089         typedef Void<> alias;
00090     };
00091 
00092 /**
00093 * @internal
00094 *
00095 * Object Alias.
00096 */
00097 template<> class Alias<Object>
00098     {
00099     public:
00100         typedef Void<Object> alias;
00101     };
00102 
00103 
00104 /**
00105 * @internal
00106 *
00107 * Definition of individual link in chain of implemented interfaces.
00108 *
00109 * @see implements
00110 *
00111 * @author mf 2008.07.14
00112 */
00113 template<class I, class N> class COH_EXPORT_SPEC interface_link
00114     : public virtual I, public virtual N
00115     {
00116     public:
00117         /**
00118         * @internal
00119         *
00120         * Perform an optimistic cast from this type to the specified
00121         * type.  Unlike the virtual _cast which is part of class_specs,
00122         * _icast handles interfaces, and is called only by _cast and thus
00123         * doesn't need to be virtual.
00124         *
00125         * As this is an optimistic test it may produce false negatives, but
00126         * not false positives.  A negative result should be followed up with a
00127         * dynamic_cast.
00128         *
00129         * @param pInfo  the type to cast to
00130         *
00131         * @return NULL on failure, else the cast'd value represented as a
00132         *         void* which is suitable for direct casting to the
00133         *         corresponding type.
00134         */
00135         void* _icast(const std::type_info* pInfo) const
00136             {
00137             // Perform an optimistic cast, walking across the interface links
00138             // comparing type_infos by address. This is a shallow traversal
00139             // avoiding nested interfaces.
00140             static const std::type_info* pInfoThis = &typeid(I);
00141             return pInfoThis == pInfo
00142                 ? (void*) static_cast<const I*>(this)
00143                 : N::_icast(pInfo);
00144             }
00145     };
00146 
00147 /**
00148 * @internal
00149 *
00150 * Terminal interface_link
00151 */
00152 template<class I> class COH_EXPORT_SPEC interface_link<void, I>
00153     {
00154     public:
00155     void* _icast(const std::type_info* /*pInfo*/) const
00156         {
00157         return NULL;
00158         }
00159     };
00160 
00161 
00162 /**
00163 * The implements template specifies a list of interfaces which a class or
00164 * interface specification derives from.  Each interface will be virtually
00165 * inherited by specified class or interface. Up to sixteen interfaces are
00166 * supported, in the case where more are required, they can be specified using
00167 * an interface_link<I> chain.  i.e.
00168 *
00169 * @code
00170 * implements<I1, ..., I15, interface_link<I16, interface_link<I17> > >
00171 * @endcode
00172 *
00173 * @see abstract_spec
00174 * @see class_spec
00175 * @see cloneable_spec
00176 * @see throwable_spec
00177 * @see interface_spec
00178 *
00179 * @author mf 2008.07.14
00180 */
00181 template<class I1  = void,
00182          class I2  = void,
00183          class I3  = void,
00184          class I4  = void,
00185          class I5  = void,
00186          class I6  = void,
00187          class I7  = void,
00188          class I8  = void,
00189          class I9  = void,
00190          class I10 = void,
00191          class I11 = void,
00192          class I12 = void,
00193          class I13 = void,
00194          class I14 = void,
00195          class I15 = void,
00196          class I16 = void>
00197 class COH_EXPORT_SPEC implements
00198     {
00199     public:
00200         typedef interface_link<I1,
00201                 interface_link<I2,
00202                 interface_link<I3,
00203                 interface_link<I4,
00204                 interface_link<I5,
00205                 interface_link<I6,
00206                 interface_link<I7,
00207                 interface_link<I8,
00208                 interface_link<I9,
00209                 interface_link<I10,
00210                 interface_link<I11,
00211                 interface_link<I12,
00212                 interface_link<I13,
00213                 interface_link<I14,
00214                 interface_link<I15,
00215                 interface_link<I16,
00216                 void > > > > > > > > > > > > > > > >
00217         implements_chain;
00218 
00219         typedef I1  interface_1;
00220         typedef I2  interface_2;
00221         typedef I3  interface_3;
00222         typedef I4  interface_4;
00223         typedef I5  interface_5;
00224         typedef I6  interface_6;
00225         typedef I7  interface_7;
00226         typedef I8  interface_8;
00227         typedef I9  interface_9;
00228         typedef I10 interface_10;
00229         typedef I11 interface_11;
00230         typedef I12 interface_12;
00231         typedef I13 interface_13;
00232         typedef I14 interface_14;
00233         typedef I15 interface_15;
00234         typedef I16 interface_16;
00235     };
00236 
00237 /**
00238 * The extends template indicates the parent class in a class specification.
00239 *
00240 * @see abstract_spec
00241 * @see class_spec
00242 * @see cloneable_spec
00243 * @see throwable_spec
00244 *
00245 * @author mf 2008.07.14
00246 */
00247 template<class P = Void<>, class A = typename Alias<P>::alias >
00248 class COH_EXPORT_SPEC extends
00249     {
00250     public:
00251         /**
00252         * Marker for the actual inherited parent class.
00253         */
00254         typedef P inherited;
00255 
00256         /**
00257          * The literal inherited class.
00258          */
00259         typedef P inherited_literal;
00260 
00261         /**
00262         * The purpose of this definition is to cause a compilation error if
00263         * an attempt is made to instantiate the extends template by supplying
00264         * an interface.
00265         */
00266         typedef typename P::super grand;
00267 
00268         /**
00269         * Alias type used in throwables.
00270         */
00271         typedef A alias;
00272     };
00273 
00274 /**
00275 * @internal
00276 *
00277 * Terminal definition in extension hierarchy.
00278 */
00279 template<> class COH_EXPORT_SPEC extends<Void<>, Void<> >
00280     {
00281     public:
00282         typedef Void<> inherited;
00283         typedef Void<> inherited_literal;
00284         typedef Void<> alias;
00285     };
00286 
00287 // ----- helper macros used in the creation of specs ------------------------
00288 
00289 /**
00290 * The COH_LIST macros create a comma separated list of names, which each name
00291 * is the same except for a numeric suffix.
00292 */
00293 #define COH_LIST1(A)                 A##1
00294 #define COH_LIST2(A)  COH_LIST1 (A), A##2
00295 #define COH_LIST3(A)  COH_LIST2 (A), A##3
00296 #define COH_LIST4(A)  COH_LIST3 (A), A##4
00297 #define COH_LIST5(A)  COH_LIST4 (A), A##5
00298 #define COH_LIST6(A)  COH_LIST5 (A), A##6
00299 #define COH_LIST7(A)  COH_LIST6 (A), A##7
00300 #define COH_LIST8(A)  COH_LIST7 (A), A##8
00301 #define COH_LIST9(A)  COH_LIST8 (A), A##9
00302 #define COH_LIST10(A) COH_LIST9 (A), A##10
00303 #define COH_LIST11(A) COH_LIST10(A), A##11
00304 #define COH_LIST12(A) COH_LIST11(A), A##12
00305 #define COH_LIST13(A) COH_LIST12(A), A##13
00306 #define COH_LIST14(A) COH_LIST13(A), A##14
00307 #define COH_LIST15(A) COH_LIST14(A), A##15
00308 #define COH_LIST16(A) COH_LIST15(A), A##16
00309 
00310 /**
00311 * The COH_ARG_LIST macros create a comma separated list of argument
00312 * declarations names, which each argument name is the same except for a
00313 * numeric suffix.
00314 */
00315 #define COH_ARG_LIST1(A)                     A##1&  a1
00316 #define COH_ARG_LIST2(A)  COH_ARG_LIST1 (A), A##2&  a2
00317 #define COH_ARG_LIST3(A)  COH_ARG_LIST2 (A), A##3&  a3
00318 #define COH_ARG_LIST4(A)  COH_ARG_LIST3 (A), A##4&  a4
00319 #define COH_ARG_LIST5(A)  COH_ARG_LIST4 (A), A##5&  a5
00320 #define COH_ARG_LIST6(A)  COH_ARG_LIST5 (A), A##6&  a6
00321 #define COH_ARG_LIST7(A)  COH_ARG_LIST6 (A), A##7&  a7
00322 #define COH_ARG_LIST8(A)  COH_ARG_LIST7 (A), A##8&  a8
00323 #define COH_ARG_LIST9(A)  COH_ARG_LIST8 (A), A##9&  a9
00324 #define COH_ARG_LIST10(A) COH_ARG_LIST9 (A), A##10& a10
00325 #define COH_ARG_LIST11(A) COH_ARG_LIST10(A), A##11& a11
00326 #define COH_ARG_LIST12(A) COH_ARG_LIST11(A), A##12& a12
00327 #define COH_ARG_LIST13(A) COH_ARG_LIST12(A), A##13& a13
00328 #define COH_ARG_LIST14(A) COH_ARG_LIST13(A), A##14& a14
00329 #define COH_ARG_LIST15(A) COH_ARG_LIST14(A), A##15& a15
00330 #define COH_ARG_LIST16(A) COH_ARG_LIST15(A), A##16& a16
00331 
00332 /**
00333 * Define a proxy constructor with N arguments.
00334 */
00335 #define COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, N) \
00336     template<COH_LIST##N (class A)> SPEC(COH_ARG_LIST##N (A)) \
00337         : super_spec(COH_LIST##N (a)) {} \
00338     template<COH_LIST##N (class A)> SPEC(COH_ARG_LIST##N (const A)) \
00339         : super_spec(COH_LIST##N (a)) {}
00340 
00341 /**
00342 * Define a set of templated copy constructors.
00343 *
00344 * @param SPEC the class of which the constructors are declared
00345 */
00346 #define COH_DEFINE_PROXY_CONSTRUCTORS(SPEC) \
00347     SPEC() : super_spec() {} \
00348     SPEC(const SPEC& that) : super_spec(that) {} \
00349     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 1)  \
00350     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 2)  \
00351     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 3)  \
00352     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 4)  \
00353     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 5)  \
00354     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 6)  \
00355     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 7)  \
00356     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 8)  \
00357     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 9)  \
00358     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 10) \
00359     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 11) \
00360     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 12) \
00361     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 13) \
00362     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 14) \
00363     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 15) \
00364     COH_DEFINE_PROXY_CONSTRUCTOR(SPEC, 16)
00365 
00366 /**
00367 * Define a factory create method with N arguments.
00368 */
00369 #define COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, N) \
00370     template<COH_LIST##N (class A)> static RETURN create(COH_ARG_LIST##N (A)) \
00371         {return FUNCTION(COH_LIST##N(a));} \
00372     template<COH_LIST##N (class A)> static RETURN create(COH_ARG_LIST##N (const A)) \
00373         {return FUNCTION(COH_LIST##N(a));}
00374 
00375 /**
00376 * Define factory "create" methods.
00377 *
00378 * @param RETURN    the return type from the factory
00379 * @param FUNCTION  the function to be called to produce the the RETURN
00380 */
00381 #define COH_DEFINE_CREATE_METHODS(RETURN, FUNCTION) \
00382     static RETURN create() {return FUNCTION();}  \
00383     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 1)  \
00384     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 2)  \
00385     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 3)  \
00386     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 4)  \
00387     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 5)  \
00388     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 6)  \
00389     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 7)  \
00390     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 8)  \
00391     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 9)  \
00392     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 10) \
00393     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 11) \
00394     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 12) \
00395     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 13) \
00396     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 14) \
00397     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 15) \
00398     COH_DEFINE_PROXY_CREATE_METHOD(RETURN, FUNCTION, 16)
00399 
00400 /**
00401 * The factory class auto-generates static create methods for a class,
00402 * corresponding to the class's constructors.  The factory must be made a
00403 * friend of the defined class so that it may access the protected constructors.
00404 *
00405 * The factory is used by class specifications to provide the class with static
00406 * create methods.  i.e. the result of using a class_spec when defining class
00407 * Foo will result in Foo having auto-generated static create methods.  Direct
00408 * use of the factory for class instantiation is not supported.
00409 *
00410 * The factory supports constructors from zero to sixteen parameters. To help
00411 * the template system it is best (though not required) that there are not
00412 * multiple constructors with the same number of parameters. Classes wishing to
00413 * provide custom create methods may simply define them in their class, and
00414 * these will override and hide the factory auto-generated versions.
00415 *
00416 * @see class_spec
00417 * @see cloneable_spec
00418 * @see throwable_spec
00419 *
00420 * @author mf 2008.07.14
00421 */
00422 template<class T> class COH_EXPORT_SPEC factory
00423     {
00424     template<class, class, class> friend class class_spec;
00425 
00426     protected:
00427         /**
00428         * Generate a set of static "create" methods matching the signatures of
00429         * class T's constructors.
00430         *
00431         * NOTE: Compilation errors referencing this line likely indicate that
00432         *       the parameters supplied by the caller to the create method did
00433         *       not match one of the constructors.
00434         */
00435         COH_DEFINE_CREATE_METHODS(T*, new T)
00436     };
00437 
00438 COH_CLOSE_NAMESPACE2
00439 
00440 #endif // COH_LANG_SPEC_HPP
Copyright © 2000, 2013, Oracle and/or its affiliates. All rights reserved.