Smolgui
Immediate gui library based on SFML
Loading...
Searching...
No Matches
sgui::ObjectPool< Object, ObjectId > Class Template Reference

: implement a generic pool of objects that are stored continuously in memory without fragmentation, and is in theory thread safe More...

#include <ObjectPool.h>

Public Member Functions

 ObjectPool ()=default
 ObjectPool (ObjectPool< Object, ObjectId > &&rhs)
 ObjectPool (const ObjectPool< Object, ObjectId > &rhs)
ObjectPooloperator= (ObjectPool< Object, ObjectId > &&rhs)
ObjectPooloperator= (const ObjectPool< Object, ObjectId > &rhs)
Object & add (Object &&object, const ObjectId &id)
 Add object in pool.
Object & add (const Object &object, const ObjectId &id)
template<typename... ObjectArgs>
Object & emplace (const ObjectId &id, ObjectArgs &&... constructorArgs)
 Build a new object in pool.
void remove (const ObjectId &object)
 Remove a specific object from pool.
void reserve (const size_t amount)
 Reserve some amount of memory.
void clear ()
 Clear data in object pool.
bool has (const ObjectId &object) const
 Test if an object exists in pool.
bool empty () const
 Test if pool is empty.
Object & get (const ObjectId &object)
 Get oject in pool.
const Object & get (const ObjectId &object) const
void changeId (const ObjectId &oldId, const ObjectId &newId)
 Change id of a stored object.
std::vector< ObjectId > ids () const
 Get list of all identifiers used to store object.
size_t size () const
 Get count of pooled objects.
auto begin ()
auto end ()
auto begin () const
auto end () const

Detailed Description

template<typename Object, typename ObjectId = uint32_t>
class sgui::ObjectPool< Object, ObjectId >

: implement a generic pool of objects that are stored continuously in memory without fragmentation, and is in theory thread safe

Constructor & Destructor Documentation

◆ ObjectPool() [1/3]

template<typename Object, typename ObjectId = uint32_t>
sgui::ObjectPool< Object, ObjectId >::ObjectPool ( )
default

Big five

◆ ObjectPool() [2/3]

template<typename Object, typename ObjectId = uint32_t>
sgui::ObjectPool< Object, ObjectId >::ObjectPool ( ObjectPool< Object, ObjectId > && rhs)

◆ ObjectPool() [3/3]

template<typename Object, typename ObjectId = uint32_t>
sgui::ObjectPool< Object, ObjectId >::ObjectPool ( const ObjectPool< Object, ObjectId > & rhs)

Member Function Documentation

◆ add() [1/2]

template<typename Object, typename ObjectId = uint32_t>
Object & sgui::ObjectPool< Object, ObjectId >::add ( const Object & object,
const ObjectId & id )

◆ add() [2/2]

template<typename Object, typename ObjectId = uint32_t>
Object & sgui::ObjectPool< Object, ObjectId >::add ( Object && object,
const ObjectId & id )

Add object in pool.

Parameters
objectObject to be added
idIdentifier that will serve to retrieve object

◆ begin() [1/2]

template<typename Object, typename ObjectId = uint32_t>
auto sgui::ObjectPool< Object, ObjectId >::begin ( )
inline

To iterate through pooled objects

◆ begin() [2/2]

template<typename Object, typename ObjectId = uint32_t>
auto sgui::ObjectPool< Object, ObjectId >::begin ( ) const
inline

◆ changeId()

template<typename Object, typename ObjectId = uint32_t>
void sgui::ObjectPool< Object, ObjectId >::changeId ( const ObjectId & oldId,
const ObjectId & newId )

Change id of a stored object.

Parameters
oldIdOld identifier of the object
newIdNew identifier of the object

◆ clear()

template<typename Object, typename ObjectId = uint32_t>
void sgui::ObjectPool< Object, ObjectId >::clear ( )

Clear data in object pool.

◆ emplace()

template<typename Object, typename ObjectId = uint32_t>
template<typename... ObjectArgs>
Object & sgui::ObjectPool< Object, ObjectId >::emplace ( const ObjectId & id,
ObjectArgs &&... constructorArgs )

Build a new object in pool.

Parameters
idIdentifier that will serve to retrieve object
constructorArgsParameters used to build object

◆ empty()

template<typename Object, typename ObjectId = uint32_t>
bool sgui::ObjectPool< Object, ObjectId >::empty ( ) const

Test if pool is empty.

Returns
True if the pool is empty

◆ end() [1/2]

template<typename Object, typename ObjectId = uint32_t>
auto sgui::ObjectPool< Object, ObjectId >::end ( )
inline

◆ end() [2/2]

template<typename Object, typename ObjectId = uint32_t>
auto sgui::ObjectPool< Object, ObjectId >::end ( ) const
inline

◆ get() [1/2]

template<typename Object, typename ObjectId = uint32_t>
Object & sgui::ObjectPool< Object, ObjectId >::get ( const ObjectId & object)

Get oject in pool.

Parameters
objectIdentifier of the object searched
Returns
Object with required identifier

◆ get() [2/2]

template<typename Object, typename ObjectId = uint32_t>
const Object & sgui::ObjectPool< Object, ObjectId >::get ( const ObjectId & object) const

◆ has()

template<typename Object, typename ObjectId = uint32_t>
bool sgui::ObjectPool< Object, ObjectId >::has ( const ObjectId & object) const

Test if an object exists in pool.

Parameters
objectIdentifier of the object searched

◆ ids()

template<typename Object, typename ObjectId = uint32_t>
std::vector< ObjectId > sgui::ObjectPool< Object, ObjectId >::ids ( ) const

Get list of all identifiers used to store object.

◆ operator=() [1/2]

template<typename Object, typename ObjectId = uint32_t>
ObjectPool & sgui::ObjectPool< Object, ObjectId >::operator= ( const ObjectPool< Object, ObjectId > & rhs)

◆ operator=() [2/2]

template<typename Object, typename ObjectId = uint32_t>
ObjectPool & sgui::ObjectPool< Object, ObjectId >::operator= ( ObjectPool< Object, ObjectId > && rhs)

◆ remove()

template<typename Object, typename ObjectId = uint32_t>
void sgui::ObjectPool< Object, ObjectId >::remove ( const ObjectId & object)

Remove a specific object from pool.

Parameters
objectIdentifier of the object to be removed

◆ reserve()

template<typename Object, typename ObjectId = uint32_t>
void sgui::ObjectPool< Object, ObjectId >::reserve ( const size_t amount)

Reserve some amount of memory.

Parameters
amountAmount reserved in memory

◆ size()

template<typename Object, typename ObjectId = uint32_t>
size_t sgui::ObjectPool< Object, ObjectId >::size ( ) const

Get count of pooled objects.

Returns
Return count of the pooled objects

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