Class column
Synopsis
#include <include/flecs/cpp/column.hpp>
template <typename T>
class column
Description
Wrapper class around a column.
- Template Parameters
T
- component type of the column.
Inheritance
Decsendents: any_column< T, typename std::enable_if< std::is_pointer< T >::value==false >::type >
Methods
column overload | Create column from component array. | |
column overload | Create column from iterator. | |
is_set | Return whether component is set | |
is_shared | Return whether component is shared | |
operator-> | Return first element of component array | |
operator[] | Return element in component array |
Source
Lines 58-124 in include/flecs/cpp/column.hpp.
template <typename T>
class column {
public:
/** Create column from component array.
*
* @param array Pointer to the component array.
* @param count Number of elements in component array.
* @param is_shared Is the component shared or not.
*/
column(T* array, size_t count, bool is_shared = false)
: m_array(array)
, m_count(count)
, m_is_shared(is_shared) {}
/** Create column from iterator.
*
* @param iter Iterator object.
* @param column Index of the signature of the query being iterated over.
*/
column(iter &iter, int column);
/** Return element in component array.
* This operator may only be used if the column is not shared.
*
* @param index Index of element.
* @return Reference to element.
*/
T& operator[](size_t index) {
ecs_assert(index < m_count, ECS_COLUMN_INDEX_OUT_OF_RANGE, NULL);
ecs_assert(!index || !m_is_shared, ECS_INVALID_PARAMETER, NULL);
ecs_assert(m_array != nullptr, ECS_COLUMN_INDEX_OUT_OF_RANGE, NULL);
return m_array[index];
}
/** Return first element of component array.
* This operator is typically used when the column is shared.
*
* @return Reference to the first element.
*/
T* operator->() {
ecs_assert(m_array != nullptr, ECS_COLUMN_INDEX_OUT_OF_RANGE, NULL);
return m_array;
}
/** Return whether component is set.
* If the column is optional, this method may return false.
*
* @return True if component is set, false if component is not set.
*/
bool is_set() const {
return m_array != nullptr;
}
/** Return whether component is shared.
* If the column is shared, this method returns true.
*
* @return True if component is shared, false if component is owned.
*/
bool is_shared() const {
return m_is_shared;
}
protected:
T* m_array;
size_t m_count;
bool m_is_shared;
};