PlayRho  2.0.0
An interactive physics engine & library.
playrho::ObjectPool< T > Class Template Reference

Object pool with indexable properties. More...

#include <playrho/ObjectPool.hpp>

Inheritance diagram for playrho::ObjectPool< T >:
[legend]

Public Types

using const_reference = typename std::vector< value_type >::const_reference
 Constant reference type alias.
 
using reference = typename std::vector< value_type >::reference
 Reference type alias.
 
using size_type = typename std::vector< value_type >::size_type
 Size type.
 
using value_type = T
 Element type.
 

Public Member Functions

template<class... Args>
size_type Allocate (Args &&... args)
 Allocates an entry in the array with the given constructor parameters. More...
 
size_type Allocate (const value_type &copy)
 Allocates an entry in the array with the given instance. More...
 
reference at (size_type pos)
 Bounds checking indexed array accessor.
 
const_reference at (size_type pos) const
 Bounds checking indexed array accessor.
 
std::vector< value_type >::const_iterator begin () const noexcept
 Gets the beginning iterator over the data of this container.
 
std::vector< value_type >::iterator begin () noexcept
 Gets the beginning iterator over the data of this container.
 
void clear () noexcept
 Clears this instance's free pool and allocated pool.
 
const value_typedata () const noexcept
 Gets a pointer to the data of this container.
 
std::vector< value_type >::const_iterator end () const noexcept
 Gets the ending iterator over the data of this container.
 
std::vector< value_type >::iterator end () noexcept
 Gets the ending iterator over the data of this container.
 
bool FindFree (size_type index) const noexcept
 Finds whether the given index is in the free list. More...
 
reference Free (size_type index)
 Frees the previously-allocated index entry. More...
 
size_type free_size () const noexcept
 Gets the number of elements currently free. More...
 
size_type GetIndex (value_type *ptr) const
 Gets the index of the given pointer. More...
 
size_type max_size () const noexcept
 Gets the maximum theoretical size this instance can have in number of elements.
 
reference operator[] (size_type pos)
 Array index operator. More...
 
const_reference operator[] (size_type pos) const
 Constant array index operator. More...
 
void reserve (size_type value)
 Reserves the given number of elements from dynamic memory. More...
 
size_type size () const noexcept
 Gets the size of this instance in number of elements. More...
 

Friends

bool operator!= (const ObjectPool &lhs, const ObjectPool &rhs) noexcept
 Hidden friend operator inequality support.
 
bool operator== (const ObjectPool &lhs, const ObjectPool &rhs) noexcept
 Hidden friend operator equality support.
 

Detailed Description

template<typename T>
class playrho::ObjectPool< T >

Object pool with indexable properties.

Member Function Documentation

◆ Allocate() [1/2]

template<typename T >
template<class... Args>
size_type playrho::ObjectPool< T >::Allocate ( Args &&...  args)
inline

Allocates an entry in the array with the given constructor parameters.

Note
Call Free(size_type) if the allocated entry needs to be freed.
Postcondition
size() - free_size() will return a value one less than before.
See also
Free, size, free_size.

◆ Allocate() [2/2]

template<typename T >
size_type playrho::ObjectPool< T >::Allocate ( const value_type copy)
inline

Allocates an entry in the array with the given instance.

Note
Call Free(size_type) if the allocated entry needs to be freed.
Postcondition
size() - free_size() will return a value one less than before.
See also
Free, size, free_size.

◆ FindFree()

template<typename T >
bool playrho::ObjectPool< T >::FindFree ( size_type  index) const
inlinenoexcept

Finds whether the given index is in the free list.

Note
Complexity is at most O(n) where n is the number of elements free.
See also
Free, free_size.
https://en.wikipedia.org/wiki/Big_O_notation

Referenced by playrho::ObjectPool< T >::Free().

◆ Free()

template<typename T >
reference playrho::ObjectPool< T >::Free ( size_type  index)
inline

Frees the previously-allocated index entry.

Note
Provides the strong exception guarantee - if the operation errs, state is like it was prior to calling this function.
Precondition
FindFree(size_type) returns false for the given index.
Postcondition
FindFree(size_type) returns true for the freed index.
free_size() returns a value one greater than before.
Exceptions
std::out_of_rangeif given an index that's greater than or equal to the size of this instance as returned by size().
See also
Allocate, FindFree, free_size, size.

◆ free_size()

template<typename T >
size_type playrho::ObjectPool< T >::free_size ( ) const
inlinenoexcept

Gets the number of elements currently free.

See also
Free.

◆ GetIndex()

template<typename T >
size_type playrho::ObjectPool< T >::GetIndex ( value_type ptr) const
inline

Gets the index of the given pointer.

Returns
-1 if the given pointer is not within the range of the allocator's allocation, otherwise return index of pointer within allocator.

◆ operator[]() [1/2]

template<typename T >
reference playrho::ObjectPool< T >::operator[] ( size_type  pos)
inline

Array index operator.

Note
This does not do bounds checking.
See also
at

◆ operator[]() [2/2]

template<typename T >
const_reference playrho::ObjectPool< T >::operator[] ( size_type  pos) const
inline

Constant array index operator.

Note
This does not do bounds checking.
See also
at

◆ reserve()

template<typename T >
void playrho::ObjectPool< T >::reserve ( size_type  value)
inline

Reserves the given number of elements from dynamic memory.

Note
This may increase this instance's capacity; not its size.

◆ size()

template<typename T >
size_type playrho::ObjectPool< T >::size ( ) const
inlinenoexcept

Gets the size of this instance in number of elements.

See also
Allocate, Free.

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