1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
\r
6 // This software is provided 'as-is', without any express or implied warranty.
\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.
\r
9 // Permission is granted to anyone to use this software for any purpose,
\r
10 // including commercial applications, and to alter it and redistribute it freely,
\r
11 // subject to the following restrictions:
\r
13 // 1. The origin of this software must not be misrepresented;
\r
14 // you must not claim that you wrote the original software.
\r
15 // If you use this software in a product, an acknowledgment
\r
16 // in the product documentation would be appreciated but is not required.
\r
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
26 ////////////////////////////////////////////////////////////
\r
27 /// Default constructor
\r
28 ////////////////////////////////////////////////////////////
\r
29 template <typename T>
\r
30 ResourcePtr<T>::ResourcePtr() :
\r
37 ////////////////////////////////////////////////////////////
\r
38 /// Construct from a raw resource
\r
39 ////////////////////////////////////////////////////////////
\r
40 template <typename T>
\r
41 ResourcePtr<T>::ResourcePtr(const T* Resource) :
\r
42 myResource(Resource)
\r
45 myResource->Connect(*this);
\r
49 ////////////////////////////////////////////////////////////
\r
50 /// Copy constructor
\r
51 ////////////////////////////////////////////////////////////
\r
52 template <typename T>
\r
53 ResourcePtr<T>::ResourcePtr(const ResourcePtr<T>& Copy) :
\r
54 myResource(Copy.myResource)
\r
57 myResource->Connect(*this);
\r
61 ////////////////////////////////////////////////////////////
\r
63 ////////////////////////////////////////////////////////////
\r
64 template <typename T>
\r
65 ResourcePtr<T>::~ResourcePtr()
\r
68 myResource->Disconnect(*this);
\r
72 ////////////////////////////////////////////////////////////
\r
73 /// Assignment operator from another ResourcePtr
\r
74 ////////////////////////////////////////////////////////////
\r
75 template <typename T>
\r
76 ResourcePtr<T>& ResourcePtr<T>::operator =(const ResourcePtr<T>& Other)
\r
79 myResource->Disconnect(*this);
\r
81 myResource = Other.myResource;
\r
84 myResource->Connect(*this);
\r
90 ////////////////////////////////////////////////////////////
\r
91 /// Assignment operator from a raw resource
\r
92 ////////////////////////////////////////////////////////////
\r
93 template <typename T>
\r
94 ResourcePtr<T>& ResourcePtr<T>::operator =(const T* Resource)
\r
97 myResource->Disconnect(*this);
\r
99 myResource = Resource;
\r
102 myResource->Connect(*this);
\r
108 ////////////////////////////////////////////////////////////
\r
109 /// Cast operator to implicitely convert the resource pointer to
\r
110 /// its raw pointer type.
\r
111 /// This might be dangerous in the general case, but in this context
\r
112 /// it is safe enough to define this operator
\r
113 ////////////////////////////////////////////////////////////
\r
114 template <typename T>
\r
115 ResourcePtr<T>::operator const T*() const
\r
121 ////////////////////////////////////////////////////////////
\r
122 /// Operator * overload to return a reference to the actual resource
\r
123 ////////////////////////////////////////////////////////////
\r
124 template <typename T>
\r
125 const T& ResourcePtr<T>::operator *() const
\r
127 return *myResource;
\r
131 ////////////////////////////////////////////////////////////
\r
132 /// Operator -> overload to return a pointer to the actual resource
\r
133 ////////////////////////////////////////////////////////////
\r
134 template <typename T>
\r
135 const T* ResourcePtr<T>::operator ->() const
\r
141 ////////////////////////////////////////////////////////////
\r
142 /// Function called when the observed resource is about to be
\r
144 ////////////////////////////////////////////////////////////
\r
145 template <typename T>
\r
146 void ResourcePtr<T>::OnResourceDestroyed()
\r