ResourcePtr.inl
1
2//
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
29template <typename T>
31myResource(NULL)
32{
33
34}
35
36
40template <typename T>
42myResource(Resource)
43{
44 if (myResource)
45 myResource->Connect(*this);
46}
47
48
52template <typename T>
54myResource(Copy.myResource)
55{
56 if (myResource)
57 myResource->Connect(*this);
58}
59
60
64template <typename T>
66{
67 if (myResource)
68 myResource->Disconnect(*this);
69}
70
71
75template <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
93template <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
114template <typename T>
116{
117 return myResource;
118}
119
120
124template <typename T>
126{
127 return *myResource;
128}
129
130
134template <typename T>
136{
137 return myResource;
138}
139
145template <typename T>
147{
148 myResource = NULL;
149}
Safe pointer to a T resource (inheriting from sf::Resource<T>), its pointer is automatically reseted ...
Definition Resource.hpp:117
ResourcePtr()
Default constructor.
const T & operator*() const
Operator * overload to return a reference to the actual resource.
void OnResourceDestroyed()
Function called when the observed resource is about to be destroyed.
ResourcePtr< T > & operator=(const ResourcePtr< T > &Other)
Assignment operator from another ResourcePtr.
const T * operator->() const
Operator -> overload to return a pointer to the actual resource.
~ResourcePtr()
Destructor.
Base class for every resource that needs to notify dependent classes about its destruction.
Definition Resource.hpp:51