Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Menge::Resource Class Referenceabstract

Basic class for managing on-disk resources. More...

#include <Resource.h>

Inheritance diagram for Menge::Resource:
Menge::Graph Menge::NavMesh Menge::NavMeshLocalizer Menge::VectorField

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
 

Detailed Description

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.

Constructor & Destructor Documentation

Menge::Resource::Resource ( const std::string &  fileName)
inline

Constructor.

This does not initialize the data structure. It merely registers the resource.

Parameters
fileNameThe path to the on-disk resource.

Member Function Documentation

int Menge::Resource::decRef ( )
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.

Returns
The number of remaining references.
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).

const std::string& Menge::Resource::getName ( ) const
inline

Return the file name for this resource.

Returns
The file name associated with this resource.
int Menge::Resource::incRef ( )
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.

Returns
The total number of references.
bool Menge::Resource::isUnreferenced ( ) const
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.

Returns
True if the underlying managed data is no longer referenced, false otherwise.

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