Om  1.0.0
A universal framework for multimedia simulation
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
om::resources::Resource< DataType > Class Template Reference

A class that encapsulates a handle to resource data. More...

#include <omResource.h>

Public Types

typedef lang::Function< lang::Shared< DataType > const ResourceID &) > LoadCallback
 Define the type for a resource loading callback function. More...
 

Public Member Functions

 Resource ()
 Create a new default resource with no data and no resource identifier or loader. More...
 
 Resource (const lang::Shared< DataType > &newData)
 Create a new resource for the specified data pointer. More...
 
 Resource (const lang::Shared< DataType > &newData, const ResourceID &newIdentifier)
 Create a new resource for the specified data that is associated with the specified unique identifier. More...
 
 Resource (const ResourceID &newIdentifier)
 Create a new resource for the specified unique resource identifier. More...
 
 Resource (const ResourceID &newIdentifier, const LoadCallback &newLoadCallback)
 Create a new resource for the specified unique resource identifier using the specified loader object. More...
 
 Resource (const Resource &other)
 
 ~Resource ()
 
Resourceoperator= (const Resource &other)
 
Bool operator== (const Resource &other) const
 Return whether or not this resource refers to the same resource as another. More...
 
Bool operator!= (const Resource &other) const
 Return whether or not this resource refers to a different resource than another. More...
 
lang::Shared< DataType > getData () const
 Return a pointer to the data associated with this resource. More...
 
void setData (const lang::Shared< DataType > &newData)
 Set a pointer to the data associated with this resource. More...
 
DataType * getPointer () const
 Return a pointer to the data associated with this resource. More...
 
 operator DataType * () const
 Cast this Resource object to a raw pointer. More...
 
template<typename U >
 operator U * () const
 Cast this Resource object to a raw pointer of a different type to allow polymorphism. More...
 
 operator lang::Shared< DataType > () const
 Cast this Resource object to a reference-counted pointer. More...
 
DataType & operator* () const
 Return a reference to the data associated with this resource. More...
 
DataType * operator-> () const
 Return a pointer to the data associated with this resource. More...
 
Bool hasID () const
 Return whether or not this resource has a unique identifier associated with it. More...
 
ResourceIDgetID () const
 Return a pointer to the unique identifier associated with this resource. More...
 
void setID (const ResourceID &newID)
 Set the unique identifier associated with this resource. More...
 
const data::UTF8StringgetName () const
 Return a pointer to the name associated with this resource. More...
 
void setName (const data::UTF8String &newName)
 Set the name associated with this resource. More...
 
Bool hadLoadCallback () const
 Return whether or not this resource has a ResourceLoader object associated with it. More...
 
const LoadCallbackgetLoadCallback () const
 Return a pointer to the resource loading callback function associated with this resource. More...
 
void setLoadCallback (const LoadCallback &newLoadCallback)
 Set the resource loading callback function associated with this resource. More...
 
Bool load () const
 Attempt to load the data for this resource if necessary. More...
 
void release ()
 Release the data assoicated with this resource, but keep the same resource ID and loader. More...
 
Bool isNull () const
 Return whether or not the data associated with this resource is currently NULL. More...
 
Bool isSet () const
 Return whether or not the data associated with this resource is currently set. More...
 
Size getReferenceCount () const
 Return the number of shared references that there are to this resource's data. More...
 

Static Public Member Functions

static Resource construct ()
 Construct a resource object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 >
static Resource construct (P1 p1)
 Construct a resource object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 , typename P2 >
static Resource construct (P1 p1, P2 p2)
 Construct a resource object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 , typename P2 , typename P3 >
static Resource construct (P1 p1, P2 p2, P3 p3)
 Construct a resource object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 , typename P2 , typename P3 , typename P4 >
static Resource construct (P1 p1, P2 p2, P3 p3, P4 p4)
 Construct a resource object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 >
