Torque2D Reference
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
ConsoleObject Class Reference

#include <consoleObject.h>

+ Inheritance diagram for ConsoleObject:

Public Member Functions

const AbstractClassRep::FieldfindField (StringTableEntry fieldName) const
 Get a reference to a field by name. More...
 
virtual AbstractClassRepgetClassRep () const
 Gets the ClassRep. More...
 
bool setField (const char *fieldName, const char *value)
 Set the value of a field. More...
 
virtual ~ConsoleObject ()
 

Static Public Member Functions

static const char * lookupClassName (const U32 in_classTag)
 Get the classname from a class tag. More...
 
static void initPersistFields ()
 
static void consoleInit ()
 

Protected Member Functions

 ConsoleObject ()
 
 ConsoleObject (const ConsoleObject &)
 

Object Creation

static ConsoleObjectcreate (const char *in_pClassName)
 
static ConsoleObjectcreate (const U32 groupId, const U32 typeId, const U32 in_classId)
 

Fields

static void addGroup (const char *in_pGroupname, const char *in_pGroupDocs=NULL)
 
static void endGroup (const char *in_pGroupname)
 
static void addField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, const U32 in_elementCount=1, EnumTable *in_table=NULL, const char *in_pFieldDocs=NULL)
 
static void addField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::WriteDataNotify in_writeDataFn, const U32 in_elementCount=1, EnumTable *in_table=NULL, const char *in_pFieldDocs=NULL)
 
static void addField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, const char *in_pFieldDocs)
 
static void addField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::WriteDataNotify in_writeDataFn, const char *in_pFieldDocs)
 
static void addFieldV (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, ConsoleTypeValidator *v, const char *in_pFieldDocs=NULL)
 
static void addProtectedField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn=&defaultProtectedGetFn, const U32 in_elementCount=1, EnumTable *in_table=NULL, const char *in_pFieldDocs=NULL)
 
static void addProtectedField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn=&defaultProtectedGetFn, AbstractClassRep::WriteDataNotify in_writeDataFn=&defaultProtectedWriteFn, const U32 in_elementCount=1, EnumTable *in_table=NULL, const char *in_pFieldDocs=NULL)
 
static void addProtectedField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn=&defaultProtectedGetFn, const char *in_pFieldDocs=NULL)
 
static void addProtectedField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn=&defaultProtectedGetFn, AbstractClassRep::WriteDataNotify in_writeDataFn=&defaultProtectedWriteFn, const char *in_pFieldDocs=NULL)
 
static void addDepricatedField (const char *fieldName)
 
static bool removeField (const char *in_pFieldname)
 

Field List

const AbstractClassRep::FieldListgetFieldList () const
 Get a list of all the fields. This information cannot be modified. More...
 
AbstractClassRep::FieldListgetModifiableFieldList ()
 
bool & getDynamicGroupExpand ()
 

ConsoleObject Implementation

These functions are implemented in every subclass of ConsoleObject by an IMPLEMENT_CONOBJECT or IMPLEMENT_CO_* macro.

S32 getClassId (U32 netClassGroup) const
 
const char * getClassName () const
 
static AbstractClassRepgetStaticClassRep ()
 Get the abstract class information for this class. More...
 
static AbstractClassRepgetParentStaticClassRep ()
 Get the abstract class information for this class's superclass. More...
 

Detailed Description

Interface class to the console.

The Basics

Any object which you want to work with the console system should derive from this, and access functionality through the static interface.

This class is always used with the DECLARE_CONOBJECT and IMPLEMENT_* macros.

// A very basic example object. It will do nothing!
class TorqueObject : public ConsoleObject {
// Must provide a Parent typedef so the console system knows what we inherit from.
typedef ConsoleObject Parent;
// This does a lot of menial declaration for you.
DECLARE_CONOBJECT(TorqueObject);
// This is for us to register our fields in.
static void initPersistFields();
// A sample field.
S8 mSample;
}
// And the accordant implementation...
IMPLEMENT_CONOBJECT(TorqueObject);
void TorqueObject::initPersistFields()
{
// If you want to inherit any fields from the parent (you do), do this:
Parent::initPersistFields();
// Pass the field, the type, the offset, and a usage string.
addField("sample", TypeS8, Offset(mSample, TorqueObject), "A test field.");
}

That's all you need to do to get a class registered with the console system. At this point, you can instantiate it via script, tie methods to it using ConsoleMethod, register fields, and so forth. You can also register any global variables related to the class by creating a consoleInit() method.

You will need to use different IMPLEMENT_ macros in different cases; for instance, if you are making a NetObject (for ghosting), a DataBlock, or a NetEvent.

See Also
AbstractClassRep for gory implementation details.

Constructor & Destructor Documentation

ConsoleObject ( )
inlineprotected
Deprecated:
This is disallowed.
ConsoleObject ( const ConsoleObject )
protected
Deprecated:
This is disallowed.
~ConsoleObject ( )
virtual

Member Function Documentation

void addDepricatedField ( const char *  fieldName)
staticprotected

Add a deprecated field.

