Safe pointer to a sf::Resource<T>. More...
#include <Resource.hpp>
Public Member Functions | |
ResourcePtr () | |
Default constructor. | |
ResourcePtr (const T *resource) | |
Construct from a raw pointer. | |
ResourcePtr (const ResourcePtr< T > ©) | |
Copy constructor. | |
~ResourcePtr () | |
Destructor. | |
ResourcePtr< T > & | operator= (const ResourcePtr< T > &other) |
Assignment operator for a ResourcePtr parameter. | |
ResourcePtr< T > & | operator= (const T *resource) |
Assignment operator for a raw pointer parameter. | |
operator const T * () const | |
Cast operator to implicitely convert the resource pointer to its raw pointer type (T*). | |
const T & | operator* () const |
Overload of unary operator *. | |
const T * | operator-> () const |
Overload of operator ->. | |
void | OnResourceDestroyed () |
Function called when the observed resource is about to be destroyed. |
Safe pointer to a sf::Resource<T>.
sf::ResourcePtr is a special kind of smart pointer for resources.
Its main feature is to automatically reset its internal pointer to 0 when the resource gets destroyed, so that pointers to a resource never become invalid when the resource is destroyed. Instead, it properly returns 0 when the resource no longer exists.
Its usage is completely transparent, so that it is similar to manipulating the raw resource directly (like any smart pointer).
For sf::ResourcePtr<T> to work, T must inherit from the sf::Resource class.
These two classes are heavily used internally in SFML to safely handle resources and the classes that use them:
sf::Resource and sf::ResourcePtr are designed for internal use, but if you feel like they would fit well in your implementation there's no problem to use them.
Definition at line 126 of file Resource.hpp.
sf::ResourcePtr< T >::ResourcePtr | ( | ) |
Default constructor.
A default constructed ResourcePtr is empty (null).
sf::ResourcePtr< T >::ResourcePtr | ( | const T * | resource | ) |
Construct from a raw pointer.
resource | Raw pointer to the resource to wrap |
sf::ResourcePtr< T >::ResourcePtr | ( | const ResourcePtr< T > & | copy | ) |
Copy constructor.
The new ResourcePtr will share the same resource as copy.
copy | Instance to copy |
sf::ResourcePtr< T >::~ResourcePtr | ( | ) |
Destructor.
void sf::ResourcePtr< T >::OnResourceDestroyed | ( | ) |
Function called when the observed resource is about to be destroyed.
This functions is called by the destructor of the pointed resource. It allows this instance to reset its internal pointer when the resource is destroyed, and avoid dangling pointers.
sf::ResourcePtr< T >::operator const T * | ( | ) | const |
Cast operator to implicitely convert the resource pointer to its raw pointer type (T*).
This might be dangerous in the general case, but in this context it is safe enough to define this operator.
const T& sf::ResourcePtr< T >::operator* | ( | ) | const |
Overload of unary operator *.
Like raw pointers, applying the * operator returns a reference to the pointed object.
const T* sf::ResourcePtr< T >::operator-> | ( | ) | const |
Overload of operator ->.
Like raw pointers, applying the -> operator returns the pointed object.
ResourcePtr<T>& sf::ResourcePtr< T >::operator= | ( | const T * | resource | ) |
Assignment operator for a raw pointer parameter.
resource | Resource to assign |
ResourcePtr<T>& sf::ResourcePtr< T >::operator= | ( | const ResourcePtr< T > & | other | ) |
Assignment operator for a ResourcePtr parameter.
other | ResourcePtr to assign |