struct TRTTIIteratorField

template<class ObjectRTTIType, class DataType, bool IsDataTypeContainer, class ObjectType>
Inherits: RTTIIteratorField

RTTI field type that supports iteration over arbitrary containers, including maps.

Unlike older field types, this field type internally handles plain, reflectable and reflectable pointer types, rather than requiring a separate field type for each. Also handles access to non-container elements by mimicing a single-element container.

Template parameters

ObjectRTTIType

RTTIType of the object that contains the field we're accessing.

DataType

Type of the container being iterated over.

IsDataTypeContainer

Set to true DataType is a container (e.g. vector, map) and you wish to iterate over it as such. If false, the iterator will act as faux iterator over a single element.

ObjectType

Type of the object that the field is a member of.

Public

Constructors

TRTTIIteratorField<ObjectRTTIType, DataType, IsDataTypeContainer, ObjectType>

TRTTIIteratorField<ObjectRTTIType, DataType, IsDataTypeContainer, ObjectType>(String name, u16 uniqueId, GetIteratorDelegate getIteratorCallback, GetValueDelegate getValueCallback, SetValueDelegate setValueCallback, const RTTIFieldInfo &fieldInfo)

Methods

InitSchema

void InitSchema() override

Initializes the field's RTTI schema.

Should be called once after construction.

GetIterator

SPtr<IRTTIIterator> GetIterator(RTTIType *rttiTypeInstance, void *object, FrameAllocator &frameAllocator) const override

Returns the iterator that can be used for iterating all entries in the field.

IteratorSupportsSeekToIndex

bool IteratorSupportsSeekToIndex() const override

Returns true if the iterator is allowed to seek to index.

True for iterators over arrays.

IteratorSupportsSeekToKey

bool IteratorSupportsSeekToKey() const override

Returns true if the iterator is allowed to seek to key.

True for iterators over sets and maps.

GetIteratorValue

const void *GetIteratorValue(RTTIType *rttiTypeInstance, void *object, FrameAllocator &frameAllocator, IRTTIIterator &iterator) const override

Returns the current value of the iterator.

SetIteratorValue

void SetIteratorValue(RTTIType *rttiTypeInstance, void *object, FrameAllocator &frameAllocator, IRTTIIterator &iterator, void *value) override

Inserts a new value before the iterator location. must have been created by a call to CreateEmptyFieldValue() or GetIteratorValueCopy(), using the same .

CreateEmptyFieldValue

void *CreateEmptyFieldValue(FrameAllocator &frameAllocator) override

Creates a new empty field value.

This should be populated by calls to WritePlainTypeTupleToStream(), SetReflectablePointer() or SetReflectable(), then passed to SetIteratorValue(), and finally freed via FreeFieldValue().

GetIteratorValueCopy

void *GetIteratorValueCopy(RTTIType *rttiTypeInstance, void *object, FrameAllocator &frameAllocator, IRTTIIterator &iterator) const override

Returns a modifiable copy of the current value of the iterator.

Returned value must be freed via FreeFieldValue() when done using it.

FreeFieldValue

void FreeFieldValue(void *fieldValue, FrameAllocator &frameAllocator) override

Frees the field value created by CreateEmptyFieldValue() or GetIteratorValueCopy().

Same allocator must be provided as used for creating the field value.

ReadPlainTypeTupleFromStream

void ReadPlainTypeTupleFromStream(void *fieldValue, u32 tupleElementIndex, Bitstream &stream, bool useCompression) override

Reads into the provided field value from the stream.

If the field value represents a tuple (i.e. contains multiple sub-types, such as std::pair

<K

, V>), this reads just a single tuple element, as specified by .

fieldValue
Field value to read into, as created by CreateEmptyFieldValue().
tupleElementIndex
Index of the tuple element in to read into. If doesn't represent a tuple, this should be 0.
stream
Stream from which to read from.
useCompression
If true, values will read as compressed where relevant. Must be set of the value was written with compression enabled.

WritePlainTypeTupleToStream

void WritePlainTypeTupleToStream(const void *fieldValue, u32 tupleElementIndex, Bitstream &stream, bool useCompression) override

Writes the provided field value to the stream.

