Oracle Coherence for C++ API
Release 3.7.1.0
E22845-01
00001 /* 00002 * class_spec.hpp 00003 * 00004 * Copyright (c) 2000, 2011, 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 /** 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 definitions 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() definition 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 definition 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 of the spec's parent class 00104 */ 00105 typedef typename E::inherited super_spec; 00106 00107 /** 00108 * Definition T's logical parent class 00109 */ 00110 typedef typename E::inherited_literal inherited; 00111 00112 /** 00113 * @internal 00114 * 00115 * Definition T's alias 00116 */ 00117 typedef typename E::alias alias; 00118 00119 /** 00120 * Standard Handle definition 00121 */ 00122 typedef TypedHandle<T> Handle; 00123 00124 /** 00125 * Standard View definition 00126 */ 00127 typedef TypedHandle<const T> View; 00128 00129 /** 00130 * Standard Holder definition 00131 */ 00132 typedef TypedHolder<T> Holder; 00133 00134 /** 00135 * implemented interface typedefs 00136 */ 00137 typedef typename I::interface_1 interface_1; 00138 typedef typename I::interface_2 interface_2; 00139 typedef typename I::interface_3 interface_3; 00140 typedef typename I::interface_4 interface_4; 00141 typedef typename I::interface_5 interface_5; 00142 typedef typename I::interface_6 interface_6; 00143 typedef typename I::interface_7 interface_7; 00144 typedef typename I::interface_8 interface_8; 00145 typedef typename I::interface_9 interface_9; 00146 typedef typename I::interface_10 interface_10; 00147 typedef typename I::interface_11 interface_11; 00148 typedef typename I::interface_12 interface_12; 00149 typedef typename I::interface_13 interface_13; 00150 typedef typename I::interface_14 interface_14; 00151 typedef typename I::interface_15 interface_15; 00152 typedef typename I::interface_16 interface_16; 00153 00154 00155 // ----- constructors --------------------------------------------------- 00156 00157 protected: 00158 /** 00159 * Generate a set of proxy constructors matching the signatures of the 00160 * parent class's constructors. 00161 * 00162 * NOTE: Compilation errors referencing this line likely indicate that 00163 * class being defined by this spec makes calls a "super" 00164 * constructor supplying a set of parameters for which there is 00165 * no exact match on the parent class. 00166 */ 00167 COH_DEFINE_PROXY_CONSTRUCTORS(class_spec) 00168 00169 public: 00170 /** 00171 * Generate a set of static "create" methods matching the signatures of 00172 * class T's constructors. 00173 * 00174 * NOTE: Compilation errors referencing this line likely indicate that 00175 * the parameters supplied by the caller to the create method did 00176 * not match one of the constructors. 00177 */ 00178 COH_DEFINE_CREATE_METHODS(Handle, factory_spec::create) 00179 00180 virtual TypedHandle<Object> clone() const 00181 { 00182 coh_throw_clone_not_supported(typeid(T)); 00183 return NULL; 00184 } 00185 00186 virtual size32_t sizeOf() const 00187 { 00188 return (size32_t) sizeof(T); 00189 } 00190 00191 virtual void* _cast(const std::type_info* pInfo) const 00192 { 00193 // optimistically test for class equality based on type_info 00194 // reference equality; this may result in false negatives, but 00195 // not false positives 00196 static const std::type_info* pInfoThis = &typeid(T); 00197 if (pInfoThis == pInfo) 00198 { 00199 return (void*) static_cast<const T*>(this); 00200 } 00201 // recurse down class trunk 00202 void* pCast = super_spec::_cast(pInfo); 00203 // traverse interfaces upon trunk cast failure 00204 return pCast ? pCast : I::implements_chain::_icast(pInfo); 00205 } 00206 00207 protected: 00208 /** 00209 * @internal 00210 * 00211 * Protect access to create method generated for the copy constructor. 00212 */ 00213 static inline Handle create(const T& that) 00214 { 00215 return Handle(factory_spec::create(that)); 00216 } 00217 }; 00218 00219 COH_CLOSE_NAMESPACE2 00220 00221 #endif // COH_CLASS_SPEC_HPP