AbstractClassRep
Engine/source/console/consoleObject.h
Core functionality for class manipulation.
Classes:
Fields
ACRFieldTypes { ARCFirstCustomField = 0xFFFFFFFB StartArrayFieldType = 0xFFFFFFFB EndArrayFieldType = 0xFFFFFFFC StartGroupFieldType = 0xFFFFFFFD EndGroupFieldType = 0xFFFFFFFE DeprecatedFieldType = 0xFFFFFFFF }
These are special field type values used to mark groups and arrays in the field list.
FieldFlags { FIELD_HideInInspectors = BIT( 0 ) FIELD_ComponentInspectors = BIT(1) FIELD_CustomInspectors = BIT(2) }
findField(StringTableEntry fieldName)
bool(*
SetDataNotify )(void *obj, const char *array, const char *data)
This is a function pointer typedef to support get/set callbacks for fields.
const char *(*
GetDataNotify )(void *obj, const char *data)
bool(*
WriteDataNotify )(void *obj, StringTableEntry pFieldName)
This is a function pointer typedef to support optional writing for fields.
Representation Interface
getClassId(U32 netClassGroup)
getCommonParent(const AbstractClassRep * otherClass)
Return the name of this class.
Return the namespace that contains the methods of this class.
Return the AbstractClassRep of the class that this class is derived from.
getContainerChildClass(const bool recurse)
Return the next class in the global class list link chain.
bool
isSubclassOf(const AbstractClassRep * klass)
Helper class to see if we are a given class, or a subclass thereof by comparing AbstractClassRep pointers.
bool
isSubclassOf(const char * klass)
Helper class to see if we are a given class, or a subclass thereof by comparing the class name strings.
bool
isClass(const AbstractClassRep * acr)
create()
findFieldRoot(StringTableEntry fieldName)
getClassCRC(U32 netClassGroup)
Return the head of the global class list.
Mask indicating in which NetGroups this object belongs.
Stores the NetClass of this class.
Stores the NetDirection of this class.
Size of instances in bytes.
const char *
Categories
const char *
Return the space separated category path for the class.
const char *
Return a short description string suitable for displaying in tooltips.
const char *
Abstract Class Database
classTable [NetClassGroupsCount][NetClassTypesCount]
bool
NetClassCount [NetClassGroupsCount][NetClassTypesCount]
NetClassBitSize [NetClassGroupsCount][NetClassTypesCount]
'Tructors
AbstractClassRep(S32 * conIdPtr, const char * typeName)
Console Type Interface
void *
Allocate a single value.
deleteNativeVariable(void * var)
Delete a single value allocated with getNativeVariable().
Public Types
Parent
void(*
WriteCustomTamlSchema )(const AbstractClassRep *pClassRep, TiXmlElement *pParentElement)
Allows the writing of a custom TAML schema.
Public Friends
class
Public Attributes
bool
bool
Public Functions
bool
bool
Detailed Description
Core functionality for class manipulation.
Introduction (or, Why AbstractClassRep?)
Many of Torque's subsystems, especially network, console, and sim, require the ability to programatically instantiate classes. For instance, when objects are ghosted, the networking layer needs to be able to create an instance of the object on the client. When the console scripting language runtime encounters the "new" keyword, it has to be able to fill that request.
Since standard C++ doesn't provide a function to create a new instance of an arbitrary class at runtime, one must be created. This is what AbstractClassRep and ConcreteClassRep are all about. They allow the registration and instantiation of arbitrary classes at runtime.
In addition, ACR keeps track of the fields (registered via addField() and co.) of a class, allowing programmatic access of class fields.
note:In general, you will only access the functionality implemented in this class via ConsoleObject::create(). Most of the time, you will only ever need to use this part part of the engine indirectly - ie, you will use the networking system or the console, or ConsoleObject, and they will indirectly use this code. The following discussion is really only relevant for advanced engine users.
NetClasses and Class IDs
Torque supports a notion of group, type, and direction for objects passed over the network. Class IDs are assigned sequentially per-group, per-type, so that, for instance, the IDs assigned to Datablocks are seperate from the IDs assigned to NetObjects or NetEvents. This can translate into significant bandwidth savings (especially since the size of the fields for transmitting these bits are determined at run-time based on the number of IDs given out.
AbstractClassRep Internals
Much like ConsoleConstructor, ACR does some preparatory work at runtime before execution is passed to main(). In actual fact, this preparatory work is done by the ConcreteClassRep template. Let's examine this more closely.
If we examine ConsoleObject, we see that two macros must be used in the definition of a properly integrated objects. From the ConsoleObject example:
// This is from inside the class definition... DECLARE_CONOBJECT(TorqueObject); // And this is from outside the class definition... IMPLEMENT_CONOBJECT(TorqueObject);
What do these things actually do?
Not all that much, in fact. They expand to code something like this:
// This is from inside the class definition... static ConcreteClassRep<TorqueObject> dynClassRep; static AbstractClassRep* getParentStaticClassRep(); static AbstractClassRep* getStaticClassRep(); virtual AbstractClassRep* getClassRep() const;
// And this is from outside the class definition... AbstractClassRep* TorqueObject::getClassRep() const { return &TorqueObject::dynClassRep; } AbstractClassRep* TorqueObject::getStaticClassRep() { return &dynClassRep; } AbstractClassRep* TorqueObject::getParentStaticClassRep() { return Parent::getStaticClassRep(); } ConcreteClassRep<TorqueObject> TorqueObject::dynClassRep("TorqueObject", 0, -1, 0);
As you can see, getClassRep(), getStaticClassRep(), and getParentStaticClassRep() are just accessors to allow access to various ConcreteClassRep instances. This is where the Parent typedef comes into play as well - it lets getParentStaticClassRep() get the right class rep.
In addition, dynClassRep is declared as a member of TorqueObject, and defined later on. Much like ConsoleConstructor, ConcreteClassReps add themselves to a global linked list in their constructor.
Then, when AbstractClassRep::initialize() is called, from Con::init(), we iterate through the list and perform the following tasks:
Sets up a Namespace for each class.
Call the init() method on each ConcreteClassRep. This method:
Links namespaces between parent and child classes, using Con::classLinkNamespaces.
Calls initPersistFields() and consoleInit().
As a result of calling initPersistFields, the field list for the class is populated.
Assigns network IDs for classes based on their NetGroup membership. Determines bit allocations for network ID fields.
Fields
ACRFieldTypes
Enumerator
- ARCFirstCustomField = 0xFFFFFFFB
The first custom field type...
all fields types greater or equal to this one are not console data types.
- StartArrayFieldType = 0xFFFFFFFB
Marks the start of a fixed size array of fields.
see:addArray
- EndArrayFieldType = 0xFFFFFFFC
Marks the end of a fixed size array of fields.
see:endArray
- StartGroupFieldType = 0xFFFFFFFD
Marks the beginning of a group of fields.
see:addGroup
- EndGroupFieldType = 0xFFFFFFFE
Marks the beginning of a group of fields.
see:endGroup
- DeprecatedFieldType = 0xFFFFFFFF
Marks a field that is depreciated and no longer stores a value.
see:addDeprecatedField
These are special field type values used to mark groups and arrays in the field list.
addArray, endArray
addGroup, endGroup
addGroup, endGroup
addDeprecatedField
FieldFlags
Enumerator
- FIELD_HideInInspectors = BIT( 0 )
Do not show the field in inspectors.
- FIELD_ComponentInspectors = BIT(1)
Custom fields used by components.
They are likely to be non-standard size/configuration, so They are handled specially
- FIELD_CustomInspectors = BIT(2)
Display as a button in inspectors.
findField(StringTableEntry fieldName)
FieldList mFieldList
bool mDynamicGroupExpand
typedef bool(* SetDataNotify )(void *obj, const char *array, const char *data)
This is a function pointer typedef to support get/set callbacks for fields.
typedef const char *(* GetDataNotify )(void *obj, const char *data)
typedef bool(* WriteDataNotify )(void *obj, StringTableEntry pFieldName)
This is a function pointer typedef to support optional writing for fields.
typedef Vector< Field > FieldList
Representation Interface
getClassId(U32 netClassGroup)
getCommonParent(const AbstractClassRep * otherClass)
getClassName()
Return the name of this class.
getNameSpace()
Return the namespace that contains the methods of this class.
getParentClass()
Return the AbstractClassRep of the class that this class is derived from.
getContainerChildClass(const bool recurse)
Reimplemented by: ConcreteAbstractClassRep, RuntimeClassRep
getCustomTamlSchema(void )
Reimplemented by: ConcreteAbstractClassRep, RuntimeClassRep
getSizeof()
Return the size of instances of this class in bytes.
getNextClass()
Return the next class in the global class list link chain.
isSubclassOf(const AbstractClassRep * klass)
Helper class to see if we are a given class, or a subclass thereof by comparing AbstractClassRep pointers.
isSubclassOf(const char * klass)
Helper class to see if we are a given class, or a subclass thereof by comparing the class name strings.
isClass(const AbstractClassRep * acr)
create()
Reimplemented by: ConcreteAbstractClassRep, ConcreteClassRep, RuntimeClassRep
findFieldRoot(StringTableEntry fieldName)
getClassCRC(U32 netClassGroup)
getClassList()
Return the head of the global class list.
init()
Reimplemented by: ConcreteAbstractClassRep
S32 mClassGroupMask
Mask indicating in which NetGroups this object belongs.
S32 mClassType
Stores the NetClass of this class.
S32 mNetEventDir
Stores the NetDirection of this class.
S32 mClassId [NetClassGroupsCount]
Stores the IDs assigned to this class for each group.
S32 mClassSizeof
Size of instances in bytes.
const char * mClassName
AbstractClassRep * nextClass
AbstractClassRep * parentClass
Namespace * mNamespace
Categories
getCategory()
Return the space separated category path for the class.
getDescription()
Return a short description string suitable for displaying in tooltips.
const char * mCategory
const char * mDescription
Abstract Class Database
registerClassRep(AbstractClassRep * )
findClassRep(const char * in_pClassName)
findClassRep(U32 groupId, U32 typeId, U32 classId)
removeClassRep(AbstractClassRep * )
initialize()
shutdown()
create(const char * in_pClassName)
create(const U32 groupId, const U32 typeId, const U32 in_classId)
AbstractClassRep ** classTable [NetClassGroupsCount][NetClassTypesCount]
AbstractClassRep * classLinkList
U32 classCRC [NetClassGroupsCount]
bool initialized
U32 NetClassCount [NetClassGroupsCount][NetClassTypesCount]
U32 NetClassBitSize [NetClassGroupsCount][NetClassTypesCount]
'Tructors
AbstractClassRep(S32 * conIdPtr, const char * typeName)
Parameters:
conIdPtr | Pointer to the static S32 console ID. |
conTypeName | Console type name. |
Console Type Interface
getNativeVariable()
Reimplemented from: ConsoleBaseType
deleteNativeVariable(void * var)
Reimplemented from: ConsoleBaseType
Public Types
typedef ConsoleBaseType Parent
typedef void(* WriteCustomTamlSchema )(const AbstractClassRep *pClassRep, TiXmlElement *pParentElement)
Allows the writing of a custom TAML schema.