RTTITypeBase Class Referenceabstract

Description

Provides an interface for accessing fields of a certain class.

Data can be easily accessed by getter and setter methods.

Supported data types:

  • Plain types - All types defined in BsRTTIField.h, mostly native types and POD (plain old data) structs. Data is parsed byte by byte. No pointers to plain types are supported. Data is passed around by value.
  • Reflectable types - Any class deriving from IReflectable. Data is parsed based on fields in its RTTI class. Can be pointer or value type.
  • Arrays of both plain and reflectable types are supported
  • Data blocks - A managed or unmanaged block of data. See ManagedDataBlock.

Inherited by RTTIType< Type, BaseType, MyRTTIType >.

Methods

virtual Vector< RTTITypeBase * > & getDerivedClasses ()=0
 Returns RTTI type information for all classes that derive from the class that owns this RTTI type. More...
 
virtual RTTITypeBasegetBaseClass ()=0
 Returns RTTI type information for the class that owns this RTTI type. More...
 
virtual bool isDerivedFrom (RTTITypeBase *base)=0
 Returns true if current RTTI class is derived from base. More...
 
virtual SPtr< IReflectablenewRTTIObject ()=0
 Creates a new instance of the class owning this RTTI type. More...
 
virtual const StringgetRTTIName ()=0
 Returns the name of the class owning this RTTI type. More...
 
virtual UINT32 getRTTIId ()=0
 Returns an RTTI id that uniquely represents each class in the RTTI system. More...
 
virtual void onSerializationStarted (IReflectable *obj, const UnorderedMap< String, UINT64 > &params)
 Called by the serializers when serialization for this object has started. More...
 
virtual void onSerializationEnded (IReflectable *obj, const UnorderedMap< String, UINT64 > &params)
 Called by the serializers when serialization for this object has ended. More...
 
virtual void onDeserializationStarted (IReflectable *obj, const UnorderedMap< String, UINT64 > &params)
 Called by the serializers when deserialization for this object has started. More...
 
virtual void onDeserializationEnded (IReflectable *obj, const UnorderedMap< String, UINT64 > &params)
 Called by the serializers when deserialization for this object has ended. More...
 
virtual IDiffgetDiffHandler () const
 Returns a handler that determines how are "diffs" generated and applied when it comes to objects of this RTTI type. More...
 
template<class ObjectType , class DataType >
void setPlainValue (ObjectType *object, const String &name, DataType &value)
 Allows you to assign a value to a plain field with the specified name on the provided instance. More...
 
template<class ObjectType , class DataType >
void setPlainArrayValue (ObjectType *object, const String &name, UINT32 index, DataType &value)
 Allows you to assign a value to a plain field array element with the specified name and index on the provided instance. More...
 
template<class ObjectType , class DataType >
void setReflectableValue (ObjectType *object, const String &name, DataType &value)
 Allows you to assign a value to a reflectable field with the specified name on the provided instance. More...
 
template<class ObjectType , class DataType >
void setReflectableArrayValue (ObjectType *object, const String &name, UINT32 index, DataType &value)
 Allows you to assign a value to a reflectable field array element with the specified name and index on the provided instance. More...
 
template<class ObjectType >
void setDataBlockValue (ObjectType *object, const String &name, const SPtr< DataStream > &value, UINT32 size)
 Allows you to assign a value to a managed data block field with the specified name on the provided instance. More...
 
template<class ObjectType , class DataType >
void setReflectablePtrValue (ObjectType *object, const String &name, SPtr< DataType > value)
 Allows you to assign a value to a reflectable pointer field with the specified name on the provided instance. More...
 
template<class ObjectType , class DataType >
void setReflectablePtrArrayValue (ObjectType *object, const String &name, UINT32 index, SPtr< DataType > value)
 Allows you to assign a value to a reflectable pointer field array element with the specified name and index on the provided instance. More...
 
template<class ObjectType , class DataType >
void getPlainValue (ObjectType *object, const String &name, DataType &value)
 Reads a value from a plain field with the specified name from the provided instance. More...
 
template<class ObjectType , class DataType >
void getPlainArrayValue (ObjectType *object, const String &name, UINT32 index, DataType &value)
 Reads a value from a plain array field with the specified name and index from the provided instance. More...
 
template<class ObjectType >
IReflectablegetReflectableValue (ObjectType *object, const String &name)
 Reads a value from a reflectable object field with the specified name from the provided instance. More...
 
