Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
ObjectPool.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of
8this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the Software
14is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_OBJECT_POOL_H_
34#define DVD_OBJECT_POOL_H_
35
36#include "PoolHandle.h"
38
39namespace Divide {
40
41template<typename T, size_t N, bool allowResize>
43public:
44 ObjectPool();
45
46 template<typename... Args>
47 [[nodiscard]] PoolHandle allocate(Args... args);
48 void deallocate(PoolHandle handle);
49
50 [[nodiscard]] PoolHandle registerExisting(T& object);
51 void unregisterExisting(PoolHandle handle);
52
53 [[nodiscard]] T* find(PoolHandle handle) const;
54
55protected:
56 [[nodiscard]] PoolHandle registerExistingInternal( T& object, bool retry );
57
58protected:
60
61 eastl::fixed_vector<PoolHandle, N, allowResize> _ids{};
62 eastl::fixed_vector<T*, N, allowResize> _pool{};
63};
64
65} //namespace Divide
66
67#endif //DVD_OBJECT_POOL_H_
68
69#include "ObjectPool.inl"
PoolHandle registerExisting(T &object)
Definition: ObjectPool.inl:77
eastl::fixed_vector< PoolHandle, N, allowResize > _ids
Definition: ObjectPool.h:61
T * find(PoolHandle handle) const
Definition: ObjectPool.inl:46
void unregisterExisting(PoolHandle handle)
Definition: ObjectPool.inl:110
void deallocate(PoolHandle handle)
Definition: ObjectPool.inl:66
PoolHandle registerExistingInternal(T &object, bool retry)
Definition: ObjectPool.inl:84
eastl::fixed_vector< T *, N, allowResize > _pool
Definition: ObjectPool.h:62
PoolHandle allocate(Args... args)
Definition: ObjectPool.inl:59
SharedMutex _poolLock
Definition: ObjectPool.h:59
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
std::shared_mutex SharedMutex
Definition: SharedMutex.h:43