Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00025
00028
00029 #ifndef THOR_RESOURCEPTR_HPP
00030 #define THOR_RESOURCEPTR_HPP
00031
00032 #include <Thor/Detail/ResourceSlotBase.hpp>
00033 #include <Thor/Detail/SafeBoolIdiom.hpp>
00034 #include <Thor/Detail/Metaprogramming.hpp>
00035 #include <Thor/Config.hpp>
00036
00037 #include THOR_TR1_HEADER(type_traits)
00038 #include <algorithm>
00039 #include <cassert>
00040
00041
00042 namespace thor
00043 {
00044
00047
00058 template <class Resource>
00059 class ResourcePtr
00060 {
00061
00062
00063 private:
00064
00065 typedef typename std::tr1::remove_const<Resource>::type MutableResource;
00066
00067
00068 typedef typename detail::Conditional<
00069 std::tr1::is_const<Resource>::value,
00070 const detail::ResourceSlotBase<MutableResource>,
00071 detail::ResourceSlotBase<MutableResource> >::Type ResourceSlot;
00072
00073
00074
00075
00076 public:
00079 ResourcePtr();
00080
00083 ResourcePtr(const ResourcePtr& origin);
00084
00087 template <class Resource2>
00088 ResourcePtr(const ResourcePtr<Resource2>& origin);
00089
00092 ResourcePtr& operator= (const ResourcePtr& origin);
00093
00094
00097 template <class Resource2>
00098 ResourcePtr& operator= (const ResourcePtr<Resource2>& origin);
00099
00103 ~ResourcePtr();
00104
00108 void Swap(ResourcePtr& other);
00109
00113 void Reset();
00114
00120 operator THOR_DETAIL SafeBool() const;
00121
00124 Resource& operator* () const;
00125
00128 Resource* operator-> () const;
00129
00130
00131
00132
00133 public:
00134
00135 explicit ResourcePtr(ResourceSlot& slot);
00136
00137
00138
00139
00140 private:
00141 void IncRef();
00142
00143
00144 void DecRef();
00145
00146
00147 void Invalidate();
00148
00149
00150
00151
00152 private:
00153 ResourceSlot* mSlot;
00154
00155
00156
00157
00159 template <class Resource1, class Resource2>
00160 friend bool operator== (const ResourcePtr<Resource1>& lhs, const ResourcePtr<Resource2>& rhs);
00161
00162 template <class Resource2>
00163 friend class ResourcePtr;
00164
00165 friend class detail::ResourceSlotBase<MutableResource>;
00167 };
00168
00171 template <class Resource>
00172 void swap(ResourcePtr<Resource>& lhs, ResourcePtr<Resource>& rhs);
00173
00178 template <class Resource1, class Resource2>
00179 bool operator== (const ResourcePtr<Resource1>& lhs, const ResourcePtr<Resource2>& rhs);
00180
00185 template <class Resource1, class Resource2>
00186 bool operator!= (const ResourcePtr<Resource1>& lhs, const ResourcePtr<Resource2>& rhs);
00187
00189
00190 }
00191
00192 #include <Thor/Detail/ResourcePtr.inl>
00193 #endif // THOR_RESOURCEPTR_HPP