template<class ObjectType >
IReflectablegetReflectableArrayValue (ObjectType *object, const String &name, UINT32 index)
 Reads a value from a reflectable object array field with the specified name and index from the provided instance. More...
 
template<class ObjectType >
SPtr< DataStreamgetDataBlockValue (ObjectType *object, const String &name, UINT32 &size)
 Reads a managed data block field with the specified name from the provided instance. More...
 
template<class ObjectType >
SPtr< IReflectablegetReflectablePtrValue (ObjectType *object, const String &name)
 Reads a value from a reflectable object pointer field with the specified name from the provided instance. More...
 
template<class ObjectType >
SPtr< IReflectablegetReflectablePtrArrayValue (ObjectType *object, const String &name, UINT32 index)
 Reads a value from a reflectable pointer array field with the specified name and index from the provided instance. More...
 
template<class ObjectType >
UINT32 getArraySize (ObjectType *object, const String &name)
 Returns the size of the array of the field with the specified name on the provided instance. More...
 
template<class ObjectType >
void setArraySize (ObjectType *object, const String &name, UINT32 size)
 Sets the size of the array of the field with the specified name on the provided instance. More...
 
UINT32 getNumFields () const
 Returns the total number of fields in this RTTI type. More...
 
RTTIFieldgetField (UINT32 idx)
 Returns a field based on the field index. More...
 
RTTIFieldfindField (const String &name)
 Tries to find a field with the specified name. More...
 
RTTIFieldfindField (int uniqueFieldId)
 Tries to find a field with the specified unique ID. More...
 
Internal
virtual void _registerDerivedClass (RTTITypeBase *derivedClass)=0
 Called by the RTTI system when a class is first found in order to form child/parent class hierarchy. More...
 

Method documentation

virtual void _registerDerivedClass ( RTTITypeBase derivedClass)
pure virtual

Called by the RTTI system when a class is first found in order to form child/parent class hierarchy.

Implemented in RTTIType< Type, BaseType, MyRTTIType >.

void addNewField ( RTTIField field)
protected

Tries to add a new field to the fields array, and throws an exception if a field with the same name or id already exists.

Parameters
[in]fieldField, must be non-null.
RTTIField* findField ( const String name)

Tries to find a field with the specified name.

Throws an exception if it can't.

Parameters
nameThe name of the field.
RTTIField* findField ( int  uniqueFieldId)

Tries to find a field with the specified unique ID.

Doesn't throw an exception if it can't find the field (Unlike findField(const String&)).

Parameters
uniqueFieldIdUnique identifier for the field.
Returns
nullptr if it can't find the field.
UINT32 getArraySize ( ObjectType *  object,
const String name 
)

Returns the size of the array of the field with the specified name on the provided instance.

Note
Caller must ensure instance type is valid and that the field as an array.
virtual RTTITypeBase* getBaseClass ( )
pure virtual

Returns RTTI type information for the class that owns this RTTI type.

If the class has not base type, null is returned instead.

Implemented in RTTIType< Type, BaseType, MyRTTIType >.

SPtr<DataStream> getDataBlockValue ( ObjectType *  object,
const String name,
UINT32 &  size 
)

Reads a managed data block field with the specified name from the provided instance.

Note
Caller must ensure instance type is valid for this field.
virtual Vector<RTTITypeBase*>& getDerivedClasses ( )
pure virtual

Returns RTTI type information for all classes that derive from the class that owns this RTTI type.

Implemented in RTTIType< Type, BaseType, MyRTTIType >.

virtual IDiff& getDiffHandler ( ) const
virtual

Returns a handler that determines how are "diffs" generated and applied when it comes to objects of this RTTI type.

A "diff" is a list of differences between two objects that may be saved, viewed or applied to another object to transform it.

RTTIField* getField ( UINT32  idx)

Returns a field based on the field index.

Use getNumFields() to get total number of fields available.

UINT32 getNumFields ( ) const

Returns the total number of fields in this RTTI type.

void getPlainArrayValue ( ObjectType *  object,
const String name,
UINT32  index,
DataType &  value 
)

Reads a value from a plain array field with the specified name and index from the provided instance.

Note
Caller must ensure instance and value types are valid for this field.
void getPlainValue ( ObjectType *  object,
const String name,
DataType &  value 
)

Reads a value from a plain field with the specified name from the provided instance.

Note
Caller must ensure instance and value types are valid for this field.
IReflectable& getReflectableArrayValue ( ObjectType *  object,
const String name,
UINT32  index 
)

