Isle
Loading...
Searching...
No Matches
LegoContainer< T > Class Template Reference

Template container associating string names with object pointers, optional lifetime management. More...

#include <legocontainer.h>

Public Member Functions

 LegoContainer ()
 Default constructor, sets this container to own its elements. More...
 
virtual ~LegoContainer ()
 Destructor. More...
 
void Clear ()
 Remove and delete all mapped objects; preserves key strings. More...
 
T * Get (const char *p_name)
 Retrieve the element mapped to the given name, or nullptr if missing. More...
 
void Add (const char *p_name, T *p_value)
 Add an element mapped to the given name, replacing existing item if present. More...
 
void SetOwnership (LegoBool p_ownership)
 Set whether this container owns/deletes its objects (and name strings) on removal/destruction. More...
 

Protected Attributes

LegoBool m_ownership
 If TRUE, container owns objects and keys; else no cleanup on destruction. [AI]. More...
 
LegoContainerInfo< T > m_map
 Underlying map from name strings to objects. [AI]. More...
 

Detailed Description

template<class T>
class LegoContainer< T >

Template container associating string names with object pointers, optional lifetime management.

[AI]

Template Parameters
TObject type, used as pointer. [AI]

[AI] Manages a mapping from names (C-strings) to pointers to objects of type T. Supports adding, retrieving, and clearing objects, and can optionally manage the deletion of both key strings and mapped objects depending on m_ownership. Used for centrally managing game resources by name. [AI]

Definition at line 40 of file legocontainer.h.

Constructor & Destructor Documentation

◆ LegoContainer()

template<class T >
LegoContainer< T >::LegoContainer ( )
inline

Default constructor, sets this container to own its elements.

[AI]

[AI] By default, the container will delete objects and name strings when destroyed. [AI]

Definition at line 46 of file legocontainer.h.

◆ ~LegoContainer()

template<class T >
virtual LegoContainer< T >::~LegoContainer ( )
inlinevirtual

Destructor.

Cleans up all key strings and objects depending on ownership flag. [AI]

[AI] Iterates map and deletes both key string and object pointer. [AI]

Definition at line 52 of file legocontainer.h.

Member Function Documentation

◆ Add()

template<class T >
void LegoContainer< T >::Add ( const char *  p_name,
T *  p_value 
)
inline

Add an element mapped to the given name, replacing existing item if present.

[AI]

Parameters
p_nameName to map. Will be allocated/copied if new. [AI]
p_valuePointer to object to store. [AI]

[AI] If the key exists, the old object is deleted (if ownership is set). Key strings are managed by this container and freed in the destructor. [AI]

Definition at line 115 of file legocontainer.h.

◆ Clear()

template<class T >
void LegoContainer< T >::Clear ( )
inline

Remove and delete all mapped objects; preserves key strings.

[AI]

[AI] Iterates through the map, deleting objects (but not C-string keys) from memory. [AI]

Definition at line 74 of file legocontainer.h.

◆ Get()

template<class T >
T * LegoContainer< T >::Get ( const char *  p_name)
inline

Retrieve the element mapped to the given name, or nullptr if missing.

[AI]

Parameters
p_nameName of the element (C-string). [AI]
Returns
Pointer to the element if found, otherwise nullptr. [AI]

[AI] Looks up the map for the name (using comparator). [AI]

Definition at line 92 of file legocontainer.h.

◆ SetOwnership()

template<class T >
void LegoContainer< T >::SetOwnership ( LegoBool  p_ownership)
inline

Set whether this container owns/deletes its objects (and name strings) on removal/destruction.

[AI]

Parameters
p_ownershipIf TRUE, container owns the memory and is responsible for cleanup. [AI]

Definition at line 143 of file legocontainer.h.

Member Data Documentation

◆ m_map

template<class T >
LegoContainerInfo<T> LegoContainer< T >::m_map
protected

Underlying map from name strings to objects. [AI].

Definition at line 147 of file legocontainer.h.

◆ m_ownership

template<class T >
LegoBool LegoContainer< T >::m_ownership
protected

If TRUE, container owns objects and keys; else no cleanup on destruction. [AI].

Definition at line 146 of file legocontainer.h.


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