torque Torque Game Engine Documentation
TGE Version 1.5.2

ConsoleConstructor Class Reference

#include <console.h>


Detailed Description

This is the backend for the ConsoleMethod()/ConsoleFunction() macros.

See the group ConsoleConstructor Innards for specifics on how this works.

See also:
Console Auto-Documentation


Entry Type Fields

One of these is set based on the type of entry we want inserted in the console.

Console Auto-Documentation

StringCallback sc
 A function/method that returns a string.
IntCallback ic
 A function/method that returns an int.
FloatCallback fc
 A function/method that returns a float.
VoidCallback vc
 A function/method that returns nothing.
BoolCallback bc
 A function/method that returns a bool.
bool group
 Indicates that this is a group marker.
bool overload
 Indicates that this is an overload marker.

ConsoleConstructer Innards

The ConsoleConstructor class is used as the backend for the ConsoleFunction() and ConsoleMethod() macros.

The way it works takes advantage of several properties of C++.

The ConsoleFunction()/ConsoleMethod() macros wrap the declaration of a ConsoleConstructor.

      // The definition of a ConsoleFunction using the macro
      ConsoleFunction(ExpandFilename, const char*, 2, 2, "(string filename)")
      {
         argc;
         char* ret = Con::getReturnBuffer( 1024 );
         Con::expandScriptFilename(ret, 1024, argv[1]);
         return ret;
      }

      // Resulting code
      static const char* cExpandFilename(SimObject *, S32, const char **argv);
      static ConsoleConstructor
            gExpandFilenameobj(NULL,"ExpandFilename", cExpandFilename,
            "(string filename)", 2, 2);
      static const char* cExpandFilename(SimObject *, S32 argc, const char **argv)
      {
         argc;
         char* ret = Con::getReturnBuffer( 1024 );
         Con::expandScriptFilename(ret, 1024, argv[1]);
         return ret;
      }

      // A similar thing happens when you do a ConsoleMethod.

As you can see, several global items are defined when you use the ConsoleFunction method. The macro constructs the name of these items from the parameters you passed it. Your implementation of the console function is is placed in a function with a name based on the actual name of the console funnction. In addition, a ConsoleConstructor is declared.

Because it is defined as a global, the constructor for the ConsoleConstructor is called before execution of main() is started. The constructor is called once for each global ConsoleConstructor variable, in the order in which they were defined (this property only holds true within file scope).

We have ConsoleConstructor create a linked list at constructor time, by storing a static pointer to the head of the list, and keeping a pointer to the next item in each instance of ConsoleConstructor. init() is a helper function in this process, automatically filling in commonly used fields and updating first and next as needed. In this way, a list of items to add to the console is assemble in memory, ready for use, before we start execution of the program proper.

In Con::init(), ConsoleConstructor::setup() is called to process this prepared list. Each item in the list is iterated over, and the appropriate Con namespace functions (usually Con::addCommand) are invoked to register the ConsoleFunctions and ConsoleMethods in the appropriate namespaces.

See also:
Namespace

Con



ConsoleConstructornext
static ConsoleConstructorfirst
void init (const char *cName, const char *fName, const char *usg, S32 minArgs, S32 maxArgs)
static void setup ()

Basic Console Constructors

 ConsoleConstructor (const char *className, const char *funcName, StringCallback sfunc, const char *usage, S32 minArgs, S32 maxArgs)
 ConsoleConstructor (const char *className, const char *funcName, IntCallback ifunc, const char *usage, S32 minArgs, S32 maxArgs)
 ConsoleConstructor (const char *className, const char *funcName, FloatCallback ffunc, const char *usage, S32 minArgs, S32 maxArgs)
 ConsoleConstructor (const char *className, const char *funcName, VoidCallback vfunc, const char *usage, S32 minArgs, S32 maxArgs)
 ConsoleConstructor (const char *className, const char *funcName, BoolCallback bfunc, const char *usage, S32 minArgs, S32 maxArgs)

Magic Console Constructors

These perform various pieces of "magic" related to consoleDoc functionality.

Console Auto-Documentation

 ConsoleConstructor (const char *className, const char *groupName, const char *usage)
 Indicates a group marker.

Data Fields

S32 mina
 Minimum/maximum number of arguments for the function.
S32 maxa
const char * usage
 Usage string.
const char * funcName
 Function name.
const char * className
 Class name.


Constructor & Destructor Documentation

ConsoleConstructor::ConsoleConstructor ( const char *  className,
const char *  funcName,
StringCallback  sfunc,
const char *  usage,
S32  minArgs,
S32  maxArgs 
)

ConsoleConstructor::ConsoleConstructor ( const char *  className,
const char *  funcName,
IntCallback  ifunc,
const char *  usage,
S32  minArgs,
S32  maxArgs 
)

ConsoleConstructor::ConsoleConstructor ( const char *  className,
const char *  funcName,
FloatCallback  ffunc,
const char *  usage,
S32  minArgs,
S32  maxArgs 
)

ConsoleConstructor::ConsoleConstructor ( const char *  className,
const char *  funcName,
VoidCallback  vfunc,
const char *  usage,
S32  minArgs,
S32  maxArgs 
)

ConsoleConstructor::ConsoleConstructor ( const char *  className,
const char *  funcName,
BoolCallback  bfunc,
const char *  usage,
S32  minArgs,
S32  maxArgs 
)

ConsoleConstructor::ConsoleConstructor ( const char *  className,
const char *  groupName,
const char *  usage 
)

Indicates a group marker.

(A doxygen illusion)

See also:
Con::markCommandGroup Console Auto-Documentation


Member Function Documentation

void ConsoleConstructor::init ( const char *  cName,
const char *  fName,
const char *  usg,
S32  minArgs,
S32  maxArgs 
)

static void ConsoleConstructor::setup (  )  [static]


Field Documentation

A function/method that returns a string.

A function/method that returns an int.

A function/method that returns a float.

A function/method that returns nothing.

A function/method that returns a bool.

Indicates that this is a group marker.

Indicates that this is an overload marker.

Deprecated:
Unused.

Minimum/maximum number of arguments for the function.

Usage string.

Function name.

Class name.




All Rights Reserved GarageGames.com, Inc. 1999-2005
Auto-magically Generated with Doxygen