#include <CTBclone.hxx>
Public Methods | |
T * | operator() (const T &src) const |
Often the need arises to duplicate an object. In many cases a simple copy construct is sufficient. However, this is not possible if the object is for example only known through a pointer to a base class. In those cases the object can't be copied but must be cloned.
In templatized classes one faces the problem to use depending on the type of the object either the copy or the clone approach, the former for simple classes which don't have a clone method, the later for example for abstract base classes.
The classes CTBclone
and a helper class CTBcloneable
provide a function object interface for such a `clone or copy' functionality:
CTBclone
provides the interface. The operator()()
returns a new
'ed copy or clone of the object passed as first argument. CTBclone
uses copy semantics and provides the default for all simple classes. CTBcloneable
has the same interface as CTBclone
, its implementation uses clone semantics and expects a Clone()
method to exists. T
one has to overwrite the definition of CTBclone<T>
by providing a specialization of CTBclone
. If T
has a Clone()
method this can simply be done by deriving a specialization of CTBclone
from CTBcloneable
like class foo { public: foo* Clone() const; ... }; class CTBclone<foo> : public CTBcloneable<foo> {};
CTBclone
with the same interface and give an implemenation with whatever the class provides for cloning.
Note, that the specialization of CTBclone
has to be declared in all derived classes, it is not sufficient to do this just for the base class.
T(const T&)
Definition at line 17 of file CTBclone.hxx.
|
Create a new object of type
Definition at line 68 of file CTBclone.icc. |