YourGameLib
Loading...
Searching...
No Matches
Public Member Functions | List of all members
yourgame::util::AssetManager Class Reference

utility to store and request pointers, and to delete dynamically allocated objects, by name More...

#include <assetmanager.h>

Public Member Functions

 ~AssetManager ()
 
template<class T >
bool insert (std::string name, T *obj)
 insert pointer. if it exists (same type T and same name), previous object is deleted and the pointer is replaced. rejects nullptrs.
 
template<class T >
void insert (std::string name, T obj)
 dummy for compile-time check (static_assert) of non-pointer type
 
template<class T >
T * get (std::string name)
 request pointer by name
 
template<class T >
size_t numOf ()
 returns number of stored pointers of type T*
 
template<class T >
void destroy (std::string name)
 destroy (delete) object, remove pointer
 
template<class T >
void destroy ()
 destroy (delete) all objects of type T, remove all pointers of type T*
 
void clear ()
 clear content. delete all objects, remove all pointers
 

Detailed Description

utility to store and request pointers, and to delete dynamically allocated objects, by name

use like so:

Attention
type T is always the base type, not the pointer type (T*)
never delete objects manually with delete if they have been stored with insert()

Constructor & Destructor Documentation

◆ ~AssetManager()

yourgame::util::AssetManager::~AssetManager ( )
inline

Member Function Documentation

◆ clear()

void yourgame::util::AssetManager::clear ( )
inline

clear content. delete all objects, remove all pointers

◆ destroy() [1/2]

template<class T >
void yourgame::util::AssetManager::destroy ( )
inline

destroy (delete) all objects of type T, remove all pointers of type T*

Template Parameters
Tobject type

◆ destroy() [2/2]

template<class T >
void yourgame::util::AssetManager::destroy ( std::string  name)
inline

destroy (delete) object, remove pointer

Template Parameters
Tobject type
Parameters
namename

◆ get()

template<class T >
T * yourgame::util::AssetManager::get ( std::string  name)
inline

request pointer by name

Template Parameters
Tobject type
Parameters
namename
Returns
pointer. nullptr, if no pointer of type T* and name exists

◆ insert() [1/2]

template<class T >
bool yourgame::util::AssetManager::insert ( std::string  name,
T *  obj 
)
inline

insert pointer. if it exists (same type T and same name), previous object is deleted and the pointer is replaced. rejects nullptrs.

Attention
obj must be a pointer type
only insert pointer to object, that has been created with new
Template Parameters
Tobject type
Parameters
namename
objpointer
Returns
false, if obj was nullptr, true otherwise

◆ insert() [2/2]

template<class T >
void yourgame::util::AssetManager::insert ( std::string  name,
obj 
)
inline

dummy for compile-time check (static_assert) of non-pointer type

Template Parameters
Tobject type
Parameters
namename
objpointer

◆ numOf()

template<class T >
size_t yourgame::util::AssetManager::numOf ( )
inline

returns number of stored pointers of type T*

Template Parameters
Tobject type
Returns
number of stored pointers of type T*

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