ork::Resource Class Reference
[resource]

An abstract resource (texture, shader, mesh, etc). More...

#include <Resource.h>

Inheritance diagram for ork::Resource:
ork::ResourceTemplate< o, C >

List of all members.

Public Member Functions

 Resource (ptr< ResourceManager > manager, const string &name, ptr< ResourceDescriptor > desc)
 Creates a new Resource.
virtual ~Resource ()
 Deletes this resource.
virtual string getName ()
 Returns the name of this resource.
virtual int getUpdateOrder ()=0
 Returns the update order of this resource.
virtual bool prepareUpdate ()
 Prepares the update of this resource.
virtual void doUpdate (bool commit)=0
 Do an actual update of this resource, or reverts the work of prepareUpdate.
virtual bool changed ()
 Returns true if the descriptor of this resource has changed.

Static Public Member Functions

static void checkParameters (const ptr< ResourceDescriptor > desc, const TiXmlElement *e, const string &params)
 Utility method to check the attributes of an XML element.
static void getIntParameter (const ptr< ResourceDescriptor > desc, const TiXmlElement *e, const string &name, int *i)
 Utility method to get the int value of an XML element attribute.
static bool getFloatParameter (const ptr< ResourceDescriptor > desc, const TiXmlElement *e, const string &name, float *value)
 Utility method to get the float value of an XML element attribute.
static string getParameter (ptr< ResourceDescriptor > desc, const TiXmlElement *e, const char *name)
 Utility method to get the value of an XML element attribute.
static void log (ptr< Logger > logger, ptr< ResourceDescriptor > desc, const TiXmlElement *e, const string &msg)
 Logs a message related to a resource.
static void log (ptr< Logger > logger, const TiXmlElement *desc, const TiXmlElement *e, const string &msg)
 Logs a message related to a resource.

Protected Attributes

ptr< ResourceManagermanager
 The manager that keeps track of this resource.
const string name
 The name of this resource.
ptr< ResourceDescriptordesc
 The descriptor of this resource.
ptr< ResourceDescriptornewDesc
 The new value of the descriptor of this resource.

Detailed Description

An abstract resource (texture, shader, mesh, etc).


Constructor & Destructor Documentation

ork::Resource::Resource ( ptr< ResourceManager manager,
const string &  name,
ptr< ResourceDescriptor desc 
)

Creates a new Resource.

Parameters:
manager the manager that will keep track of this resource.
name the name of this resource.
desc the descriptor of this resource.
virtual ork::Resource::~Resource (  )  [virtual]

Deletes this resource.


Member Function Documentation

virtual bool ork::Resource::changed (  )  [virtual]

Returns true if the descriptor of this resource has changed.

Reimplemented in ork::ResourceTemplate< o, C >.

static void ork::Resource::checkParameters ( const ptr< ResourceDescriptor desc,
const TiXmlElement *  e,
const string &  params 
) [static]

Utility method to check the attributes of an XML element.

Parameters:
desc a resource descriptor.
e an element of the XML part of the resource descriptor desc.
params the authorized XML attributes for e, separated by commas.
Exceptions:
exception if e has an attribute which is not in the list specified by params.
virtual void ork::Resource::doUpdate ( bool  commit  )  [pure virtual]

Do an actual update of this resource, or reverts the work of prepareUpdate.

Parameters:
commit true to do the actual update, or false to revert the work prepareUpdate.

Implemented in ork::ResourceTemplate< o, C >.

static bool ork::Resource::getFloatParameter ( const ptr< ResourceDescriptor desc,
const TiXmlElement *  e,
const string &  name,
float *  value 
) [static]

Utility method to get the float value of an XML element attribute.

Parameters:
desc a resource descriptor.
e an element of the XML part of the resource descriptor desc.
name the attribute whose value must be returned.
[out] value the value of the requested attribute.
Exceptions:
exception if the attribute has a wrong format.
Returns:
false is the attribute is missing.
static void ork::Resource::getIntParameter ( const ptr< ResourceDescriptor desc,
const TiXmlElement *  e,
const string &  name,
int *  i 
) [static]

Utility method to get the int value of an XML element attribute.

Parameters:
desc a resource descriptor.
e an element of the XML part of the resource descriptor desc.
name the attribute whose value must be returned.
[out] i the value of the requested attribute.
Exceptions:
exception if the attribute is missing or has a wrong format.
virtual string ork::Resource::getName (  )  [virtual]

Returns the name of this resource.

static string ork::Resource::getParameter ( ptr< ResourceDescriptor desc,
const TiXmlElement *  e,
const char *  name 
) [static]

Utility method to get the value of an XML element attribute.

Parameters:
desc a resource descriptor.
e an element of the XML part of the resource descriptor desc.
name the attribute whose value must be returned.
Exceptions:
exception if the attribute is missing.
Returns:
the attribute's value.
virtual int ork::Resource::getUpdateOrder (  )  [pure virtual]

Returns the update order of this resource.

In order to be updated correctly a resource must be updated after the resource it depends on are updated. For instance a program must be updated after the shaders it is made of, which must themselves be updated after the textures they may depend on, and so on. This order is computed by sorting the resources according to their "update order" (0 means "update first").

Implemented in ork::ResourceTemplate< o, C >.

static void ork::Resource::log ( ptr< Logger logger,
const TiXmlElement *  desc,
const TiXmlElement *  e,
const string &  msg 
) [static]

Logs a message related to a resource.

Parameters:
logger the logger to be used to log the message.
desc the XML part of the descriptor of the resource.
e an optional element of the XML part of the resource descriptor.
msg the message to be logged.
static void ork::Resource::log ( ptr< Logger logger,
ptr< ResourceDescriptor desc,
const TiXmlElement *  e,
const string &  msg 
) [static]

Logs a message related to a resource.

Parameters:
logger the logger to be used to log the message.
desc the descriptor of the resource.
e an optional element of the XML part of the resource descriptor.
msg the message to be logged.
virtual bool ork::Resource::prepareUpdate (  )  [virtual]

Prepares the update of this resource.

In order to update all resources atomically (see ResourceManager::updateResources) a two phase commit is used. In the first phase all resources test if they can be updated successfully or not. If all resources can do so then they are all updated, otherwise none is updated. This method tests is a resource can be updated successfully. Returning true means that it is guaranteed that the actual update will not fail. NOTE: the default implementation of this method does not follow this contract. Indeed it returns true if the descriptor of this resource has changed. This method MUST therefore be overriden in subclasses of this class.

Returns:
true if it is guaranteed that a call doUpdate with a true parameter will not fail.

Reimplemented in ork::ResourceTemplate< o, C >.


Member Data Documentation

The descriptor of this resource.

The manager that keeps track of this resource.

May be NULL for an unused resource (see ResourceManager::releaseResource).

const string ork::Resource::name [protected]

The name of this resource.

The new value of the descriptor of this resource.

This field is set in the prepareUpdate method. If it is not NULL it means that the descriptor has changed, and the value is stored in this field. This field is set back to NULL in doUpdate.


Generated on Mon Oct 18 09:36:11 2010 for ork by  doxygen 1.6.1