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>
30ResourcePtr<T>::ResourcePtr() :
31myResource(NULL)
32{
33
34}
35
36
40template <typename T>
41ResourcePtr<T>::ResourcePtr(const T* Resource) :
42myResource(Resource)
43{
44 if (myResource)
45 myResource->Connect(*this);
46}
47
48
52template <typename T>
53ResourcePtr<T>::ResourcePtr(const ResourcePtr<T>& Copy) :
54myResource(Copy.myResource)
55{
56 if (myResource)
57 myResource->Connect(*this);
58}
59
60
64template <typename T>
65ResourcePtr<T>::~ResourcePtr()
66{
67 if (myResource)
68 myResource->Disconnect(*this);
69}
70
71
75template <typename T>
76ResourcePtr<T>& ResourcePtr<T>::operator =(const ResourcePtr<T>& Other)
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>
94ResourcePtr<T>& ResourcePtr<T>::operator =(const T* Resource)
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>
115ResourcePtr<T>::operator const T*() const
116{
117 return myResource;
118}
119
120
124template <typename T>
125const T& ResourcePtr<T>::operator *() const
126{
127 return *myResource;
128}
129
130
134template <typename T>
135const T* ResourcePtr<T>::operator ->() const
136{
137 return myResource;
138}
139
140
145template <typename T>
146void ResourcePtr<T>::OnResourceDestroyed()
147{
148 myResource = NULL;
149}