coherence/lang/class_spec.hpp

00001 /*
00002 * class_spec.hpp
00003 *
00004 * Copyright 2001-2008 by Oracle. 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 /**
00033 * Helper for defining a non-cloneable concrete managed class.
00034 *
00035 * Managed classes are implementations of coherence::lang::Object, and include
00036 * a set of well known features, which are auto-generated by this helper class:
00037 *
00038 * - Handle/View/Holder defintions
00039 * - super class definition
00040 * - virtual interface inheritance of up to 16 interfaces
00041 * - public static create methods which delegate to protected constructors with
00042 *   up to sixteen arguments
00043 * - automatic sizeOf() defintion
00044 *
00045 * The template takes three parameters:
00046 *
00047 * - The name of the class being defined
00048 * - The defined classes parent class, indicated as extends<parent>
00049 * - An optional list of interfaces to implement, indicated as
00050 *   implements<i1, i2, ...>
00051 *
00052 * A normal class defintion would be:
00053 * @code
00054 * class Foo
00055 *   : public class_spec<Foo,
00056 *       extends<Bar>,
00057 *       implements<SomeInterface, SomeOtherInterface> >
00058 *   {
00059 *   // add support for auto-generated static create methods
00060 *   friend class factory<Foo>;
00061 *
00062 *   protected:
00063 *       // Constructors are defined as protected, and access via
00064 *       // auto-generated create methods, with matching signatures
00065 *       Foo()
00066 *           : super() // calls Bar()
00067 *           {
00068 *           }
00069 *
00070 *   public:
00071 *       // normal class definition....
00072 *   };
00073 * @endcode
00074 *
00075 * @see extends
00076 * @see implements
00077 *
00078 * @author mf 2008.07.14
00079 */
00080 template<class T, class E = extends<Object, void>, class I = implements<> >
00081 class COH_EXPORT_SPEC class_spec
00082     : public E, public E::inherited, public virtual I::implements_chain
00083     {
00084     // ----- typedefs -------------------------------------------------------
00085 
00086     public:
00087         /**
00088         * Specification definition
00089         */
00090         typedef class_spec this_spec;
00091 
00092         /**
00093         * Factory for this class
00094         */
00095         typedef factory<T> factory_spec;
00096 
00097         /**
00098         * Definition T's actual parent class
00099         */
00100         typedef class_spec super;
00101 
00102         /**
00103         * Definition T's logical parent class
00104         */
00105         typedef typename E::inherited inherited;
00106 
00107         /**
00108         * @internal
00109         *
00110         * Definition T's alias
00111         */
00112         typedef typename E::alias alias;
00113 
00114         /**
00115         * Standard Handle definition
00116         */
00117         typedef TypedHandle<T> Handle;
00118 
00119         /**
00120         * Standard View definition
00121         */
00122         typedef TypedHandle<const T> View;
00123 
00124         /**
00125         * Standard Holder defintion
00126         */
00127         typedef TypedHolder<T> Holder;
00128 
00129 
00130     // ----- constructors ---------------------------------------------------
00131 
00132     protected:
00133         /**
00134         * Generate a set of proxy constuctors matching the signatures of the
00135         * parent class's constructors.
00136         *
00137         * NOTE: Compilation errors referencing this line likely indicate that
00138         *       class being defined by this spec makes calls a "super"
00139         *       constructor supplying a set of parameters for which there is
00140         *       no exact match on the parent class.
00141         */
00142         COH_DECLARE_PROXY_CONSTRUCTORS(class_spec);
00143 
00144     public:
00145         /**
00146         * Generate a set of static "create" methods matching the signatures of
00147         * class T's constructors.
00148         *
00149         * NOTE: Compilation errors referencing this line likely indicate that
00150         *       the parameters supplied by the caller to the create method did
00151         *       not match one of the constructors.
00152         */
00153         COH_DEFINE_CREATE_METHODS(Handle, factory_spec::create)
00154 
00155         virtual TypedHandle<Object> clone() const
00156             {
00157             coh_throw_clone_not_supported(typeid(T));
00158             return NULL;
00159             }
00160 
00161         virtual size32_t sizeOf() const
00162             {
00163             return sizeof(T);
00164             }
00165 
00166     protected:
00167         /**
00168         * @internal
00169         *
00170         * Protect access to create method generated for the copy constructor.
00171         */
00172         static inline Handle create(const T& that)
00173             {
00174             return factory_spec::create(that);
00175             }
00176     };
00177 COH_DEFINE_PROXY_CONSTRUCTORS(COH_TEMPLATE_DECLARE3(T, E, I), \
00178         COH_TEMPLATE_DEFINE3(T, E, I), class_spec, inherited)
00179 
00180 COH_CLOSE_NAMESPACE2
00181 
00182 #endif // COH_CLASS_SPEC_HPP
Copyright (c) 2000-2008 Oracle. All rights reserved.