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

E47891-01

coherence/lang/lang_spec.hpp

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