17 template<
typename T,
typename U>
25 template<
typename ClassType,
typename FieldType>
82 template<
typename ClassType,
typename FieldType>
83 Field(
const Name& name, FieldType ClassType::* field);
91 template<
typename ClassType,
typename FieldType>
112 template<
typename FieldValueType>
114 FieldValueType *
getPtr(
void * container)
const
116 if constexpr (!std::is_array<FieldValueType>()) {
117 assert(
sizeof(FieldValueType) <= byteSize &&
"Pointer overflows field size.");
120 return static_cast<FieldValueType*
>(
static_cast<void*
>(
static_cast<char*
>(container) + offset));
129 template<
typename FieldValueType>
131 const FieldValueType *
getPtr(
const void * container)
const
133 return static_cast<const FieldValueType*
>(
static_cast<const void*
>(
static_cast<const char*
>(container) + offset));
164 unsetFlag(FieldFlags::NoSerialize);
167 fieldFlags |= FieldFlags::NoSerialize;
177 unsetFlag(FieldFlags::NoCodeGen);
180 fieldFlags |= FieldFlags::NoCodeGen;
194#if defined( EMSCRIPTEN )
196 if (!attribute.isRuntime())
199 return attributes.
add(*
this, attribute);
211 return attributes.get<
T>();
233 size_t arrayDimensions = 0;
#define COGSFOUNDATION_API
Definition: FoundationBase.h:31
Field definition describing a single data member of a data structure.
Definition: Field.h:70
const Name & getName() const
Get the name of the field.
Definition: Field.h:138
const T * get() const
Retrieve an attribute of the given type from storage, if present.
Definition: Field.h:209
Field & add(T attribute)
Adds the given attribute.
Definition: Field.h:192
TypeId typeId
Type id of the field.
Definition: Field.h:236
size_t getDimensions() const
Get the array dimensions of the field. Returns zero if the field is not an array.
Definition: Field.h:158
Field & setSerialize(bool serialize)
Mark if field shall be serializable, e.g. value saved generating Scene. Default = true.
Definition: Field.h:161
void unsetFlag(FieldFlags flag)
Definition: Field.h:215
FieldFlags getFlags() const
Get the field flags.
Definition: Field.h:150
bool isSet(FieldFlags flag) const
Checks if the given flag(s) is set. Requires exact bit match if test of several bits.
Definition: Field.h:154
size_t getOffset() const
Get the fields offset from the start of the structure in bytes.
Definition: Field.h:146
Field(Field &&other) noexcept=default
Default move constructor.
Field(const Field &other)=default
Default copy constructor.
Name name
Name of the field.
Definition: Field.h:224
Attributes attributes
Attribute storage.
Definition: Field.h:218
size_t byteSize
Size of the field in bytes.
Definition: Field.h:230
TypeId getTypeId() const
Get the type id of the field.
Definition: Field.h:142
FieldValueType * getPtr(void *container) const
Get a pointer to this field on the given container.
Definition: Field.h:114
Field & setCodeGen(bool codegen)
Mark if field shall have plumbing code generated. Default = true.
Definition: Field.h:174
const FieldValueType * getPtr(const void *container) const
Get a const pointer to this field on the given container.
Definition: Field.h:131
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.
Definition: Field.h:227
Field & operator=(Field &&other) noexcept=default
Default move assignment operator.
FieldFlags
Field flags.
Definition: Field.h:42
@ NoSerialize
Skip Serialize field.
@ NoCodeGen
Do not add code generation of plumbing for this field.
@ Array
Field is an array.
uint16_t TypeId
Built in type used to uniquely identify a single type instance.
Definition: Name.h:48
FieldFlags & operator|=(FieldFlags &lhs, FieldFlags rhs)
Or assignment operator.
Definition: Field.h:64
FieldFlags operator&(FieldFlags lhs, FieldFlags rhs)
And operator.
Definition: Field.h:61
FieldFlags operator|(FieldFlags lhs, FieldFlags rhs)
Or operator.
Definition: Field.h:57
Main Cogs namespace.
Definition: MortonCode.h:5
Provides scoped storage for a raw pointer and corresponding deletion logic.
Definition: Pointer.h:66
Attribute storage for structures.
Definition: Attributes.h:130
Convenience wrapper for adding attributes during field creation in a type safe manner.
Definition: Field.h:19
FieldWrapper & setStep(U step)
Convenience method for setting the valid value step of the field.
Definition: Field.inl:51
FieldWrapper(const Name &name, FieldType ClassType::*field)
Construct the field wrapper, forwarding arguments to the underlying field.
Definition: Field.h:26
FieldWrapper & setDefault(U value)
Convenience method for setting the default value of the field.
Definition: Field.inl:35
FieldWrapper & setRange(U min, U max)
Convenience method for setting the valid value range of the field.
Definition: Field.inl:43
Represents an unique name.
Definition: Name.h:70