A deprecated field will always be undefined, even if you assign a value to it. This is useful when you need to make sure that a field is not being used anymore.

void addField ( const char *  in_pFieldname,
const U32  in_fieldType,
const dsize_t  in_fieldOffset,
const U32  in_elementCount = 1,
EnumTable in_table = NULL,
const char *  in_pFieldDocs = NULL 
)
staticprotected

Register a complex field.

Parameters
in_pFieldnameName of the field.
in_fieldTypeType of the field.
See Also
ConsoleDynamicTypes
Parameters
in_fieldOffsetOffset to the field from the start of the class; calculated using the Offset() macro.
in_elementCountNumber of elements in this field. Arrays of elements are assumed to be contiguous in memory.
in_tableAn EnumTable, if this is an enumerated field.
in_pFieldDocsUsage string for this field.
See Also
console_autodoc
void addField ( const char *  in_pFieldname,
const U32  in_fieldType,
const dsize_t  in_fieldOffset,
AbstractClassRep::WriteDataNotify  in_writeDataFn,
const U32  in_elementCount = 1,
EnumTable in_table = NULL,
const char *  in_pFieldDocs = NULL 
)
staticprotected

Register a complex field with a write notify.

Parameters
in_pFieldnameName of the field.
in_fieldTypeType of the field.
See Also
ConsoleDynamicTypes
Parameters
in_fieldOffsetOffset to the field from the start of the class; calculated using the Offset() macro.
in_writeDataFnThis method will return whether the field should be written or not.
in_elementCountNumber of elements in this field. Arrays of elements are assumed to be contiguous in memory.
in_tableAn EnumTable, if this is an enumerated field.
in_pFieldDocsUsage string for this field.
See Also
console_autodoc
void addField ( const char *  in_pFieldname,
const U32  in_fieldType,
const dsize_t  in_fieldOffset,
const char *  in_pFieldDocs 
)
staticprotected

Register a simple field.

Parameters
in_pFieldnameName of the field.
in_fieldTypeType of the field.
See Also
ConsoleDynamicTypes
Parameters
in_fieldOffsetOffset to the field from the start of the class; calculated using the Offset() macro.
in_pFieldDocsUsage string for this field.
See Also
console_autodoc
void addField ( const char *  in_pFieldname,
const U32  in_fieldType,
const dsize_t  in_fieldOffset,
AbstractClassRep::WriteDataNotify  in_writeDataFn,
const char *  in_pFieldDocs 
)
staticprotected

Register a simple field with a write notify.

Parameters
in_pFieldnameName of the field.
in_fieldTypeType of the field.
See Also
ConsoleDynamicTypes
Parameters
in_fieldOffsetOffset to the field from the start of the class; calculated using the Offset() macro.
in_writeDataFnThis method will return whether the field should be written or not.
in_pFieldDocsUsage string for this field.
See Also
console_autodoc
void addFieldV ( const char *  in_pFieldname,
const U32  in_fieldType,
const dsize_t  in_fieldOffset,
ConsoleTypeValidator v,
const char *  in_pFieldDocs = NULL 
)
staticprotected

Register a validated field.

A validated field is just like a normal field except that you can't have it be an array, and that you give it a pointer to a ConsoleTypeValidator subclass, which is then used to validate any value placed in it. Invalid values are ignored and an error is printed to the console.

See Also
addField
typeValidators.h
void addGroup ( const char *  in_pGroupname,
const char *  in_pGroupDocs = NULL 
)
staticprotected

Mark the beginning of a group of fields.

This is used in the consoleDoc system.

See Also
console_autodoc
void addProtectedField ( const char *  in_pFieldname,
const U32  in_fieldType,
const dsize_t  in_fieldOffset,
AbstractClassRep::SetDataNotify  in_setDataFn,
AbstractClassRep::GetDataNotify  in_getDataFn = &defaultProtectedGetFn,
const U32  in_elementCount = 1,
EnumTable in_table = NULL,
const char *  in_pFieldDocs = NULL 
)
staticprotected

Register a complex protected field.

Parameters
in_pFieldnameName of the field.
in_fieldTypeType of the field.
See Also
ConsoleDynamicTypes
Parameters
in_fieldOffsetOffset to the field from the start of the class; calculated using the Offset() macro.
in_setDataFnWhen this field gets set, it will call the callback provided.
See Also
console_protected
Parameters
in_getDataFnWhen this field is accessed for it's data, it will return the value of this function
in_elementCountNumber of elements in this field. Arrays of elements are assumed to be contiguous in memory.
in_tableAn EnumTable, if this is an enumerated field.
in_pFieldDocsUsage string for this field.
See Also
console_autodoc
void addProtectedField ( const char *  in_pFieldname,
const U32  in_fieldType,
const dsize_t  in_fieldOffset,
AbstractClassRep::SetDataNotify  in_setDataFn,
AbstractClassRep::GetDataNotify  in_getDataFn = &defaultProtectedGetFn,
AbstractClassRep::WriteDataNotify  in_writeDataFn = &defaultProtectedWriteFn,
const U32  in_elementCount = 1,
EnumTable in_table = NULL,
const char *  in_pFieldDocs = NULL 
)
staticprotected

