00001 /* 00002 * cloneable_spec.hpp 00003 * 00004 * Copyright (c) 2000, 2016, 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_CLONEABLE_SPEC_HPP 00017 #define COH_CLONEABLE_SPEC_HPP 00018 00019 #include "coherence/lang/compatibility.hpp" 00020 00021 #include "coherence/lang/class_spec.hpp" 00022 #include "coherence/lang/lang_spec.hpp" 00023 #include "coherence/lang/TypedHandle.hpp" 00024 #include "coherence/lang/TypedHolder.hpp" 00025 00026 COH_OPEN_NAMESPACE2(coherence,lang) 00027 00028 class Object; 00029 00030 /** 00031 * Helper for defining a cloneable managed class. 00032 * 00033 * It addition to the features auto-generated by the class_spec<> helper template 00034 * cloneable_spec<> auto-generates an implementation of "Object::Handle clone() const" 00035 * which delegates to the defined classes const copy constructor. 00036 * 00037 * A normal cloneable class definition would be: 00038 * @code 00039 * class Foo 00040 * : public cloneable_spec<Foo, 00041 * extends<Bar>, 00042 * implements<SomeInterface, SomeOtherInterface> > 00043 * { 00044 * // add support for auto-generated static create methods 00045 * friend class factory<Foo>; 00046 * 00047 * protected: 00048 * // Constructors are defined as protected, and access via 00049 * // auto-generated create methods, with matching signatures 00050 * Foo() 00051 * : super() ... 00052 * { 00053 * } 00054 * 00055 * // Copy constructor 00056 * Foo(const Foo& that) 00057 * : super(that) ... 00058 * { 00059 * } 00060 * 00061 * public: 00062 * // normal class definition.... 00063 * }; 00064 * @endcode 00065 * 00066 * @see extends 00067 * @see implements 00068 * 00069 * @author mf 2008.07.14 00070 */ 00071 template<class T, class E = extends<Object>, class I = implements<> > 00072 class COH_EXPORT_SPEC cloneable_spec 00073 : public class_spec<T, E, I> 00074 { 00075 // ----- typedefs ------------------------------------------------------- 00076 00077 public: 00078 /** 00079 * Specification definition 00080 */ 00081 typedef cloneable_spec this_spec; 00082 00083 /** 00084 * Definition T's parent class 00085 */ 00086 typedef cloneable_spec super; 00087 00088 /** 00089 * Definition of the spec's parent class 00090 */ 00091 typedef class_spec<T, E, I> super_spec; 00092 00093 00094 // ----- constructors --------------------------------------------------- 00095 00096 protected: 00097 /** 00098 * Generate a set of proxy constructors matching the signatures of the 00099 * parent class's constructors. 00100 * 00101 * NOTE: Compilation errors referencing this line likely indicate that 00102 * class being defined by this spec makes calls a "super" 00103 * constructor supplying a set of parameters for which there is 00104 * no exact match on the parent class. 00105 */ 00106 COH_DEFINE_PROXY_CONSTRUCTORS(cloneable_spec) 00107 00108 public: 00109 /** 00110 * {@inheritDoc} 00111 */ 00112 virtual TypedHandle<Object> clone() const 00113 { 00114 return T::create(static_cast<const T&>(*this)); 00115 } 00116 }; 00117 00118 COH_CLOSE_NAMESPACE2 00119 00120 #endif // COH_CLONEABLE_SPEC_HPP