Reads a value from a reflectable object array field with the specified name and index from the provided instance.

Note
Caller must ensure instance and value types are valid for this field.
SPtr<IReflectable> getReflectablePtrArrayValue ( ObjectType *  object,
const String name,
UINT32  index 
)

Reads a value from a reflectable pointer array field with the specified name and index from the provided instance.

Note
Caller must ensure instance and value types are valid for this field.
SPtr<IReflectable> getReflectablePtrValue ( ObjectType *  object,
const String name 
)

Reads a value from a reflectable object pointer field with the specified name from the provided instance.

Note
Caller must ensure instance and value types are valid for this field.
IReflectable& getReflectableValue ( ObjectType *  object,
const String name 
)

Reads a value from a reflectable object field with the specified name from the provided instance.

Note
Caller must ensure instance and value types are valid for this field.
virtual UINT32 getRTTIId ( )
pure virtual

Returns an RTTI id that uniquely represents each class in the RTTI system.

virtual const String& getRTTIName ( )
pure virtual

Returns the name of the class owning this RTTI type.

virtual bool isDerivedFrom ( RTTITypeBase base)
pure virtual

Returns true if current RTTI class is derived from base.

(Or if it is the same type as base)

Implemented in RTTIType< Type, BaseType, MyRTTIType >.

virtual SPtr<IReflectable> newRTTIObject ( )
pure virtual

Creates a new instance of the class owning this RTTI type.

virtual void onDeserializationEnded ( IReflectable obj,
const UnorderedMap< String, UINT64 > &  params 
)
virtual

Called by the serializers when deserialization for this object has ended.

At this point you can be sure the instance has been fully deserialized and you may safely use it.

One exception being are fields you marked with RTTI_Flag_WeakRef, as they might be resolved only after deserialization has fully completed for all objects.

virtual void onDeserializationStarted ( IReflectable obj,
const UnorderedMap< String, UINT64 > &  params 
)
virtual

Called by the serializers when deserialization for this object has started.

Use this to do any preprocessing on data you might need during deserialization itself.

virtual void onSerializationEnded ( IReflectable obj,
const UnorderedMap< String, UINT64 > &  params 
)
virtual

Called by the serializers when serialization for this object has ended.

After serialization has ended you can be sure that the type has been fully serialized, and you may clean up any temporary data.

virtual void onSerializationStarted ( IReflectable obj,
const UnorderedMap< String, UINT64 > &  params 
)
virtual

Called by the serializers when serialization for this object has started.

Use this to do any preprocessing on data you might need during serialization itself.

void setArraySize ( ObjectType *  object,
const String name,
UINT32  size 
)

Sets the size of the array of the field with the specified name on the provided instance.

Note
Caller must ensure instance type is valid and that the field as an array. This might clear any existing data from the array.
void setDataBlockValue ( ObjectType *  object,
const String name,
const SPtr< DataStream > &  value,
UINT32  size 
)

Allows you to assign a value to a managed data block field with the specified name on the provided instance.

Note
Caller must ensure instance type is valid for this field.
void setPlainArrayValue ( ObjectType *  object,
const String name,
UINT32  index,
DataType &  value 
)

Allows you to assign a value to a plain field array element with the specified name and index on the provided instance.

Note
Caller must ensure instance and value types are valid for this field.
void setPlainValue ( ObjectType *  object,
const String name,
DataType &  value 
)

Allows you to assign a value to a plain field with the specified name on the provided instance.

Note
Caller must ensure instance and value types are valid for this field.
void setReflectableArrayValue ( ObjectType *  object,
const String name,
UINT32  index,
DataType &  value 
)

Allows you to assign a value to a reflectable field array element with the specified name and index on the provided instance.

Note
Caller must ensure instance and value types are valid for this field.
void setReflectablePtrArrayValue ( ObjectType *  object,
const String name,
UINT32  index,
SPtr< DataType >  value 
)

Allows you to assign a value to a reflectable pointer field array element with the specified name and index on the provided instance.

Note
Caller must ensure instance and value types are valid for this field.
void setReflectablePtrValue ( ObjectType *  object,
const String name,
SPtr< DataType >  value 
)

Allows you to assign a value to a reflectable pointer field with the specified name on the provided instance.

Note
Caller must ensure instance and value types are valid for this field.
void setReflectableValue ( ObjectType *  object,
const String name,
DataType &  value 
)

Allows you to assign a value to a reflectable field with the specified name on the provided instance.

Note
Caller must ensure instance and value types are valid for this field.