6#include <unordered_map>
14template <
typename Object,
typename ObjectId = u
int32_t>
31 Object&
add (Object&&
object,
const ObjectId&
id);
32 Object&
add (
const Object&
object,
const ObjectId&
id);
38 template <
typename... ObjectArgs>
39 Object&
emplace (
const ObjectId&
id, ObjectArgs&&... constructorArgs);
44 void remove (
const ObjectId&
object);
58 bool has (
const ObjectId&
object)
const;
69 Object&
get (
const ObjectId&
object);
70 const Object&
get (
const ObjectId&
object)
const;
76 void changeId (
const ObjectId& oldId,
const ObjectId& newId);
80 std::vector<ObjectId>
ids ()
const;
89 auto begin () {
return std::begin (mObjects); }
90 auto end () {
return std::end (mObjects); }
91 auto begin ()
const {
return std::cbegin (mObjects); }
92 auto end ()
const {
return std::cend (mObjects); }
94 void trackSlot (
const ObjectId& slot);
96 using MutexType = std::shared_timed_mutex;
97 using ReadLock = std::shared_lock <MutexType>;
98 using WriteLock = std::unique_lock <MutexType>;
99 mutable MutexType mMutex;
100 std::unordered_map <ObjectId, size_t> mIdToSlot;
101 std::vector <ObjectId> mSlotToId;
102 std::vector <Object> mObjects;
ObjectPool & operator=(const ObjectPool< Object, ObjectId > &rhs)
auto end() const
Definition ObjectPool.h:92
auto begin()
Definition ObjectPool.h:89
void changeId(const ObjectId &oldId, const ObjectId &newId)
Change id of a stored object.
const Object & get(const ObjectId &object) const
Object & add(const Object &object, const ObjectId &id)
size_t size() const
Get count of pooled objects.
void remove(const ObjectId &object)
Remove a specific object from pool.
std::vector< ObjectId > ids() const
Get list of all identifiers used to store object.
Object & emplace(const ObjectId &id, ObjectArgs &&... constructorArgs)
Build a new object in pool.
void clear()
Clear data in object pool.
ObjectPool(ObjectPool< Object, ObjectId > &&rhs)
ObjectPool(const ObjectPool< Object, ObjectId > &rhs)
ObjectPool & operator=(ObjectPool< Object, ObjectId > &&rhs)
auto end()
Definition ObjectPool.h:90
bool empty() const
Test if pool is empty.
Object & get(const ObjectId &object)
Get oject in pool.
auto begin() const
Definition ObjectPool.h:91
Object & add(Object &&object, const ObjectId &id)
Add object in pool.
bool has(const ObjectId &object) const
Test if an object exists in pool.
void reserve(const size_t amount)
Reserve some amount of memory.
Definition Interpolation.h:16