5#include "../Memory/MemoryBuffer.h"
6#include "../Reflection/TypeDatabase.h"
10 namespace ComponentModel
58 return *
get(roster[index]);
64 return reinterpret_cast<Component *
>(store.data() + (index * elementSize));
70 return get(handle.index);
92 bool isSet(
const uint32_t flag)
const {
return (flags & flag) == flag; }
122 template<
typename ComponentType>
125 static_assert(
sizeof(
Component) <=
sizeof(ComponentType),
"Component type incompatible.");
167 const ComponentType &
operator*()
const {
return pool[index]; }
170 const ComponentType *
operator->()
const {
return &pool[index]; }
187 ComponentPoolBase(Reflection::TypeDatabase::getType<ComponentType>().getTypeId(), poolSize, allocator, memType)
195 ComponentPoolBase(Reflection::TypeDatabase::getType<ComponentType>().getTypeId(), poolSize, Memory::Allocator::defaultAllocator(), MemBlockType::Bucket)
#define COGSFOUNDATION_API
Definition: FoundationBase.h:31
Untyped Component pool base.
Definition: ComponentPool.h:37
Component & operator[](SizeType index)
Get the component at the given roster index.
Definition: ComponentPool.h:56
COGSFOUNDATION_API void resize(SizeType capacity)
Resize the pool.
Definition: ComponentPool.cpp:93
COGSFOUNDATION_API SizeType maxSize() const
Get the maximum size of the pool.
Definition: ComponentPool.cpp:103
SizeType getComponentIndex(const Component *component) const
Get the index of the given component in the storage pool.
Definition: ComponentPool.h:86
COGSFOUNDATION_API ComponentHandle allocateComponent()
Allocates and initializes a new component using placement new into the backing store.
Definition: ComponentPool.cpp:28
bool isSet(const uint32_t flag) const
Checks if the given flag is set.
Definition: ComponentPool.h:92
SizeType capacity() const
Get the capacity of the pool, the number of components that can be allocated without resizing the poo...
Definition: ComponentPool.h:80
Component * resolve(const ComponentHandle handle)
Resolve a pointer to the component with the given handle.
Definition: ComponentPool.h:68
COGSFOUNDATION_API void deallocateComponent(ComponentHandle handle)
Deallocates a component from the pool, calling the destructor of the derived component type.
Definition: ComponentPool.cpp:59
Component * get(size_t index)
Retrieve a pointer to the component at the given index. The pointer is valid until any new allocation...
Definition: ComponentPool.h:62
SizeType size() const
Gets the current size of the pool, the number components currently active.
Definition: ComponentPool.h:77
void setFlag(ComponentPoolFlags::EComponentPoolFlags flag)
Set the given flag.
Definition: ComponentPool.h:89
Base class for Component instances.
Definition: Component.h:143
constexpr ComponentIndex getIndex() const
Get the components pool index. For internal use only.
Definition: Component.h:392
Base allocator implementation.
Definition: Allocator.h:30
Definition: MemoryBuffer.h:196
uint16_t TypeId
Built in type used to uniquely identify a single type instance.
Definition: Name.h:48
Main Cogs namespace.
Definition: MortonCode.h:5
ComponentIndex SizeType
Type used to track the size of pools.
Definition: Component.h:19
Handle to a Component instance.
Definition: Component.h:67
Contains component pool flags.
Definition: ComponentPool.h:14
EComponentPoolFlags
Contains flags controlling the behavior of a component pool instance.
Definition: ComponentPool.h:19
@ AllowGrow
Allows the component pool to grow on demand.
Definition: ComponentPool.h:23
@ None
Default behavior.
Definition: ComponentPool.h:21
Custom iterator providing iteration support for component pools.
Definition: ComponentPool.h:131
std::forward_iterator_tag iterator_category
Type of iterator. Can only be used to iterate forward over components in a pool.
Definition: ComponentPool.h:134
ComponentIterator & operator++(int)
Pre increment operator. Moves the iterator to the next component indexed in the roster of the pool.
Definition: ComponentPool.h:161
ComponentType & operator*()
Dereference operator. Returns a reference to the component at the iterators current roster index.
Definition: ComponentPool.h:164
size_t difference_type
Difference type to calculate iterator distance.
Definition: ComponentPool.h:140
ComponentType * pointer
Pointer type to the templated ComponentType.
Definition: ComponentPool.h:143
const ComponentType & operator*() const
Const dereference operator. Returns a const reference to the component at the current roster index.
Definition: ComponentPool.h:167
ComponentIterator(ComponentPool &pool, SizeType index)
Construct a new component iterator on the given pool, starting at the given roster index.
Definition: ComponentPool.h:149
ComponentIterator operator++()
Post increment operator. Moves the iterator to the next component indexed in the roster of the pool.
Definition: ComponentPool.h:158
ComponentType value_type
Value type for dereferencing the iterator is the templated ComponentType.
Definition: ComponentPool.h:137
ComponentType & reference
Reference type to the templated ComponentType.
Definition: ComponentPool.h:146
ComponentIterator(const ComponentIterator &other)
Copy construct a new iterator instance from the given iterator.
Definition: ComponentPool.h:152
const ComponentType * operator->() const
Pointer operator. Returns a pointer to the component at the current roster index.
Definition: ComponentPool.h:170
constexpr bool operator==(const ComponentIterator &other) const
Comparison operator. If the current index of both iterators are equal the iterators are considered eq...
Definition: ComponentPool.h:155
Typed component pool.
Definition: ComponentPool.h:124
ComponentIterator end()
Returns an iterator to the end of the pool.
Definition: ComponentPool.h:203
ComponentType & operator[](SizeType index)
Access the component at the given index.
Definition: ComponentPool.h:206
ComponentPool(SizeType poolSize=16384)
Construct a component pool instance.
Definition: ComponentPool.h:194
ComponentPool(Memory::Allocator *allocator, SizeType poolSize, MemBlockType memType=MemBlockType::Bucket)
Construct a component pool instance.
Definition: ComponentPool.h:186
ComponentIterator begin()
Returns an iterator to the beginning of the pool.
Definition: ComponentPool.h:200