Inferno
0.2
|
00001 #ifndef CLONE_HPP 00002 #define CLONE_HPP 00003 00004 #include "common/common.hpp" 00005 00006 00007 // NOTE: Duplicate uses shared_ptr so that it can be overloaded to return 00008 // the supplied pointer (as done by SpecificIdentifier). Clone is guaranteed 00009 // to return a new() object. 00010 class Cloner 00011 { 00012 public: 00013 virtual shared_ptr<Cloner> Clone() const = 0; 00014 virtual shared_ptr<Cloner> Duplicate( shared_ptr<Cloner> p ) 00015 { 00016 ASSERT( p.get() == this ); // unfortunate wrinkle: must always call as PX->Duplicate(PX) 00017 return Clone(); // default duplication is to clone, but can be over-ridden 00018 } 00019 template< class TYPE > 00020 inline static shared_ptr<Cloner> CloneStatic( const TYPE *source ) 00021 { 00022 shared_ptr<Cloner> clone( new TYPE(*source) ); 00023 *clone = *source; // Copy everything - be aware that this means the clone has links into the source subtree! 00024 return clone; 00025 } 00026 }; 00027 00028 #define CLONE_FUNCTION \ 00029 virtual shared_ptr<Cloner> Clone() const \ 00030 { \ 00031 return Cloner::CloneStatic(this); \ 00032 } 00033 #endif