Menge
Modular Pedestrian Simulation Framework for Research and Development
|
Basic class for managing on-disk resources. More...
#include <Resource.h>
Public Member Functions | |
Resource (const std::string &fileName) | |
Constructor. More... | |
void | destroy () |
This supplants the destructor. More... | |
const std::string & | getName () const |
Return the file name for this resource. More... | |
int | incRef () |
Increment references to the managed data. More... | |
int | decRef () |
Decrement references to the managed data. More... | |
bool | isUnreferenced () const |
Reports if the data is referenced. More... | |
virtual const std::string & | getLabel () const =0 |
Returns a unique resource label to be used to identify different resource types which use the same underlying file data. | |
Protected Member Functions | |
virtual | ~Resource () |
Virtual destructor. | |
Protected Attributes | |
const std::string | _fileName |
The file which contains the resource's data. | |
int | _refCount |
The number of data wrappers using this managed data. | |
SimpleLock | _lock |
Simple lock to handle reference counts safely. | |
Friends | |
class | ResourceManager |
Basic class for managing on-disk resources.
This is for data structures that are defined in files but may be used by multiple entities. This prevents unnecessary loading and duplication and allows for centralized memory management.
|
inline |
Constructor.
This does not initialize the data structure. It merely registers the resource.
fileName | The path to the on-disk resource. |
|
inline |
Decrement references to the managed data.
Any object that carries a pointer to managed data should call this function upon destruction (thereby removing its reference from the managed data's reference count.
void Menge::Resource::destroy | ( | ) |
This supplants the destructor.
In order to preserve potential problems in windows when dlls do not share the same c-runtime library, the destructor is held to be private. To garbage collect a Resource, the destroy method should be called (which in turn, will call the destructor from its own memory space, averting run-time crashes).
Once this has been called, the Resource no longer exists. Calling methods or accessing members will produce indetermine behavior (most likely errors).
|
inline |
Return the file name for this resource.
|
inline |
Increment references to the managed data.
Any object that carries a pointer to managed data should call this function when acquiring and storing a pointer to that data.
|
inline |
Reports if the data is referenced.
Any object that carries a pointer to managed data, after dereferencing itself upon destruction, should determine if it is no longer referenced and delete the object if this function returns true. NOTE: this is not thread-safe.