static Resource construct (P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
 Construct a resource object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6 >
static Resource construct (P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
 Construct a resource object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6 , typename P7 >
static Resource construct (P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
 Construct a resource object of the templated type with the specified arguments for its constructor. More...
 

Detailed Description

template<typename DataType>
class om::resources::Resource< DataType >

A class that encapsulates a handle to resource data.

The class allows the user to either load the resource data manually, or to provide a unique identifier and ResourceLoader object to defer loading the resource until it is needed.

Member Typedef Documentation

template<typename DataType>
typedef lang::Function< lang::Shared<DataType> const ResourceID& ) > om::resources::Resource< DataType >::LoadCallback

Define the type for a resource loading callback function.

Constructor & Destructor Documentation

template<typename DataType>
om::resources::Resource< DataType >::Resource ( )
inline

Create a new default resource with no data and no resource identifier or loader.

The created resource is essentially unuseable and can be used to indicate an invalid resource or a resource that has not yet been set.

template<typename DataType>
om::resources::Resource< DataType >::Resource ( const lang::Shared< DataType > &  newData)
inline

Create a new resource for the specified data pointer.

If the specified data pointer is NULL, the resource is unusable because it has no way to load any data for the resource.

template<typename DataType>
om::resources::Resource< DataType >::Resource ( const lang::Shared< DataType > &  newData,
const ResourceID newIdentifier 
)
inline

Create a new resource for the specified data that is associated with the specified unique identifier.

If the specified data pointer is NULL, the resource is unusable because it has no way to load the resource associated with the given ID.

template<typename DataType>
om::resources::Resource< DataType >::Resource ( const ResourceID newIdentifier)
inline

Create a new resource for the specified unique resource identifier.

template<typename DataType>
om::resources::Resource< DataType >::Resource ( const ResourceID newIdentifier,
const LoadCallback newLoadCallback 
)
inline

Create a new resource for the specified unique resource identifier using the specified loader object.

A resource created using this constructor will lazily load the resource when it is first dereferenced. The specified ID is used to load the resource using the given ResourceLoader object. If the loader object pointer is NULL, the new resource will be useless because it has no way to load any data for the resource.

template<typename DataType>
om::resources::Resource< DataType >::Resource ( const Resource< DataType > &  other)
inline
template<typename DataType>
om::resources::Resource< DataType >::~Resource ( )
inline

Member Function Documentation

template<typename DataType>
Resource& om::resources::Resource< DataType >::operator= ( const Resource< DataType > &  other)
inline
template<typename DataType>
Bool om::resources::Resource< DataType >::operator== ( const Resource< DataType > &  other) const
inline

Return whether or not this resource refers to the same resource as another.

This operator returns TRUE if the data pointer they refer to is equal, or if they both have the same resource identifier/loader. Otherwise FALSE is returned.

template<typename DataType>
Bool om::resources::Resource< DataType >::operator!= ( const Resource< DataType > &  other) const
inline

Return whether or not this resource refers to a different resource than another.

This operator returns FALSE if the data pointer they refer to is equal, or if they both have the same resource identifier/loader. Otherwise TRUE is returned.

template<typename DataType>
lang::Shared<DataType> om::resources::Resource< DataType >::getData ( ) const
inline

Return a pointer to the data associated with this resource.

The method can return NULL if the resource's data has not yet been loaded.

template<typename DataType>
void om::resources::Resource< DataType >::setData ( const lang::Shared< DataType > &  newData)
inline

Set a pointer to the data associated with this resource.

template<typename DataType>
DataType* om::resources::Resource< DataType >::getPointer ( ) const
inline

Return a pointer to the data associated with this resource.

The method can return NULL if the resource's data has not yet been loaded.

template<typename DataType>
om::resources::Resource< DataType >::operator DataType * ( ) const
inline

Cast this Resource object to a raw pointer.

template<typename DataType>
template<typename U >
om::resources::Resource< DataType >::operator U * ( ) const
inline

Cast this Resource object to a raw pointer of a different type to allow polymorphism.

template<typename DataType>
om::resources::Resource< DataType >::operator lang::Shared< DataType > ( ) const
inline

Cast this Resource object to a reference-counted pointer.

template<typename DataType>
DataType& om::resources::Resource< DataType >::operator* ( ) const
inline

Return a reference to the data associated with this resource.

This operator dereferences the data for the resource. If the data pointer is currently NULL, the resource attempts to use the associated resource loader to load the resource data. An assertion is raised if there is no identifier or loader for the resource if the data is NULL.

template<typename DataType>
DataType* om::resources::Resource< DataType >::operator-> ( ) const
inline

Return a pointer to the data associated with this resource.

This operator dereferences the data for the resource. If the data pointer is currently NULL, the resource attempts to use the associated resource loader to load the resource data. An assertion is raised if there is no identifier or loader for the resource if the data is NULL.

template<typename DataType>
Bool om::resources::Resource< DataType >::hasID ( ) const
inline

Return whether or not this resource has a unique identifier associated with it.

template<typename DataType>
ResourceID* om::resources::Resource< DataType >::getID ( ) const
inline

Return a pointer to the unique identifier associated with this resource.

If the resource has no identifier associated with it, NULL is returned.

template<typename DataType>
void om::resources::Resource< DataType >::setID ( const ResourceID newID)
inline

Set the unique identifier associated with this resource.

template<typename DataType>
const data::UTF8String* om::resources::Resource< DataType >::getName ( ) const
inline

Return a pointer to the name associated with this resource.

template<typename DataType>
void om::resources::Resource< DataType >::setName ( const data::UTF8String newName)
inline

Set the name associated with this resource.

template<typename DataType>
Bool om::resources::Resource< DataType >::hadLoadCallback ( ) const
inline

Return whether or not this resource has a ResourceLoader object associated with it.

template<typename DataType>
const LoadCallback* om::resources::Resource< DataType >::getLoadCallback ( ) const
inline

Return a pointer to the resource loading callback function associated with this resource.

If the resource has no callback function associated with it, NULL is returned.

template<typename DataType>
void om::resources::Resource< DataType >::setLoadCallback ( const LoadCallback newLoadCallback)
inline

Set the resource loading callback function associated with this resource.

If the resource has no callback function associated with it, an assertion is raised.

template<typename DataType>
Bool om::resources::Resource< DataType >::load ( ) const
inline

Attempt to load the data for this resource if necessary.

This method tries to ensure that the resource data is loaded and available for use. If the data is already loaded, the method returns TRUE. Otherwise, the method loads the data using the resource's ID and loader object and returns TRUE. If there is no loader or ID for this resource, FALSE is returned, indicating that the resource was unable to be loaded.

template<typename DataType>
void om::resources::Resource< DataType >::release ( )
inline

Release the data assoicated with this resource, but keep the same resource ID and loader.

This method just releases the reference to the data. If other resource objects reference the same data, the data is not deallocated until they all release their data.

template<typename DataType>
Bool om::resources::Resource< DataType >::isNull ( ) const
inline

Return whether or not the data associated with this resource is currently NULL.

The data can be NULL if the resource has not yet been loaded, or if the resource is itself invalid.

template<typename DataType>
Bool om::resources::Resource< DataType >::isSet ( ) const
inline

Return whether or not the data associated with this resource is currently set.

The data can be NULL if the resource has not yet been loaded, or if the resource is itself invalid.

template<typename DataType>
Size om::resources::Resource< DataType >::getReferenceCount ( ) const
inline

Return the number of shared references that there are to this resource's data.

If the returned value is 1, this means that this resource is the only object which owns the data associated with it.

template<typename DataType>
static Resource om::resources::Resource< DataType >::construct ( )
inlinestatic

Construct a resource object of the templated type with the specified arguments for its constructor.

template<typename DataType>
template<typename P1 >
static Resource om::resources::Resource< DataType >::construct ( P1  p1)
inlinestatic

Construct a resource object of the templated type with the specified arguments for its constructor.

template<typename DataType>
template<typename P1 , typename P2 >
static Resource om::resources::Resource< DataType >::construct ( P1  p1,
P2  p2 
)
inlinestatic

Construct a resource object of the templated type with the specified arguments for its constructor.

template<typename DataType>
template<typename P1 , typename P2 , typename P3 >
static Resource om::resources::Resource< DataType >::construct ( P1  p1,
P2  p2,
P3  p3 
)
inlinestatic

Construct a resource object of the templated type with the specified arguments for its constructor.

template<typename DataType>
template<typename P1 , typename P2 , typename P3 , typename P4 >
static Resource om::resources::Resource< DataType >::construct ( P1  p1,
P2  p2,
P3  p3,
P4  p4 
)
inlinestatic

Construct a resource object of the templated type with the specified arguments for its constructor.

template<typename DataType>
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 >
static Resource om::resources::Resource< DataType >::construct ( P1  p1,
P2  p2,
P3  p3,
P4  p4,
P5  p5 
)
inlinestatic

Construct a resource object of the templated type with the specified arguments for its constructor.

template<typename DataType>
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6 >
static Resource om::resources::Resource< DataType >::construct ( P1  p1,
P2  p2,
P3  p3,
P4  p4,
P5  p5,
P6  p6 
)
inlinestatic

Construct a resource object of the templated type with the specified arguments for its constructor.

template<typename DataType>
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6 , typename P7 >
static Resource om::resources::Resource< DataType >::construct ( P1  p1,
P2  p2,
P3  p3,
P4  p4,
P5  p5,
P6  p6,
P7  p7 
)
inlinestatic

Construct a resource object of the templated type with the specified arguments for its constructor.


The documentation for this class was generated from the following file: