1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_core_Cloneable_hpp
10 #define anna_core_Cloneable_hpp
14 #include <anna/core/functions.hpp>
15 #include <anna/core/RuntimeException.hpp>
16 #include <anna/core/AutoPointer.hpp>
21 * Clase de la que deben heredar todas las clases con capacidades de clonado.
23 * La clase que implemente este interface debe invocar a alguno de las macros que facilitan la implementación de los métodos virtuales requeridos.
25 * \see \ref clone_final \ref clone_default \ref clone_abstract
27 class Cloneable : public AutoPointer {
32 virtual ~Cloneable() {;}
35 * Genera de esta instancia. Por cada clon generado habrá que invocar a #release.
36 * \return Un clon de la instancia recibida
38 virtual Cloneable* clone() const throw() = 0;
41 * Devuelve el nombre lógico de esta clase.
42 * \return el nombre lógico de esta clase.
44 static const char* className() throw() { return "Cloneable"; }
49 * \param whenFinished Indica que operación a realizar cuando se invoque a anna::Cloneable::release.
51 Cloneable(const WhenFinished::_v whenFinished = WhenFinished::Ignore) : AutoPointer(whenFinished) {;}
55 * \param other Instancia de la que copiar.
56 * \warning la instancia generada con este constructor establecerá que al invocar a anna::Cloneable::release se
57 * invocará al operador \em delete de esta instancia.
59 Cloneable(const Cloneable& other) : AutoPointer(WhenFinished::Delete) {;}
64 * Define el método \em clone que invoca al constructor copia de la forma:
67 #define anna_clone_final(Class) \
68 Class* clone () const throw () { return new Class (*this); } \
69 friend class AutoPointer;
72 #define anna_clone_final(Class) \
73 Class* clone () const throw () { return new Class (*this); } \
74 friend class AutoPointer;
78 * Define el método \em clone, pero permite que sea re-escrito por herencias posteriores con la forma:
81 #define anna_clone_default(Class) \
82 virtual Class* clone () const throw () { return new Class (*this); } \
83 friend class AutoPointer;
86 #define anna_clone_default(Class) \
87 virtual Class* clone () const throw () { return new Class (*this); } \
88 friend class AutoPointer;
91 * \page clone_abstract
92 * Define el método \em clone que tiene que ser re-escrito por herencias posteriores, pero facilita la conversión de
93 * la instancia creada al tipo adecuado de 'Cloneable', tendrá la forma:
95 #define anna_clone_abstract(Class) \
96 virtual Class* clone () const throw () = 0; \
97 friend class AutoPointer;
100 #define anna_clone_abstract(Class) \
101 virtual Class* clone () const throw () = 0; \
102 friend class AutoPointer;