Cornell Cocos
Cornell Extensions to Cocos2d
Public Member Functions | Protected Attributes | List of all members
Loader< T > Class Template Reference

#include <CULoader.h>

Inheritance diagram for Loader< T >:
BaseLoader GenericLoader< T >

Public Member Functions

virtual bool contains (std::string key) const
 
virtual T * get (std::string key) const
 
T * operator[] (std::string key) const
 
virtual size_t loadCount () const override
 
virtual T * load (std::string key, std::string source)
 
- Public Member Functions inherited from BaseLoader
virtual void start ()
 
virtual void stop ()
 
bool isActive () const
 
virtual void loadAsync (std::string key, std::string source)
 
virtual void unload (std::string key)
 
virtual void unloadAll ()
 
virtual size_t waitCount () const
 
bool isComplete () const
 
float progress () const
 
CC_CONSTRUCTOR_ACCESS _active (false)
 
virtual ~BaseLoader ()
 

Protected Attributes

std::unordered_map< std::string, T * > _assets
 
- Protected Attributes inherited from BaseLoader
bool _active
 

Additional Inherited Members

- Public Attributes inherited from BaseLoader
CC_CONSTRUCTOR_ACCESS __pad0__: BaseLoader() : Ref()
 

Detailed Description

template<class T>
class Loader< T >

Type specific template for each loader.

This template works like a generic abstract class in Java. I provides some type correctness. It also provides some base functionality that is common for all loaders. Methods marked as abstract must be overriden in specific loader implementations.

All assets are assigned a key and retrieved via that key. This for a quick way to reference assets.

Member Function Documentation

template<class T>
virtual bool Loader< T >::contains ( std::string  key) const
inlinevirtual

Returns true if the key maps to a loaded asset.

This method is useful in case the asset fails to load.

Parameters
keythe key associated with the asset
Returns
True if the key maps to a loaded asset.

Reimplemented in GenericLoader< T >.

template<class T>
virtual T* Loader< T >::get ( std::string  key) const
inlinevirtual

Returns the asset for the given key.

If the key is valid, the asset is guaranteed not to be null. Otherwise, this method returns nullptr

Parameters
keythe key associated with the asset
Returns
the asset pointer for the given key

Reimplemented in GenericLoader< T >.

template<class T>
virtual T* Loader< T >::load ( std::string  key,
std::string  source 
)
inlinevirtual

Loads an asset and assigns it to the given key.

The asset will be loaded synchronously. It will be available immediately. This method should be limited to those times in which an asset is really necessary immediately, such as for a loading screen.

This method is abstract and should be overridden in the specific implementation for each asset.

Parameters
keyThe key to access the asset after loading
sourceThe pathname to the asset
Returns
the loaded asset

Reimplemented in GenericLoader< T >, FontLoader, TextureLoader, SoundLoader, and GenericBaseLoader.

template<class T>
virtual size_t Loader< T >::loadCount ( ) const
inlineoverridevirtual

Returns the number of assets currently loaded.

This is a rough way to determine how many assets have been loaded so far. This method counts each asset equally regardless of the memory requirements of each asset.

Returns
the number of assets currently loaded.

Reimplemented from BaseLoader.

Reimplemented in GenericLoader< T >.

template<class T>
T* Loader< T >::operator[] ( std::string  key) const
inline

Returns the asset for the given key.

If the key is valid, the asset is guaranteed not to be null. Otherwise, this method returns nullptr

Parameters
keythe key associated with the asset
Returns
the asset pointer for the given key

Member Data Documentation

template<class T>
std::unordered_map<std::string, T*> Loader< T >::_assets
protected

Hash map storing the loaded assets


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