Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

ModelPool Class Reference

This is the preferred interface for loading models. More...

#include <modelPool.h>

List of all members.

Static Public Member Functions

bool has_model (const string &filename)
 Returns true if the model has ever been loaded, false otherwise.

bool verify_model (const string &filename)
 Loads the given filename up as a model, if it has not already been loaded, and returns true to indicate success, or false to indicate failure.

PandaNodeload_model (const string &filename)
 Loads the given filename up as a model, if it has not already been loaded, and returns the new model.

void add_model (const string &filename, PandaNode *model)
 Adds the indicated already-loaded model to the pool.

void release_model (const string &filename)
 Removes the indicated model from the pool, indicating it will never be loaded again; the model may then be freed.

void release_all_models ()
 Releases all models in the pool and restores the pool to the empty state.

int garbage_collect ()
 Releases only those models in the pool that have a reference count of exactly 1; i.e.

void list_contents (ostream &out)
 Lists the contents of the model pool to the indicated output stream.


Private Types

typedef pmap< string, PointerTo<
PandaNode > > 
Models

Private Member Functions

 ModelPool ()
 The constructor is not intended to be called directly; there's only supposed to be one ModelPool in the universe and it constructs itself.

bool ns_has_model (const string &filename)
 The nonstatic implementation of has_model().

PandaNodens_load_model (const string &filename)
 The nonstatic implementation of load_model().

void ns_add_model (const string &filename, PandaNode *model)
 The nonstatic implementation of add_model().

void ns_release_model (const string &filename)
 The nonstatic implementation of release_model().

void ns_release_all_models ()
 The nonstatic implementation of release_all_models().

int ns_garbage_collect ()
 The nonstatic implementation of garbage_collect().

void ns_list_contents (ostream &out)
 The nonstatic implementation of list_contents().


Static Private Member Functions

ModelPool * get_ptr ()
 Initializes and/or returns the global pointer to the one ModelPool object in the system.


Private Attributes

Models _models

Static Private Attributes

ModelPool * _global_ptr = (ModelPool *)NULL


Detailed Description

This is the preferred interface for loading models.

It unifies all references to the same filename, so that multiple attempts to load the same model will return the same pointer. Note that the default behavior is thus to make instances: use with caution. Use the copy_subgraph() method on Node (or use NodePath::copy_to) to make modifiable copies of the node.

Unlike TexturePool, this class does not automatically resolve the model filenames before loading, so a relative path and an absolute path to the same model will appear to be different filenames.

This does not presently support asynchronous loading, although it wouldn't be *too* difficult to add.

Definition at line 70 of file modelPool.h.


Member Typedef Documentation

typedef pmap<string, PointerTo< PandaNode > > ModelPool::Models [private]
 

Definition at line 98 of file modelPool.h.


Constructor & Destructor Documentation

ModelPool::ModelPool  )  [inline, private]
 

The constructor is not intended to be called directly; there's only supposed to be one ModelPool in the universe and it constructs itself.

Definition at line 184 of file modelPool.I.


Member Function Documentation

void ModelPool::add_model const string &  filename,
PandaNode model
[inline, static]
 

Adds the indicated already-loaded model to the pool.

The model will always replace any previously-loaded model in the pool that had the same filename.

Definition at line 97 of file modelPool.I.

References get_ptr(), INLINE, and ns_garbage_collect().

int ModelPool::garbage_collect  )  [inline, static]
 

Releases only those models in the pool that have a reference count of exactly 1; i.e.

only those models that are not being used outside of the pool. Returns the number of models released.

Definition at line 152 of file modelPool.I.

ModelPool * ModelPool::get_ptr  )  [static, private]
 

Initializes and/or returns the global pointer to the one ModelPool object in the system.

Definition at line 184 of file modelPool.cxx.

Referenced by add_model(), load_model(), and release_model().

bool ModelPool::has_model const string &  filename  )  [inline, static]
 

Returns true if the model has ever been loaded, false otherwise.

Definition at line 34 of file modelPool.I.

References INLINE, load_model(), and NULL.

void ModelPool::list_contents ostream &  out  )  [inline, static]
 

Lists the contents of the model pool to the indicated output stream.

Definition at line 167 of file modelPool.I.

PandaNode * ModelPool::load_model const string &  filename  )  [inline, static]
 

Loads the given filename up as a model, if it has not already been loaded, and returns the new model.

If a model with the same filename was previously loaded, returns that one instead. If the model file cannot be found, returns NULL.

Definition at line 78 of file modelPool.I.

References get_ptr(), INLINE, and ns_release_model().

Referenced by has_model().

void ModelPool::ns_add_model const string &  filename,
PandaNode model
[private]
 

The nonstatic implementation of add_model().

Definition at line 89 of file modelPool.cxx.

References _models.

int ModelPool::ns_garbage_collect  )  [private]
 

The nonstatic implementation of garbage_collect().

Definition at line 133 of file modelPool.cxx.

References _models.

Referenced by add_model().

bool ModelPool::ns_has_model const string &  filename  )  [private]
 

The nonstatic implementation of has_model().

Definition at line 40 of file modelPool.cxx.

void ModelPool::ns_list_contents ostream &  out  )  [private]
 

The nonstatic implementation of list_contents().

Definition at line 164 of file modelPool.cxx.

Referenced by release_model().

PandaNode * ModelPool::ns_load_model const string &  filename  )  [private]
 

The nonstatic implementation of load_model().

Definition at line 60 of file modelPool.cxx.

References model_loader, and NULL.

void ModelPool::ns_release_all_models  )  [private]
 

The nonstatic implementation of release_all_models().

Definition at line 120 of file modelPool.cxx.

void ModelPool::ns_release_model const string &  filename  )  [private]
 

The nonstatic implementation of release_model().

Definition at line 103 of file modelPool.cxx.

References _models.

Referenced by load_model().

void ModelPool::release_all_models  )  [inline, static]
 

Releases all models in the pool and restores the pool to the empty state.

Definition at line 133 of file modelPool.I.

void ModelPool::release_model const string &  filename  )  [inline, static]
 

Removes the indicated model from the pool, indicating it will never be loaded again; the model may then be freed.

If this function is never called, a reference count will be maintained on every model every loaded, and models will never be freed.

Definition at line 118 of file modelPool.I.

References get_ptr(), and ns_list_contents().

bool ModelPool::verify_model const string &  filename  )  [inline, static]
 

Loads the given filename up as a model, if it has not already been loaded, and returns true to indicate success, or false to indicate failure.

If this returns true, it is guaranteed that a subsequent call to load_model() with the same model name will return a valid Node pointer.

Definition at line 57 of file modelPool.I.


Member Data Documentation

ModelPool * ModelPool::_global_ptr = (ModelPool *)NULL [static, private]
 

Definition at line 27 of file modelPool.cxx.

Models ModelPool::_models [private]
 

Definition at line 99 of file modelPool.h.

Referenced by ns_add_model(), ns_garbage_collect(), and ns_release_model().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:52:14 2003 for Panda by doxygen1.3