Type

class ReflectExport(reflect) Type : public Dynamic
Summary
Type
Functions
TypeConstructs a class.
~TypeDestructs this class and unlinks it from the class hierarchy.
ParentGets the parent (base class) of this Type.
SetParentSets the parent (base class) of this Type.
DerivesChecks if this class represents a subclass of another.
Derives (template)Checks if this class represents a subclass of another.
ChildThe first subclass of this class or NULL if there are no subclasses.
SiblingThe next sibling of this class, or itself if there are no siblings.
LoadTypesInitializes all types which have been static initialized.
UnloadTypesReverses the effect of Type::LoadTypes.
AnyRootTypeRetrieves a root (any root) of the type hierarchy.
FindTypeRetrieves a type by name.
FindType(char*)Retrieves a type by name.
SetNameSets the name of the type and calls RegisterName to it in a global map.
NameThe registered name of this type.
NextTypeToLoadThe next type in a NULL terminated chain of types to load in Type::LoadTypes.
FirstTypeToLoadThe first class in a NULL terminated chain of classes to load in the next Type::LoadTypes.
SerializeSerialize defines how objects represented by this type are serialized.
OpaqueCastCasts a type represented by this Type to a void *, used by Serialize.
TranslucentCastCasts a void * from OpaqueCast back to a Type.
SetBasicOperationsSets the factory function for this class.
SizeThe size of the object represented by this class.
AlignmentThe minimum required alignment of the object represented by this class.
ConstructConstructs an instance of this type.
DestructDestructs an instance of this type.
AbstractChecks if the class is Abstract.
RegisterConversionRegisters a cast from type from to this type.
CanConvertFromChecks if a cast from the specified type exists.
CanConvertFrom (template)Checks if a cast from the specified type exists.
ConvertValueUses conversions registered with RegisterConversion.

Functions

Type

Type(void (*init_cb)() =  0)

Constructs a class.

Parameters

init_cbthe function to run to initialize this class.

See Also

~Type

~Type()

Destructs this class and unlinks it from the class hierarchy.

Parent

Type *Parent() const

Gets the parent (base class) of this Type.

SetParent

void SetParent(Type *parent)

Sets the parent (base class) of this Type.

Derives

bool DerivesType(const Type *other) const

Checks if this class represents a subclass of another.

Parameters

otheranother class.

Returns

true if this class is a subclass of other

Derives (template)

template<typename T> bool Derives() const

Checks if this class represents a subclass of another.

Template version of Derives.

Child

Type *Child() const

The first subclass of this class or NULL if there are no subclasses.

The Sibling method can be used to iterate over the other subclasses.

Sibling

Type *Sibling() const

The next sibling of this class, or itself if there are no siblings.  Siblings are linked in a ring, so be careful when iterating over them.  The folling idiom can be used to iterator over the subclasses of clazz:

if(Type *child = clazz->Child()) do
{
   // PROCESS child
}
while((child = child->Sibling()) != clazz->Child());

LoadTypes

static Type *LoadTypes()

Initializes all types which have been static initialized.

Returns

The first class in the current class load chain.

See Also

UnloadTypes

static void UnloadTypes(Type *)

Reverses the effect of Type::LoadTypes.

Note: this hasn’t been tested much, it is probable that doing this is unsafe.

TODO

  • Remove conversions from all classes to unloaded types.

AnyRootType

static Type *AnyRootType()

Retrieves a root (any root) of the type hierarchy. roots are connected by <NextSibling>

FindType

static Type *FindType(string::FoundSharedString)

Retrieves a type by name.

Paramters

typenamethe name of a class.

Returns

The type or NULL if no class is registered with that name.

FindType(char*)

static Type *FindType(const char *)

Retrieves a type by name.

Paramters

typenamethe name of a type.

Result

The type or NULL if no type is registered with that name.

SetName

void SetName(const char *name)

Sets the name of the type and calls RegisterName to it in a global map.

Name

const char *Name() const

The registered name of this type.

NextTypeToLoad

Type *NextTypeToLoad() const

The next type in a NULL terminated chain of types to load in Type::LoadTypes.  The type chain is preserved after Type::LoadTypes.

FirstTypeToLoad

static Type *FirstTypeToLoad()

The first class in a NULL terminated chain of classes to load in the next Type::LoadTypes.  After Type::LoadTypes is called this will be NULL.

Serialize

virtual void Serialize(const void *in,
void *out,
Reflector &reflector) const

Serialize defines how objects represented by this type are serialized.  The void * arguments must be converted from typed pointers the by the static template function Type::OpaqueCast, subtypes may hide the default implementation.

See Also

OpaqueCast

template<typename Type> static void *OpaqueCast(Type *ptr)

Casts a type represented by this Type to a void *, used by Serialize.  (there are const and non-const versions of this function)

See Also

TranslucentCast

template<typename T> static T *TranslucentCast(void *ptr)

