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/SafeBoolIdiom.hpp>
00033 #include <Thor/Config.hpp>
00034
00035 #include THOR_TR1_HEADER(memory)
00036 #include <cassert>
00037
00038
00039 namespace thor
00040 {
00041
00044
00054 template <class Resource>
00055 class ResourcePtr
00056 {
00057
00058
00059 public:
00062 ResourcePtr();
00063
00067 explicit ResourcePtr(Resource* rawPointer);
00068
00074 template <typename D>
00075 ResourcePtr(Resource* rawPointer, D deleter);
00076
00079 ResourcePtr(const ResourcePtr& origin);
00080
00083 template <class Resource2>
00084 ResourcePtr(const ResourcePtr<Resource2>& origin);
00085
00088 ResourcePtr& operator= (const ResourcePtr& origin);
00089
00092 template <class Resource2>
00093 ResourcePtr& operator= (const ResourcePtr<Resource2>& origin);
00094
00098 ~ResourcePtr();
00099
00101 void Swap(ResourcePtr& other);
00102
00105 void Reset();
00106
00110 void Reset(Resource* rawPointer);
00111
00117 template <typename D>
00118 void Reset(Resource* rawPointer, D deleter);
00119
00125 operator THOR_DETAIL SafeBool() const;
00126
00129 Resource& operator* () const;
00130
00133 Resource* operator-> () const;
00134
00135
00136
00137
00138 public:
00139
00140 explicit ResourcePtr(std::tr1::shared_ptr<Resource> sharedPtr);
00141
00142
00143
00144
00145 private:
00146 std::tr1::shared_ptr<Resource> mPointer;
00147
00148
00149
00150
00152 template <class Resource1, class Resource2>
00153 friend bool operator== (const ResourcePtr<Resource1>& lhs, const ResourcePtr<Resource2>& rhs);
00154
00155 template <class Resource2>
00156 friend class ResourcePtr;
00158 };
00159
00162 template <class Resource>
00163 void swap(ResourcePtr<Resource>& lhs, ResourcePtr<Resource>& rhs);
00164
00169 template <class Resource1, class Resource2>
00170 bool operator== (const ResourcePtr<Resource1>& lhs, const ResourcePtr<Resource2>& rhs);
00171
00176 template <class Resource1, class Resource2>
00177 bool operator!= (const ResourcePtr<Resource1>& lhs, const ResourcePtr<Resource2>& rhs);
00178
00185 template <class Resource>
00186 ResourcePtr<Resource> NoDeletePtr(Resource* pointer);
00187
00189
00190 }
00191
00192 #include <Thor/Detail/ResourcePtr.inl>
00193 #endif // THOR_RESOURCEPTR_HPP