A template Resource class to ease the implementation of concrete Resource subclasses. More...
#include <ResourceTemplate.h>
Public Member Functions | |
ResourceTemplate (ptr< ResourceManager > manager, const string &name, ptr< ResourceDescriptor > desc) | |
Creates a new resource of class C. | |
virtual int | getUpdateOrder () |
Returns the template parameter o. | |
virtual bool | prepareUpdate () |
If the descriptor of this method has not changed, does nothing and returns true. | |
virtual void | doUpdate (bool commit) |
If commit is true swaps the desc and newDesc fields, and sets the oldValue to NULL. | |
virtual bool | changed () |
Returns true if this resource has changed. | |
Protected Member Functions | |
virtual void | doRelease () |
Calls ResourceManager::releaseResource to release this resource. | |
Protected Attributes | |
ptr< C > | oldValue |
The old value of this resource. |
A template Resource class to ease the implementation of concrete Resource subclasses.
This template class takes care of the two phase commit for the update of resources, provided that the actual resource class implements a swap(ptr<C>) method that can swap two instances of resources of class C.
o | the update order of resources of class C (see getUpdateOrder). | |
C | the concrete resource class. |
ork::ResourceTemplate< o, C >::ResourceTemplate | ( | ptr< ResourceManager > | manager, | |
const string & | name, | |||
ptr< ResourceDescriptor > | desc | |||
) | [inline] |
Creates a new resource of class C.
manager | the manager that will keep track of this resource. | |
name | the name of this resource. | |
desc | the descriptor of this resource. |
bool ork::ResourceTemplate< o, C >::changed | ( | ) | [inline, virtual] |
Returns true if this resource has changed.
Reimplemented from ork::Resource.
void ork::ResourceTemplate< o, C >::doRelease | ( | ) | [inline, protected, virtual] |
Calls ResourceManager::releaseResource to release this resource.
void ork::ResourceTemplate< o, C >::doUpdate | ( | bool | commit | ) | [inline, virtual] |
If commit is true swaps the desc and newDesc fields, and sets the oldValue to NULL.
If commit is false reverts the changes made in prepareUpdate by swapping again this instance with oldValue.
Implements ork::Resource.
int ork::ResourceTemplate< o, C >::getUpdateOrder | ( | ) | [inline, virtual] |
Returns the template parameter o.
Implements ork::Resource.
bool ork::ResourceTemplate< o, C >::prepareUpdate | ( | ) | [inline, virtual] |
If the descriptor of this method has not changed, does nothing and returns true.
Otherwise creates a new instance of this resource using the new descriptor newDesc and then swaps it with this instance, saving the current value in oldValue. If the resource creation fails, does nothing and returns false.
Reimplemented from ork::Resource.
ptr<C> ork::ResourceTemplate< o, C >::oldValue [protected] |
The old value of this resource.