00001 /* Copyright (c) 2006, 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_HOLDER_HXX_ 00009 #define _SK_UTIL_HOLDER_HXX_ 00010 00011 #include <sk/util/slot/Reference.hxx> 00012 #include <sk/util/slot/Pointer.hxx> 00013 #include <sk/util/slot/mixin/None.h> 00014 #include <sk/util/slot/policy/Storing.hxx> 00015 #include <sk/util/slot/policy/Sharing.hxx> 00016 #include <sk/util/slot/policy/Cloning.hxx> 00017 #include <sk/util/slot/policy/Copying.hxx> 00018 #include <sk/util/slot/policy/Aliasing.hxx> 00019 00020 namespace sk { 00021 namespace util { 00022 template<typename T, typename Policy = slot::policy::Storing<T> > 00023 class Holder 00024 : public Policy 00025 { 00026 public: 00027 typedef Holder<T, slot::policy::Sharing<T> > Sharing; 00028 typedef Holder<T, slot::policy::Cloning<T> > Cloning; 00029 typedef Holder<T, slot::policy::Copying<T> > Copying; 00030 typedef Holder<T, slot::policy::Aliasing<T> > Aliasing; 00031 00032 public: 00033 Holder(); 00034 Holder(const slot::policy::Storing<T>& other); 00035 explicit Holder(T* object); 00036 explicit Holder(T& object); 00037 virtual ~Holder(); 00038 00039 Holder<T, Policy>& operator=(const Holder<T, Policy>& other); 00040 Holder<T, Policy>& operator=(const slot::policy::Storing<T>& other); 00041 00042 bool contains(const T& object) const; 00043 bool isEmpty() const; 00044 bool isOwner() const; 00045 T& get() const; 00046 00047 void set(T* object); 00048 void set(T& object); 00049 00050 bool remove(); 00051 void clear(); 00052 00053 T* release(); 00054 }; 00055 } 00056 } 00057 00058 #endif /* _SK_UTIL_HOLDER_HXX_ */