1 // ANNA - Anna is Not 'N' Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // https://bitbucket.org/testillano/anna
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #ifndef anna_core_Cloneable_hpp
38 #define anna_core_Cloneable_hpp
42 #include <anna/core/functions.hpp>
43 #include <anna/core/RuntimeException.hpp>
44 #include <anna/core/AutoPointer.hpp>
49 * Clase de la que deben heredar todas las clases con capacidades de clonado.
51 * La clase que implemente este interface debe invocar a alguno de las macros que facilitan la implementación de los métodos virtuales requeridos.
53 * \see \ref clone_final \ref clone_default \ref clone_abstract
55 class Cloneable : public AutoPointer {
60 virtual ~Cloneable() {;}
63 * Genera de esta instancia. Por cada clon generado habrá que invocar a #release.
64 * \return Un clon de la instancia recibida
66 virtual Cloneable* clone() const throw() = 0;
69 * Devuelve el nombre lógico de esta clase.
70 * \return el nombre lógico de esta clase.
72 static const char* className() throw() { return "Cloneable"; }
77 * \param whenFinished Indica que operación a realizar cuando se invoque a anna::Cloneable::release.
79 Cloneable(const WhenFinished::_v whenFinished = WhenFinished::Ignore) : AutoPointer(whenFinished) {;}
83 * \param other Instancia de la que copiar.
84 * \warning la instancia generada con este constructor establecerá que al invocar a anna::Cloneable::release se
85 * invocará al operador \em delete de esta instancia.
87 Cloneable(const Cloneable& other) : AutoPointer(WhenFinished::Delete) {;}
92 * Define el método \em clone que invoca al constructor copia de la forma:
95 #define anna_clone_final(Class) \
96 Class* clone () const throw () { return new Class (*this); } \
97 friend class AutoPointer;
100 #define anna_clone_final(Class) \
101 Class* clone () const throw () { return new Class (*this); } \
102 friend class AutoPointer;
105 * \page clone_default
106 * Define el método \em clone, pero permite que sea re-escrito por herencias posteriores con la forma:
109 #define anna_clone_default(Class) \
110 virtual Class* clone () const throw () { return new Class (*this); } \
111 friend class AutoPointer;
114 #define anna_clone_default(Class) \
115 virtual Class* clone () const throw () { return new Class (*this); } \
116 friend class AutoPointer;
119 * \page clone_abstract
120 * Define el método \em clone que tiene que ser re-escrito por herencias posteriores, pero facilita la conversión de
121 * la instancia creada al tipo adecuado de 'Cloneable', tendrá la forma:
123 #define anna_clone_abstract(Class) \
124 virtual Class* clone () const throw () = 0; \
125 friend class AutoPointer;
128 #define anna_clone_abstract(Class) \
129 virtual Class* clone () const throw () = 0; \
130 friend class AutoPointer;