Register a complex protected field.

Parameters
in_pFieldnameName of the field.
in_fieldTypeType of the field.
See Also
ConsoleDynamicTypes
Parameters
in_fieldOffsetOffset to the field from the start of the class; calculated using the Offset() macro.
in_setDataFnWhen this field gets set, it will call the callback provided.
See Also
console_protected
Parameters
in_getDataFnWhen this field is accessed for it's data, it will return the value of this function
in_writeDataFnThis method will return whether the field should be written or not.
in_elementCountNumber of elements in this field. Arrays of elements are assumed to be contiguous in memory.
in_tableAn EnumTable, if this is an enumerated field.
in_pFieldDocsUsage string for this field.
See Also
console_autodoc
void addProtectedField ( const char *  in_pFieldname,
const U32  in_fieldType,
const dsize_t  in_fieldOffset,
AbstractClassRep::SetDataNotify  in_setDataFn,
AbstractClassRep::GetDataNotify  in_getDataFn = &defaultProtectedGetFn,
const char *  in_pFieldDocs = NULL 
)
staticprotected

Register a simple protected field.

Parameters
in_pFieldnameName of the field.
in_fieldTypeType of the field.
See Also
ConsoleDynamicTypes
Parameters
in_fieldOffsetOffset to the field from the start of the class; calculated using the Offset() macro.
in_setDataFnWhen this field gets set, it will call the callback provided.
See Also
console_protected
Parameters
in_getDataFnWhen this field is accessed for it's data, it will return the value of this function
in_pFieldDocsUsage string for this field.
See Also
console_autodoc
void addProtectedField ( const char *  in_pFieldname,
const U32  in_fieldType,
const dsize_t  in_fieldOffset,
AbstractClassRep::SetDataNotify  in_setDataFn,
AbstractClassRep::GetDataNotify  in_getDataFn = &defaultProtectedGetFn,
AbstractClassRep::WriteDataNotify  in_writeDataFn = &defaultProtectedWriteFn,
const char *  in_pFieldDocs = NULL 
)
staticprotected

Register a simple protected field.

Parameters
in_pFieldnameName of the field.
in_fieldTypeType of the field.
See Also
ConsoleDynamicTypes
Parameters
in_fieldOffsetOffset to the field from the start of the class; calculated using the Offset() macro.
in_setDataFnWhen this field gets set, it will call the callback provided.
See Also
console_protected
Parameters
in_getDataFnWhen this field is accessed for it's data, it will return the value of this function
in_writeDataFnThis method will return whether the field should be written or not.
in_pFieldDocsUsage string for this field.
See Also
console_autodoc
void consoleInit ( )
static

Register global constant variables and do other one-time initialization tasks in a subclass of ConsoleObject.

Deprecated:
You should use ConsoleMethod and ConsoleFunction, not this, to register methods or commands.
See Also
console
ConsoleObject * create ( const char *  in_pClassName)
inlinestatic
ConsoleObject * create ( const U32  groupId,
const U32  typeId,
const U32  in_classId 
)
inlinestatic
void endGroup ( const char *  in_pGroupname)
staticprotected

Mark the end of a group of fields.

This is used in the consoleDoc system.

See Also
console_autodoc
const AbstractClassRep::Field * findField ( StringTableEntry  fieldName) const
inline

Get a reference to a field by name.

S32 getClassId ( U32  netClassGroup) const
inline

Get our network-layer class id.

Parameters
netClassGroupThe net class for which we want our ID.
See Also
const char * getClassName ( ) const
inline

Get our compiler and platform independent class name.

Note
This name can be used to instantiate another instance using create()
AbstractClassRep * getClassRep ( ) const
virtual

Gets the ClassRep.

bool & getDynamicGroupExpand ( )
inline

Get a handle to a boolean telling us if we expanded the dynamic group.

See Also
GuiInspector::Inspect()
const AbstractClassRep::FieldList & getFieldList ( ) const
inline

Get a list of all the fields. This information cannot be modified.

AbstractClassRep::FieldList & getModifiableFieldList ( )
inline

Get a list of all the fields, set up so we can modify them.

Note
This is a bad trick to pull if you aren't very careful, since you can blast field data!
static AbstractClassRep* getParentStaticClassRep ( )
inlinestatic

Get the abstract class information for this class's superclass.

static AbstractClassRep* getStaticClassRep ( )
inlinestatic

Get the abstract class information for this class.

void initPersistFields ( )
static

Register dynamic fields in a subclass of ConsoleObject.

See Also
addField(), addFieldV(), addDepricatedField(), addGroup(), endGroup()
static const char* lookupClassName ( const U32  in_classTag)
static

Get the classname from a class tag.

bool removeField ( const char *  in_pFieldname)
staticprotected

Remove a field.

Sometimes, you just have to remove a field!

Returns
True on success.
bool setField ( const char *  fieldName,
const char *  value 
)
inline

Set the value of a field.


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