Casts a void * from OpaqueCast back to a Type.  (there are const and non-const versions of this function)

See Also

SetBasicOperations

void SetBasicOperations(unsigned size,
unsigned alignment,
void *(*construct)(void *),
void *(*destruct)(void *))

Sets the factory function for this class.

Size

unsigned Size() const

Returns

The size of the object represented by this class.

Alignment

unsigned Alignment() const

Returns

The minimum required alignment of the object represented by this class.

Construct

void *Construct(void *) const

Constructs an instance of this type.  The pointer provided should be at least Size bytes and aligned to Alignment.

Parameters

dataan aligned pointer to at least Alignment bytes of memory.

Returns

An OpaqueCast of the object (if it’s not Abstract)

Destruct

void *Destruct(void *) const

Destructs an instance of this type.  The pointer should be returned from Construct, or an opaque_cast of a pointer to data of this type.

Parameters

datathe result of a previous Construct, or the OpaqueCast of an object represented by this class.

Returns

The void pointer that would be passed to Construct originally.  This would be an allocation pointer, not an opaque pointer.

Abstract

bool Abstract() const

Checks if the class is Abstract.

See Also

Returns

trueif the class has no size.

RegisterConversion

void RegisterConversion(const Type *from,
void (*)(void *, const void *))

Registers a cast from type from to this type.

See Also

CanConvertFrom

virtual bool CanConvertFrom(const Type *from) const

Checks if a cast from the specified type exists.

CanConvertFrom (template)

template<typename T> bool CanConvertFrom() const

Checks if a cast from the specified type exists.

ConvertValue

virtual bool ConvertValue(void *opaque,
const void *source,
const Type *from) const

Uses conversions registered with RegisterConversion.

Returns

trueif a conversion from from is found.

See Also

class ReflectExport(reflect) Type : public Dynamic
Type(void (*init_cb)() =  0)
Constructs a class.
~Type()
Destructs this class and unlinks it from the class hierarchy.
Type *Parent() const
Gets the parent (base class) of this Type.
void SetParent(Type *parent)
Sets the parent (base class) of this Type.
bool DerivesType(const Type *other) const
Checks if this class represents a subclass of another.
template<typename T> bool Derives() const
Checks if this class represents a subclass of another.
Type *Child() const
The first subclass of this class or NULL if there are no subclasses.
Type *Sibling() const
The next sibling of this class, or itself if there are no siblings.
static Type *LoadTypes()
Initializes all types which have been static initialized.
static void UnloadTypes(Type *)
Reverses the effect of Type::LoadTypes.
static Type *AnyRootType()
Retrieves a root (any root) of the type hierarchy.
static Type *FindType(string::FoundSharedString)
Retrieves a type by name.
static Type *FindType(const char *)
Retrieves a type by name.
void SetName(const char *name)
Sets the name of the type and calls RegisterName to it in a global map.
const char *Name() const
The registered name of this type.
Type *NextTypeToLoad() const
The next type in a NULL terminated chain of types to load in Type::LoadTypes.
static Type *FirstTypeToLoad()
The first class in a NULL terminated chain of classes to load in the next Type::LoadTypes.
virtual void Serialize(const void *in,
void *out,
Reflector &reflector) const
Serialize defines how objects represented by this type are serialized.
template<typename Type> static void *OpaqueCast(Type *ptr)
Casts a type represented by this Type to a void *, used by Serialize.
template<typename T> static T *TranslucentCast(void *ptr)
Casts a void * from OpaqueCast back to a Type.
void SetBasicOperations(unsigned size,
unsigned alignment,
void *(*construct)(void *),
void *(*destruct)(void *))
Sets the factory function for this class.
unsigned Size() const
The size of the object represented by this class.
unsigned Alignment() const
The minimum required alignment of the object represented by this class.
void *Construct(void *) const
Constructs an instance of this type.
void *Destruct(void *) const
Destructs an instance of this type.
bool Abstract() const
Checks if the class is Abstract.
void RegisterConversion(const Type *from,
void (*)(void *, const void *))
Registers a cast from type from to this type.
virtual bool CanConvertFrom(const Type *from) const
Checks if a cast from the specified type exists.
template<typename T> bool CanConvertFrom() const
Checks if a cast from the specified type exists.
virtual bool ConvertValue(void *opaque,
const void *source,
const Type *from) const
Uses conversions registered with RegisterConversion.
template<typename T> inline void *opaque_cast(*value)
Turns a typed pointer (of type Type *) into an opaque pointer (a void *), for use with the class Signature::TheClass.
template<typename Type> inline Type translucent_cast(void *value)
Turns an opaque pointer (of type void *) into a typed pointer of the specified type.
class ReflectExport(reflect) Variant
Variants represent objects of any reflected type.
template<typename T> class Type::DescriptionHelper
Template base class for description helpers, used in reflection definitions.
Close