#include <xrb_resourcelibrary.hpp>
Public Member Functions | |
Resource () | |
Default constructor. | |
Resource (ResourceLibrary::ResourceInstance< T > *const instance) | |
Constructs a Resource using the ResourceLibrary-tracked instance of the data. | |
Resource (Resource< T > const &source) | |
Copy constructor. | |
~Resource () | |
Destructor. | |
void | operator= (Resource< T > const &source) |
Assignment operator. | |
bool | operator== (Resource< T > const &operand) const |
Equality test operator. | |
bool | operator!= (Resource< T > const &operand) const |
Inequality test operator. | |
T const * | operator* () const |
Pointer dereferencing. | |
T const * | operator-> () const |
Pointer dereferencing. | |
bool | IsValid () const |
Returns true iff this Resource is referencing data. | |
std::string const & | Path () const |
Returns the path that the resourced data was loaded from. | |
Sint32 | LoadParameter () const |
Returns the load parameter that was used when loading the resourced data. | |
void | Release () |
Explicitly causes the reference count to decrement, causing this Resource to become invalid. |
Resource should be used as a normal, non-dynamically-allocated object, and can be assigned by value when making copies of the resource (though it should generally be passed by reference when used as a parameter in functions).
The assignment operator is overridden to provide intuitive and convenient cloning of resourced data. Assignment causes the reference count to increase, so that the newly assigned resource will remain valid as long as it is in scope.
A Resource object which has not been assigned an actual resource will be "invalid" and references to its data will cause an assert. IsValid queries the validity of a Resource object. Resources can be made "valid" simply by assigning to them the value of another Resource object or by assigning to them the return value of a call to Xrb::ResourceLibrary::LoadPath.
The Release method is provided to explicitly unload data. Once this is done, the object is "invalid".
Equality and inequality testing operators are provided, as well as accessors for the resource's path and load parameter.
Dereferencing is done in two ways. The unary * operator returns a pointer to the const resource data. The -> operator is used intuitively as if the resource object was the data pointer itself. You can call methods and reference members directly using the -> operator ( e.g. font_resource->PixelHeight()
). Dereferencing the Resource will assert if it is invalid.
Definition at line 307 of file xrb_resourcelibrary.hpp.
Xrb::Resource< T >::Resource | ( | ) | [inline] |
Default constructor.
Constructs an invalid resource (not referencing anything).
Definition at line 314 of file xrb_resourcelibrary.hpp.
Xrb::Resource< T >::Resource | ( | ResourceLibrary::ResourceInstance< T > *const | instance | ) | [inline] |
Constructs a Resource using the ResourceLibrary-tracked instance of the data.
You shouldn't use this constructor directly. It is used when loading already-loaded resources.
Definition at line 323 of file xrb_resourcelibrary.hpp.
Xrb::Resource< T >::Resource | ( | Resource< T > const & | source | ) | [inline] |
Copy constructor.
Resources constructed using the copy constructor cause the reference count to increment.
Definition at line 333 of file xrb_resourcelibrary.hpp.
Xrb::Resource< T >::~Resource | ( | ) | [inline] |
Destructor.
If the Resource is valid, the reference count is decremented, which causes the data to be unloaded if the count reaches zero.
Definition at line 343 of file xrb_resourcelibrary.hpp.
void Xrb::Resource< T >::operator= | ( | Resource< T > const & | source | ) | [inline] |
Assignment operator.
Resources assigned to using the assignment operator cause the reference count to increment.
Definition at line 356 of file xrb_resourcelibrary.hpp.
bool Xrb::Resource< T >::operator== | ( | Resource< T > const & | operand | ) | const [inline] |
Equality test operator.
Returns true iff the Resources reference the same data or they are both invalid.
Definition at line 369 of file xrb_resourcelibrary.hpp.
bool Xrb::Resource< T >::operator!= | ( | Resource< T > const & | operand | ) | const [inline] |
Inequality test operator.
Returns true iff the Resources do not reference the same data or if exactly one of them is invalid. both invalid.
Definition at line 378 of file xrb_resourcelibrary.hpp.
T const* Xrb::Resource< T >::operator* | ( | ) | const [inline] |
Pointer dereferencing.
Returns a pointer to the resourced data.
Definition at line 385 of file xrb_resourcelibrary.hpp.
T const* Xrb::Resource< T >::operator-> | ( | ) | const [inline] |
Pointer dereferencing.
Provides -> dereferencing syntax for the resourced data, e.g. font_resource->PixelHeight()
.
Definition at line 394 of file xrb_resourcelibrary.hpp.
bool Xrb::Resource< T >::IsValid | ( | ) | const [inline] |
Returns true iff this Resource is referencing data.
An invalid Resource can't be dereferenced or accessed for its path or load parameter.
Definition at line 404 of file xrb_resourcelibrary.hpp.
Referenced by Xrb::WidgetBackgroundStylized::Draw(), Xrb::WidgetBackgroundTextured::Draw(), Xrb::Label::Label(), Xrb::WidgetSkin::SetFont(), and Xrb::WidgetBackgroundStylized::WidgetBackgroundStylized().
std::string const& Xrb::Resource< T >::Path | ( | ) | const [inline] |
Returns the path that the resourced data was loaded from.
Asserts if this Resource is invalid.
Definition at line 411 of file xrb_resourcelibrary.hpp.
Sint32 Xrb::Resource< T >::LoadParameter | ( | ) | const [inline] |
Returns the load parameter that was used when loading the resourced data.
If this resource was loaded without a load parameter, then Xrb::ResourceLibrary::UNSPECIFIED_LOAD_PARAMETER will be returned.
Asserts if this Resource is invalid.
Definition at line 425 of file xrb_resourcelibrary.hpp.