Add a Clonable interface, make it look something like:
class Clonable : public Interface {
public:
Object* clone( bool deepCopy=false ) = 0;
};
This could be implemented as needed. Perhaps a
templated class impl:
template<typename CloneType>
class ClonableImpl {
public:
Object* clone( bool deepCopy=false ) {
return new CloneType( *this );
}
};
Perhaps a static method coule be added to the Object
class as a utilty method for testing for this:
static bool Object::isClonable( Object* obj );
implemented as
bool Object::isClonable( Object* obj )
{
return (NULL == dynamic_cast<Clonable*>(obj)) ? false
: true;
}
Usage:
Object* clonedInstance = NULL;
if ( Object::isClonable( srcInstance ) ) {
//perform some specific action
}
Clonable* cloneable = dynamic_cast<Clonable*>(srcInstance);
Object* clonedInstance = cloneable->clone();