C++ Client API Reference for Oracle Coherence
14c (14.1.2.0.0)

F79659-03

coherence/lang/cloneable_spec.hpp

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