00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00033
00034 #ifndef GROOVX_NUB_HANDLE_H_UTC20051116165012_DEFINED
00035 #define GROOVX_NUB_HANDLE_H_UTC20051116165012_DEFINED
00036
00037 #include "nub/types.h"
00038
00039 #include "rutz/algo.h"
00040 #include "rutz/fileposition.h"
00041
00042 #include <typeinfo>
00043
00044 namespace nub
00045 {
00046 namespace detail
00047 {
00048 template <class T, class unref_policy> class handle;
00049
00050 void throw_ref_null(const std::type_info& info, const rutz::file_pos& pos);
00051 void throw_ref_unshareable(const std::type_info& msg, const rutz::file_pos& pos);
00052 }
00053 }
00054
00056
00059 template <class T, class unref_policy>
00060 class nub::detail::handle
00061 {
00062 public:
00063 explicit handle(T* master) : m_master(master)
00064 {
00065 if (master == 0)
00066 throw_ref_null(typeid(T), SRC_POS);
00067
00068 if (master->is_not_shareable())
00069 throw_ref_unshareable(typeid(T), SRC_POS);
00070
00071 m_master->incr_ref_count();
00072 }
00073
00074 ~handle() throw()
00075 { unref_policy::unref(m_master); }
00076
00077 handle(const handle& other) throw()
00078 :
00079 m_master(other.m_master)
00080 {
00081 m_master->incr_ref_count();
00082 }
00083
00084 handle& operator=(const handle& other) throw()
00085 {
00086 handle other_copy(other);
00087 this->swap(other_copy);
00088 return *this;
00089 }
00090
00091 T* get() const throw()
00092 { return m_master; }
00093
00094 bool operator==(const handle& other) const throw()
00095 { return m_master == other.m_master; }
00096
00097 private:
00098 void swap(handle& other) throw()
00099 {
00100 rutz::swap2(m_master, other.m_master);
00101 }
00102
00103 T* m_master;
00104
00105 };
00106
00107 static const char __attribute__((used)) vcid_groovx_nub_handle_h_utc20051116165012[] = "$Id: handle.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00108 #endif // !GROOVX_NUB_HANDLE_H_UTC20051116165012DEFINED