17 template<
typename T,
typename U>
25 template<
typename ClassType,
typename FieldType>
80 template<
typename ClassType,
typename FieldType>
81 Field(
const Name& name, FieldType ClassType::* field);
89 template<
typename ClassType,
typename FieldType>
110 template<
typename FieldValueType>
112 FieldValueType *
getPtr(
void * container)
const
114 if constexpr (!std::is_array<FieldValueType>()) {
115 assert(
sizeof(FieldValueType) <= byteSize &&
"Pointer overflows field size.");
118 return static_cast<FieldValueType*
>(
static_cast<void*
>(
static_cast<char*
>(container) + offset));
127 template<
typename FieldValueType>
129 const FieldValueType *
getPtr(
const void * container)
const
131 return static_cast<const FieldValueType*
>(
static_cast<const void*
>(
static_cast<const char*
>(container) + offset));
162 unsetFlag(FieldFlags::NoSerialize);
165 fieldFlags |= FieldFlags::NoSerialize;
179#if defined( EMSCRIPTEN )
181 if (!attribute.isRuntime())
184 return attributes.
add(*
this, attribute);
196 return attributes.get<T>();
200 void unsetFlag(
FieldFlags flag) { this->fieldFlags = this->fieldFlags &
static_cast<FieldFlags>(~uint32_t(flag)); }
218 size_t arrayDimensions = 0;
Field definition describing a single data member of a data structure.
const Name & getName() const
Get the name of the field.
const T * get() const
Retrieve an attribute of the given type from storage, if present.
Field & add(T attribute)
Adds the given attribute.
TypeId typeId
Type id of the field.
size_t getDimensions() const
Get the array dimensions of the field. Returns zero if the field is not an array.
Field & setSerialize(bool serialize)
Mark if field shall be serializable, e.g. value saved generating Scene. Default = true.
FieldFlags getFlags() const
Get the field flags.
bool isSet(FieldFlags flag) const
Checks if the given flag(s) is set. Requires exact bit match if test of several bits.
size_t getOffset() const
Get the fields offset from the start of the structure in bytes.
Field(Field &&other) noexcept=default
Default move constructor.
Field(const Field &other)=default
Default copy constructor.
Name name
Name of the field.
Attributes attributes
Attribute storage.
size_t byteSize
Size of the field in bytes.
TypeId getTypeId() const
Get the type id of the field.
FieldValueType * getPtr(void *container) const
Get a pointer to this field on the given container.
const FieldValueType * getPtr(const void *container) const
Get a const pointer to this field on the given container.
Field & operator=(const Field &other)=default
Default copy assignment operator.
size_t offset
Offset of the field in bytes from the beginning of the container.
Field & operator=(Field &&other) noexcept=default
Default move assignment operator.
@ NoSerialize
Skip Serialize field.
@ Array
Field is an array.
uint16_t TypeId
Built in type used to uniquely identify a single type instance.
FieldFlags & operator|=(FieldFlags &lhs, FieldFlags rhs)
Or assignment operator.
FieldFlags operator&(FieldFlags lhs, FieldFlags rhs)
And operator.
FieldFlags operator|(FieldFlags lhs, FieldFlags rhs)
Or operator.
Contains all Cogs related functionality.
Provides scoped storage for a raw pointer and corresponding deletion logic.
Attribute storage for structures.
Convenience wrapper for adding attributes during field creation in a type safe manner.
FieldWrapper & setStep(U step)
Convenience method for setting the valid value step of the field.
FieldWrapper(const Name &name, FieldType ClassType::*field)
Construct the field wrapper, forwarding arguments to the underlying field.
FieldWrapper & setDefault(U value)
Convenience method for setting the default value of the field.
FieldWrapper & setRange(U min, U max)
Convenience method for setting the valid value range of the field.
Represents an unique name.