00001 /* Copyright (c) 2007, Gennady Bystritsky <bystr@mac.com> 00002 * 00003 * Distributed under the MIT Licence. 00004 * This is free software. See 'LICENSE' for details. 00005 * You must read and accept the license prior to use. 00006 */ 00007 00008 #ifndef _SK_UTIL_SLOT_POLICY_CLONING_HXX_ 00009 #define _SK_UTIL_SLOT_POLICY_CLONING_HXX_ 00010 00011 #include <sk/util/slot/policy/Storing.hxx> 00012 00013 namespace sk { 00014 namespace util { 00015 namespace slot { 00016 namespace policy { 00017 template<typename T> 00018 struct Cloning 00019 : public Storing<T> 00020 { 00021 public: 00022 Cloning() {} 00023 00024 Cloning(const Cloning<T>& other) { 00025 makeClone(other); 00026 } 00027 00028 Cloning(const Storing<T>& other) { 00029 makeClone(other); 00030 } 00031 00032 void operator=(const Cloning<T>& other) { 00033 makeClone(other); 00034 } 00035 00036 void operator=(const Storing<T>& other) { 00037 makeClone(other); 00038 } 00039 00040 protected: 00041 void setObject(T& object) { 00042 Storing<T>::setObject(object.clone()); 00043 } 00044 00045 void setObject(T* object) { 00046 Storing<T>::setObject(object); 00047 } 00048 00049 void makeClone(const Storing<T>& other) { 00050 if(&other == this) { 00051 return; 00052 } 00053 Storing<T>::clearSlot(); 00054 00055 if(hasSlot(other) == true) { 00056 setObject(getSlot(other).get()); 00057 } 00058 } 00059 }; 00060 } 00061 } 00062 } 00063 } 00064 00065 #endif /* _SK_UTIL_SLOT_POLICY_CLONING_HXX_ */