ResourcePtr.inl
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
29 template <typename T>
31 myResource(NULL)
32 {
33 
34 }
35 
36 
40 template <typename T>
42 myResource(Resource)
43 {
44  if (myResource)
45  myResource->Connect(*this);
46 }
47 
48 
52 template <typename T>
54 myResource(Copy.myResource)
55 {
56  if (myResource)
57  myResource->Connect(*this);
58 }
59 
60 
64 template <typename T>
66 {
67  if (myResource)
68  myResource->Disconnect(*this);
69 }
70 
71 
75 template <typename T>
77 {
78  if (myResource)
79  myResource->Disconnect(*this);
80 
81  myResource = Other.myResource;
82 
83  if (myResource)
84  myResource->Connect(*this);
85 
86  return *this;
87 }
88 
89 
93 template <typename T>
95 {
96  if (myResource)
97  myResource->Disconnect(*this);
98 
99  myResource = Resource;
100 
101  if (myResource)
102  myResource->Connect(*this);
103 
104  return *this;
105 }
106 
107 
114 template <typename T>
115 ResourcePtr<T>::operator const T*() const
116 {
117  return myResource;
118 }
119 
120 
124 template <typename T>
126 {
127  return *myResource;
128 }
129 
130 
134 template <typename T>
136 {
137  return myResource;
138 }
139 
140 
145 template <typename T>
147 {
148  myResource = NULL;
149 }
Base class for every resource that needs to notify dependent classes about its destruction.
Definition: Resource.hpp:50
Safe pointer to a T resource (inheriting from sf::Resource&lt;T&gt;), its pointer is automatically reseted ...
Definition: Resource.hpp:43
~ResourcePtr()
Destructor.
Definition: ResourcePtr.inl:65
ResourcePtr< T > & operator=(const ResourcePtr< T > &Other)
Assignment operator from another ResourcePtr.
Definition: ResourcePtr.inl:76
const T * operator->() const
Operator -&gt; overload to return a pointer to the actual resource.
ResourcePtr()
Default constructor.
Definition: ResourcePtr.inl:30
void OnResourceDestroyed()
Function called when the observed resource is about to be destroyed.
const T & operator*() const
Operator * overload to return a reference to the actual resource.