Wasabi
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
WManager< T > Class Template Referenceabstract

#include <WManager.hpp>

Public Member Functions

 WManager (class Wasabi *const a)
 
bool RegisterChangeCallback (std::string name, std::function< void(T *, bool)> callback)
 
void RemoveChangeCallback (std::string name)
 
void AddEntity (T *entity)
 
bool RemoveEntity (T *entity)
 
void OnEntityNameChanged (T *entity, std::string oldName)
 
virtual void Init ()
 
T * GetEntity (uint32_t ID) const
 
T * GetEntity (std::string name) const
 
T * GetEntityByIndex (uint32_t index) const
 
uint32_t GetEntitiesCount (void) const
 

Public Attributes

class Wasabi *const m_app
 

Protected Member Functions

virtual std::string GetTypeName () const =0
 

Protected Attributes

std::vector< T * > m_entities [W_HASHTABLESIZE]
 
std::unordered_map< std::string, T * > m_entitiesByName
 

Detailed Description

template<typename T>
class WManager< T >

A WManager is a template for a class that manages classes which inherit from a WBase. A manager has a list of all instances of the class that it manages, as long as the class makes sure it registers itself (usually in its constructor) and removes itself upon destruction (usually in its destructor).

Member Function Documentation

◆ AddEntity()

template<typename T>
void WManager< T >::AddEntity ( T *  entity)
inline

Registers an entity in the manager.

Parameters
entityPointer to the entity to register

◆ GetEntitiesCount()

template<typename T>
uint32_t WManager< T >::GetEntitiesCount ( void  ) const
inline

Retrieves the number of registered entities.

Returns
Number of registered entities

◆ GetEntity() [1/2]

template<typename T>
T* WManager< T >::GetEntity ( std::string  name) const
inline

Retrieves a registered entity using its name.

Parameters
nameName of the object to retrieve
Returns
The registered object, nullptr if its not found

◆ GetEntity() [2/2]

template<typename T>
T* WManager< T >::GetEntity ( uint32_t  ID) const
inline

Retrieves a registered entity using its ID.

Parameters
IDID of the registered object
Returns
The registered object, nullptr if its not found

◆ GetEntityByIndex()

template<typename T>
T* WManager< T >::GetEntityByIndex ( uint32_t  index) const
inline

Retrieves a registered entity using its index into the hashtable.

Parameters
indexIndex of the object to retrieve
Returns
The registered object, nullptr if its not found

◆ GetTypeName()

template<typename T>
virtual std::string WManager< T >::GetTypeName ( ) const
protectedpure virtual

This function must be implemented by a child class. It should return the name of the object that it is managing, which can be used for debugging purposes.

Returns
The name of the object being managed

◆ Init()

template<typename T>
virtual void WManager< T >::Init ( )
inlinevirtual

Initializes the manager.

Reimplemented in WRigidBodyManager.

◆ RegisterChangeCallback()

template<typename T>
bool WManager< T >::RegisterChangeCallback ( std::string  name,
std::function< void(T *, bool)>  callback 
)
inline

Registers a function to be called when an entity is added or removed

Parameters
nameName given to the callback, can be used to remove it (name must be unique)
callbackA function pointer, called when an entity is added (with the pointer to the entity and true as arguments) or removed (with the pointer to the entity and false as arguments)
Returns
True iff the callback was registered

◆ RemoveChangeCallback()

template<typename T>
void WManager< T >::RemoveChangeCallback ( std::string  name)
inline

Removes a callback previously registered by RegisterChangeCallback()

Parameters
nameCallback name passed to RegisterChangeCallback()

◆ RemoveEntity()

template<typename T>
bool WManager< T >::RemoveEntity ( T *  entity)
inline

De-registers an entity from the manager.

Parameters
entityEntity to de-register
Returns
true if the entity was found (and de-registered), false otherwise

Member Data Documentation

◆ m_app

template<typename T>
class Wasabi* const WManager< T >::m_app

Pointer to the Wasabi instance that made this manager

◆ m_entities

template<typename T>
std::vector<T*> WManager< T >::m_entities[W_HASHTABLESIZE]
protected

a hash table of all entities registered


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