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

E90870-01

coherence/lang/class_spec.hpp

00001 /*
00002 * class_spec.hpp
00003 *
00004 * Copyright (c) 2000, 2019, 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_CLASS_SPEC_HPP
00017 #define COH_CLASS_SPEC_HPP
00018 
00019 #include "coherence/lang/compatibility.hpp"
00020 
00021 #include "coherence/lang/lang_spec.hpp"
00022 #include "coherence/lang/TypedHandle.hpp"
00023 #include "coherence/lang/TypedHolder.hpp"
00024 
00025 COH_OPEN_NAMESPACE2(coherence,lang)
00026 
00027 class Object;
00028 
00029 extern COH_EXPORT void coh_throw_clone_not_supported(const std::type_info&);
00030 
00031 /**
00032 * Helper for defining a non-cloneable concrete managed class.
00033 *
00034 * Managed classes are implementations of coherence::lang::Object, and include
00035 * a set of well known features, which are auto-generated by this helper class:
00036 *
00037 * - Handle/View/Holder definitions
00038 * - super class definition
00039 * - virtual interface inheritance of up to 16 interfaces
00040 * - public static create methods which delegate to protected constructors with
00041 *   up to sixteen arguments
00042 * - automatic sizeOf() definition
00043 *
00044 * The template takes three parameters:
00045 *
00046 * - The name of the class being defined
00047 * - The defined classes parent class, indicated as extends<parent>
00048 * - An optional list of interfaces to implement, indicated as
00049 *   implements<i1, i2, ...>
00050 *
00051 * A normal class definition would be:
00052 * @code
00053 * class Foo
00054 *   : public class_spec<Foo,
00055 *       extends<Bar>,
00056 *       implements<SomeInterface, SomeOtherInterface> >
00057 *   {
00058 *   // add support for auto-generated static create methods
00059 *   friend class factory<Foo>;
00060 *
00061 *   protected:
00062 *       // Constructors are defined as protected, and access via
00063 *       // auto-generated create methods, with matching signatures
00064 *       Foo()
00065 *           : super() // calls Bar()
00066 *           {
00067 *           }
00068 *
00069 *   public:
00070 *       // normal class definition....
00071 *   };
00072 * @endcode
00073 *
00074 * @see extends
00075 * @see implements
00076 *
00077 * @author mf 2008.07.14
00078 */
00079 template<class T, class E = extends<Object, void>, class I = implements<> >
00080 class COH_EXPORT_SPEC class_spec
00081     : public E, public E::inherited, public virtual I::implements_chain
00082     {
00083     // ----- typedefs -------------------------------------------------------
00084 
00085     public:
00086         /**
00087         * Specification definition
00088         */
00089         typedef class_spec this_spec;
00090 
00091         /**
00092         * Factory for this class
00093         */
00094         typedef factory<T> factory_spec;
00095 
00096         /**
00097         * Definition T's actual parent class
00098         */
00099         typedef class_spec super;
00100 
00101         /**
00102         * Definition of the spec's parent class
00103         */
00104         typedef typename E::inherited super_spec;
00105 
00106         /**
00107         * Definition T's logical parent class
00108         */
00109         typedef typename E::inherited_literal inherited;
00110 
00111         /**
00112         * @internal
00113         *
00114         * Definition T's alias
00115         */
00116         typedef typename E::alias alias;
00117 
00118         /**
00119         * Standard Handle definition
00120         */
00121         typedef TypedHandle<T> Handle;
00122 
00123         /**
00124         * Standard View definition
00125         */
00126         typedef TypedHandle<const T> View;
00127 
00128         /**
00129         * Standard Holder definition
00130         */
00131         typedef TypedHolder<T> Holder;
00132 
00133         /**
00134          * implemented interface typedefs
00135          */
00136         typedef typename I::interface_1  interface_1;
00137         typedef typename I::interface_2  interface_2;
00138         typedef typename I::interface_3  interface_3;
00139         typedef typename I::interface_4  interface_4;
00140         typedef typename I::interface_5  interface_5;
00141         typedef typename I::interface_6  interface_6;
00142         typedef typename I::interface_7  interface_7;
00143         typedef typename I::interface_8  interface_8;
00144         typedef typename I::interface_9  interface_9;
00145         typedef typename I::interface_10 interface_10;
00146         typedef typename I::interface_11 interface_11;
00147         typedef typename I::interface_12 interface_12;
00148         typedef typename I::interface_13 interface_13;
00149         typedef typename I::interface_14 interface_14;
00150         typedef typename I::interface_15 interface_15;
00151         typedef typename I::interface_16 interface_16;
00152 
00153 
00154     // ----- constructors ---------------------------------------------------
00155 
00156     protected:
00157         /**
00158         * Generate a set of proxy constructors matching the signatures of the
00159         * parent class's constructors.
00160         *
00161         * NOTE: Compilation errors referencing this line likely indicate that
00162         *       class being defined by this spec makes calls a "super"
00163         *       constructor supplying a set of parameters for which there is
00164         *       no exact match on the parent class.
00165         */
00166         COH_DEFINE_PROXY_CONSTRUCTORS(class_spec)
00167 
00168     public:
00169         /**
00170         * Generate a set of static "create" methods matching the signatures of
00171         * class T's constructors.
00172         *
00173         * NOTE: Compilation errors referencing this line likely indicate that
00174         *       the parameters supplied by the caller to the create method did
00175         *       not match one of the constructors.
00176         */
00177         COH_DEFINE_CREATE_METHODS(Handle, factory_spec::create)
00178 
00179         virtual TypedHandle<Object> clone() const
00180             {
00181             coh_throw_clone_not_supported(typeid(T));
00182             return NULL;
00183             }
00184 
00185         virtual size64_t sizeOf(bool fDeep = false) const
00186             {
00187             return fDeep
00188                     ? inherited::sizeOf(/*fDeep*/ true)
00189                     : sizeof(T);
00190             }
00191 
00192         virtual void* _cast(coh_class_id pInfo) const
00193             {
00194             // first check if this class has the class id in question
00195             // if not do a breadth first search across directly implemented
00196             // interfaces, and then finally tail recurse up the inheritance
00197             // hierarchy
00198             void* p = COH_CLASS_ID(T) == pInfo
00199                     ? (void*) static_cast<const T*>(this)
00200                     : I::implements_chain::_icast(pInfo);
00201             return p ? p : super_spec::_cast(pInfo);
00202             }
00203 
00204 
00205         COH_GENERATE_CLASS_ID(T)
00206 
00207         /**
00208          * @internal
00209          *
00210          * Return the class id of an object.
00211          */
00212         virtual coh_class_id _getClassId() const
00213             {
00214             return COH_CLASS_ID(T);
00215             }
00216 
00217     protected:
00218         /**
00219         * @internal
00220         *
00221         * Protect access to create method generated for the copy constructor.
00222         */
00223         static inline Handle create(const T& that)
00224             {
00225             return Handle(factory_spec::create(that));
00226             }
00227     };
00228 
00229 COH_CLOSE_NAMESPACE2
00230 
00231 #endif // COH_CLASS_SPEC_HPP
Copyright © 2000, 2019, Oracle and/or its affiliates. All rights reserved.