Cogs.Core
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Cogs::Reflection::Field Class Reference

Field definition describing a single data member of a data structure. More...

#include <Field.h>

Public Member Functions

template<typename ClassType , typename FieldType >
 Field (const Name &name, FieldType ClassType::*field)
 Initializes a new field instance with the given name and the given pointer to member data.
 
 Field (const Field &other)=default
 Default copy constructor.
 
 Field (Field &&other) noexcept=default
 Default move constructor.
 
Fieldoperator= (const Field &other)=default
 Default copy assignment operator.
 
Fieldoperator= (Field &&other) noexcept=default
 Default move assignment operator.
 
template<typename FieldValueType >
FieldValueType * getPtr (void *container) const
 Get a pointer to this field on the given container.
 
template<typename FieldValueType >
const FieldValueType * getPtr (const void *container) const
 Get a const pointer to this field on the given container.
 
const NamegetName () const
 Get the name of the field.
 
TypeId getTypeId () const
 Get the type id of the field.
 
size_t getOffset () const
 Get the fields offset from the start of the structure in bytes.
 
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 getDimensions () const
 Get the array dimensions of the field. Returns zero if the field is not an array.
 
FieldsetSerialize (bool serialize)
 Mark if field shall be serializable, e.g. value saved generating Scene. Default = true.
 
template<typename T >
Fieldadd (T attribute)
 Adds the given attribute.
 
template<typename T >
const T * get () const
 Retrieve an attribute of the given type from storage, if present.
 

Static Public Member Functions

template<typename ClassType , typename FieldType >
static FieldWrapper< Field, FieldType > create (const Name &name, FieldType ClassType::*field)
 Creates a new field instance, returning a wrapper for type safe continuation style setup.
 

Private Member Functions

void unsetFlag (FieldFlags flag)
 

Private Attributes

Attributes attributes
 Attribute storage.
 
FieldFlags fieldFlags = FieldFlags::Default
 Flags.
 
Name name
 Name of the field.
 
size_t offset
 Offset of the field in bytes from the beginning of the container.
 
size_t byteSize
 Size of the field in bytes.
 
size_t arrayDimensions = 0
 Dimensions.
 
TypeId typeId
 Type id of the field.
 

Detailed Description

Field definition describing a single data member of a data structure.

Definition at line 67 of file Field.h.

Constructor & Destructor Documentation

◆ Field()

template<typename ClassType , typename FieldType >
Cogs::Reflection::Field::Field ( const Name name,
FieldType ClassType::*  field 
)

Initializes a new field instance with the given name and the given pointer to member data.

Template Parameters
ClassTypeType of the class the field resides in.
FieldTypeType of the field data.
Parameters
nameName of the field to use for lookup.
fieldMember pointer to the given field.

Definition at line 11 of file Field.inl.

References Cogs::Reflection::Array, arrayDimensions, fieldFlags, and Cogs::Reflection::Pointer.

Member Function Documentation

◆ add()

template<typename T >
Field & Cogs::Reflection::Field::add ( attribute)
inline

◆ create()

template<typename ClassType , typename FieldType >
FieldWrapper< Field, FieldType > Cogs::Reflection::Field::create ( const Name name,
FieldType ClassType::*  field 
)
static

Creates a new field instance, returning a wrapper for type safe continuation style setup.

See also
Field::Field()

Definition at line 29 of file Field.inl.

References name.

Referenced by Cogs::Core::FogComponent::registerType(), and Cogs::Core::LightComponent::registerType().

◆ get()

template<typename T >
const T * Cogs::Reflection::Field::get ( ) const
inline

Retrieve an attribute of the given type from storage, if present.

See also
Attributes::get()

Definition at line 194 of file Field.h.

◆ getDimensions()

size_t Cogs::Reflection::Field::getDimensions ( ) const
inline

Get the array dimensions of the field. Returns zero if the field is not an array.

Definition at line 156 of file Field.h.

◆ getFlags()

FieldFlags Cogs::Reflection::Field::getFlags ( ) const
inline

Get the field flags.

Definition at line 148 of file Field.h.

Referenced by Cogs::Core::writeEntity().

◆ getName()

const Name & Cogs::Reflection::Field::getName ( ) const
inline

Get the name of the field.

Definition at line 136 of file Field.h.

Referenced by Cogs::Core::applyFieldValues(), and Cogs::Core::writeEntity().

◆ getOffset()

size_t Cogs::Reflection::Field::getOffset ( ) const
inline

Get the fields offset from the start of the structure in bytes.

Definition at line 144 of file Field.h.

◆ getPtr() [1/2]

template<typename FieldValueType >
const FieldValueType * Cogs::Reflection::Field::getPtr ( const void *  container) const
inline

Get a const pointer to this field on the given container.

Parameters
containerField container, e.g. component
Template Parameters
FieldValueTypeThe type of the field.

Definition at line 129 of file Field.h.

◆ getPtr() [2/2]

template<typename FieldValueType >
FieldValueType * Cogs::Reflection::Field::getPtr ( void *  container) const
inline

Get a pointer to this field on the given container.

Parameters
containerField container, e.g. component
Template Parameters
FieldValueTypeThe type of the field.

Definition at line 112 of file Field.h.

Referenced by Cogs::Core::writeEntity().

◆ getTypeId()

TypeId Cogs::Reflection::Field::getTypeId ( ) const
inline

Get the type id of the field.

Definition at line 140 of file Field.h.

Referenced by Cogs::Core::applyFieldValues(), and Cogs::Core::writeEntity().

◆ isSet()

bool Cogs::Reflection::Field::isSet ( FieldFlags  flag) const
inline

Checks if the given flag(s) is set. Requires exact bit match if test of several bits.

Definition at line 152 of file Field.h.

◆ setSerialize()

Field & Cogs::Reflection::Field::setSerialize ( bool  serialize)
inline

Mark if field shall be serializable, e.g. value saved generating Scene. Default = true.

Definition at line 159 of file Field.h.

Referenced by Cogs::Core::CameraComponent::registerType().

◆ unsetFlag()

void Cogs::Reflection::Field::unsetFlag ( FieldFlags  flag)
inlineprivate

Definition at line 200 of file Field.h.

Member Data Documentation

◆ arrayDimensions

size_t Cogs::Reflection::Field::arrayDimensions = 0
private

Dimensions.

Definition at line 218 of file Field.h.

Referenced by Field().

◆ attributes

Attributes Cogs::Reflection::Field::attributes
private

Attribute storage.

Definition at line 203 of file Field.h.

◆ byteSize

size_t Cogs::Reflection::Field::byteSize
private

Size of the field in bytes.

Definition at line 215 of file Field.h.

◆ fieldFlags

FieldFlags Cogs::Reflection::Field::fieldFlags = FieldFlags::Default
private

Flags.

Definition at line 206 of file Field.h.

Referenced by Field().

◆ name

Name Cogs::Reflection::Field::name
private

Name of the field.

Definition at line 209 of file Field.h.

Referenced by create().

◆ offset

size_t Cogs::Reflection::Field::offset
private

Offset of the field in bytes from the beginning of the container.

Definition at line 212 of file Field.h.

◆ typeId

TypeId Cogs::Reflection::Field::typeId
private

Type id of the field.

Definition at line 221 of file Field.h.


The documentation for this class was generated from the following files: