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)
212 friend struct ComponentIterator;
Untyped Component pool base.
Component & operator[](SizeType index)
Get the component at the given roster index.
COGSFOUNDATION_API void resize(SizeType capacity)
Resize the pool.
COGSFOUNDATION_API SizeType maxSize() const
Get the maximum size of the pool.
SizeType getComponentIndex(const Component *component) const
Get the index of the given component in the storage pool.
COGSFOUNDATION_API ComponentHandle allocateComponent()
Allocates and initializes a new component using placement new into the backing store.
bool isSet(const uint32_t flag) const
Checks if the given flag is set.
SizeType capacity() const
Get the capacity of the pool, the number of components that can be allocated without resizing the poo...
Component * resolve(const ComponentHandle handle)
Resolve a pointer to the component with the given handle.
COGSFOUNDATION_API void deallocateComponent(ComponentHandle handle)
Deallocates a component from the pool, calling the destructor of the derived component type.
Component * get(size_t index)
Retrieve a pointer to the component at the given index. The pointer is valid until any new allocation...
SizeType size() const
Gets the current size of the pool, the number components currently active.
void setFlag(ComponentPoolFlags::EComponentPoolFlags flag)
Set the given flag.
Base class for Component instances.
constexpr ComponentIndex getIndex() const
Get the components pool index. For internal use only.
Base allocator implementation.
uint16_t TypeId
Built in type used to uniquely identify a single type instance.
Contains all Cogs related functionality.
ComponentIndex SizeType
Type used to track the size of pools.
Handle to a Component instance.
Contains component pool flags.
EComponentPoolFlags
Contains flags controlling the behavior of a component pool instance.
@ AllowGrow
Allows the component pool to grow on demand.
Custom iterator providing iteration support for component pools.
std::forward_iterator_tag iterator_category
Type of iterator. Can only be used to iterate forward over components in a pool.
ComponentIterator & operator++(int)
Pre increment operator. Moves the iterator to the next component indexed in the roster of the pool.
ComponentType & operator*()
Dereference operator. Returns a reference to the component at the iterators current roster index.
size_t difference_type
Difference type to calculate iterator distance.
ComponentType * pointer
Pointer type to the templated ComponentType.
const ComponentType & operator*() const
Const dereference operator. Returns a const reference to the component at the current roster index.
ComponentIterator(ComponentPool &pool, SizeType index)
Construct a new component iterator on the given pool, starting at the given roster index.
ComponentIterator operator++()
Post increment operator. Moves the iterator to the next component indexed in the roster of the pool.
ComponentType value_type
Value type for dereferencing the iterator is the templated ComponentType.
ComponentType & reference
Reference type to the templated ComponentType.
ComponentIterator(const ComponentIterator &other)
Copy construct a new iterator instance from the given iterator.
const ComponentType * operator->() const
Pointer operator. Returns a pointer to the component at the current roster index.
constexpr bool operator==(const ComponentIterator &other) const
Comparison operator. If the current index of both iterators are equal the iterators are considered eq...
ComponentIterator end()
Returns an iterator to the end of the pool.
ComponentType & operator[](SizeType index)
Access the component at the given index.
ComponentPool(SizeType poolSize=16384)
Construct a component pool instance.
ComponentPool(Memory::Allocator *allocator, SizeType poolSize, MemBlockType memType=MemBlockType::Bucket)
Construct a component pool instance.
ComponentIterator begin()
Returns an iterator to the beginning of the pool.