If the field value represents a tuple (i.e. contains multiple sub-types, such as std::pair

<K

, V>), this encodes just a single tuple element, as specified by .

fieldValue
Field value to write, as returned by GetIteratorValue().
tupleElementIndex
Index of the tuple element in to write. If doesn't represent a tuple, this should be 0.
stream
Stream in which to write to.
useCompression
If true, values will attempt to be compressed where relevant. Must be decoded with this flag in the same state.

SetReflectablePointer

void SetReflectablePointer(void *fieldValue, u32 tupleElementIndex, const SPtr<IReflectable> &reflectable) override

Assigns the reflectable pointer to the provided field value.

If the field value represents a tuple (i.e. contains multiple sub-types, such as std::pair

<K

, V>), this assigns a single element of the tuple, as specified by . If the field value is not a tuple, is simply assigned to .

fieldValue
Field value in which to store the reflectable pointer, as created by CreateEmptyFieldValue().
tupleElementIndex
Index of the tuple element in in which to store the reflectable pointer. If doesn't represent a tuple, this should be 0.
reflectable
Reflectable pointer to assign to the field value.

GetReflectablePointer

SPtr<IReflectable> GetReflectablePointer(const void *fieldValue, u32 tupleElementIndex) override

Reads the reflectable pointer from the provided field value.

If the field value represents a tuple (i.e. contains multiple sub-types, such as std::pair

<K

, V>), this reads a single element of the tuple, as specified by . If the field value is not a tuple, is simply cast to a reflectable pointer type.

fieldValue
Field value containing the reflectable pointer, as returned by GetIteratorValue().
tupleElementIndex
Index of the tuple element in which contains the reflectable pointer. If doesn't represent a tuple, this should be 0.

Returns: Reflectable pointer.

SetReflectable

void SetReflectable(void *fieldValue, u32 tupleElementIndex, const IReflectable &reflectable) override

Assigns the reflectable to the provided field value.

If the field value represents a tuple (i.e. contains multiple sub-types, such as std::pair

<K

, V>), this assigns a single element of the tuple, as specified by . If the field value is not a tuple, is simply assigned to .

fieldValue
Field value in which to store the reflectable, as created by CreateEmptyFieldValue().
tupleElementIndex
Index of the tuple element in in which to store the reflectable. If doesn't represent a tuple, this should be 0.
reflectable
Reflectable to assign to the field value.

GetReflectable

const IReflectable &GetReflectable(const void *fieldValue, u32 tupleElementIndex) override

Reads the reflectable value from the provided field value.

If the field value represents a tuple (i.e. contains multiple sub-types, such as std::pair

<K

, V>), this reads a single element of the tuple, as specified by . If the field value is not a tuple, is simply cast to a reflectable type.

fieldValue
Field value containing the reflectable, as returned by GetIteratorValue().
tupleElementIndex
Index of the tuple element in which contains the reflectable. If doesn't represent a tuple, this should be 0.

Returns: Reflectable.

GetPlainTypeSize

BitLength GetPlainTypeSize(const void *fieldValue, u32 tupleElementIndex, bool useCompression) override

Returns the size of the plain type in the provided field value.

If the field value represents a tuple (i.e. contains multiple sub-types, such as std::pair

<K

, V>), this returns the size of just a single tuple element, as specified by .

fieldValue
Field value to retrieve size from, as returned by GetIteratorValue().
tupleElementIndex
Index of the tuple element in to retrieve size for. If doesn't represent a tuple, this should be 0.
useCompression
If true, size will be compressed if possible.

~RTTIIteratorField

virtual ~RTTIIteratorField() noexcept = default

~RTTIField

virtual ~RTTIField() noexcept = default

CheckIsArray

void CheckIsArray(bool array) const

Throws an exception depending if the field is or isn't an array.

array
If true, then exception will be thrown if field is not an array. If false, then it will be thrown if field is an array.

Fields

Name

String Name

Schema

Protected

Methods

Init

void Init(String name, const RTTIFieldSchema &schema)

Private

Fields

mGetIteratorCallback

GetIteratorDelegate mGetIteratorCallback

mGetValueCallback

GetValueDelegate mGetValueCallback

mSetValueCallback

SetValueDelegate mSetValueCallback