00001 // 00002 // See license.txt for license information. 00003 // 00004 // cloneable_object.hpp 00005 // 00006 // 17-Jul-2003 phamilton Created 00007 // 00008 00009 #ifndef incCOMMON_CLONEABLE_OBJECT 00010 #define incCOMMON_CLONEABLE_OBJECT 00011 00012 // forwards 00013 #include <string> 00014 00015 namespace ph { 00016 namespace common { 00017 00018 class cloneable_object_context; 00019 class object_base; 00020 00021 class cloneable_object_base 00022 /** 00023 Abstract class representing the interface for an object to be cloned. 00024 00025 This is an important part of allowing objects to be used in the 00026 Abstract Factory pattern, which is used heavily in persistance. 00027 */ 00028 { 00029 public: 00030 virtual ~cloneable_object_base() {} 00031 00032 virtual bool construct(cloneable_object_context *context) = 0; 00033 //!< Allow objects to construct themselves WITH inheritence. 00034 //! it's up to the impementation to call this on the object 00035 //! when it is created (or cloned from another). 00036 00037 virtual object_base *clone( 00038 const std::string &name, 00039 cloneable_object_context *context) const = 0; 00040 //!< Clone this object. 00041 //! 00042 00043 virtual object_base *subclass( 00044 const std::string &name, 00045 cloneable_object_context *context) const = 0; 00046 //!< Subclassing copies the object,but makes it's "type" the 00047 //! name of this object, and makes the "name" equal to the name passed in. 00048 //! This allows an object to be a virtual copy of another, except 00049 //! for the type identifier. This feature is used in template 00050 //! systems. 00051 }; 00052 00053 class cloneable_object_context 00054 /** 00055 Abstract class representing a context that is passed when objects 00056 are cloned. 00057 */ 00058 { 00059 public: 00060 virtual ~cloneable_object_context() {}; 00061 }; 00062 00063 }; // common 00064 }; // ph 00065 00066 #endif // incCOMMON_CLONEABLE_OBJECT