Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5461 in orxonox.OLD


Ignore:
Timestamp:
Oct 30, 2005, 10:37:14 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: command-chain (copy and renaming of shell_command) added to project … think some more

Location:
trunk/src/lib/event
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/event/command_chain.cc

    r5460 r5461  
    3030
    3131/**
    32  * creates a new ShellCommandClass
     32 * creates a new CommandChainClass
    3333 * @param className the Name of the command-class to create
    3434 */
    35 ShellCommandClass::ShellCommandClass(const char* className)
    36 {
    37   this->setClassID(CL_SHELL_COMMAND_CLASS, "ShellCommandClass");
     35CommandChainClass::CommandChainClass(const char* className)
     36{
     37  this->setClassID(CL_COMMAND_CHAIN_CLASS, "CommandChainClass");
    3838  this->setName(className);
    3939
    4040  this->className = className;
    4141  this->classID = CL_NULL;
    42   this->commandList = new tList<ShellCommandBase>;
    43 
    44   ShellCommandClass::commandClassList->add(this);
     42  this->commandList = new tList<CommandChainBase>;
     43
     44  CommandChainClass::commandClassList->add(this);
    4545}
    4646
     
    4848 * destructs the shellCommandClass again
    4949 */
    50 ShellCommandClass::~ShellCommandClass()
    51 {
    52   tIterator<ShellCommandBase>* iterator = this->commandList->getIterator();
    53   ShellCommandBase* elem = iterator->firstElement();
     50CommandChainClass::~CommandChainClass()
     51{
     52  tIterator<CommandChainBase>* iterator = this->commandList->getIterator();
     53  CommandChainBase* elem = iterator->firstElement();
    5454  while(elem != NULL)
    5555  {
     
    6767 * @returns true on success, false otherwise
    6868 */
    69 bool ShellCommandClass::getCommandListOfClass(const char* className, tList<const char>* stringList)
     69bool CommandChainClass::getCommandListOfClass(const char* className, tList<const char>* stringList)
    7070{
    7171  if (stringList == NULL || className == NULL)
    7272    return false;
    7373
    74   tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    75   ShellCommandClass* elem = iterator->firstElement();
     74  tIterator<CommandChainClass>* iterator = CommandChainClass::commandClassList->getIterator();
     75  CommandChainClass* elem = iterator->firstElement();
    7676  while(elem != NULL)
    7777  {
    7878    if (!strcmp (elem->getName(), className))
    7979    {
    80       tIterator<ShellCommandBase>* itFkt = elem->commandList->getIterator();
    81       ShellCommandBase* command = itFkt->firstElement();
     80      tIterator<CommandChainBase>* itFkt = elem->commandList->getIterator();
     81      CommandChainBase* command = itFkt->firstElement();
    8282      while (command != NULL)
    8383      {
     
    9595
    9696/**
    97  * collects the Aliases registered to the ShellCommands
     97 * collects the Aliases registered to the CommandChains
    9898 * @param stringList a List to paste the Aliases into.
    9999 * @returns true on success, false otherwise
    100100 */
    101 bool ShellCommandClass::getCommandListOfAlias(tList<const char>* stringList)
    102 {
    103   if (stringList == NULL || ShellCommandClass::aliasList == NULL)
     101bool CommandChainClass::getCommandListOfAlias(tList<const char>* stringList)
     102{
     103  if (stringList == NULL || CommandChainClass::aliasList == NULL)
    104104    return false;
    105105
    106   tIterator<ShellCommandAlias>* iterator = ShellCommandClass::aliasList->getIterator();
    107    ShellCommandAlias* elem = iterator->firstElement();
     106  tIterator<CommandChainAlias>* iterator = CommandChainClass::aliasList->getIterator();
     107   CommandChainAlias* elem = iterator->firstElement();
    108108   while(elem != NULL)
    109109   {
     
    118118 * unregisters all Commands that exist
    119119 */
    120 void ShellCommandClass::unregisterAllCommands()
     120void CommandChainClass::unregisterAllCommands()
    121121{
    122122  // unregister all commands
    123   tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    124   ShellCommandClass* elem = iterator->firstElement();
     123  tIterator<CommandChainClass>* iterator = CommandChainClass::commandClassList->getIterator();
     124  CommandChainClass* elem = iterator->firstElement();
    125125  while(elem != NULL)
    126126  {
     
    131131  delete iterator;
    132132
    133   delete ShellCommandClass::commandClassList;
    134   ShellCommandClass::commandClassList = NULL;
     133  delete CommandChainClass::commandClassList;
     134  CommandChainClass::commandClassList = NULL;
    135135
    136136  // unregister all aliases (there should be nothing to do here :))
    137   if (ShellCommandClass::aliasList != NULL)
    138   {
    139     tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();
    140     ShellCommandAlias* elemAL = itAL->firstElement();
     137  if (CommandChainClass::aliasList != NULL)
     138  {
     139    tIterator<CommandChainAlias>* itAL = CommandChainClass::aliasList->getIterator();
     140    CommandChainAlias* elemAL = itAL->firstElement();
    141141    while(elemAL != NULL)
    142142    {
     
    145145    }
    146146    delete itAL;
    147     delete ShellCommandClass::aliasList;
    148     ShellCommandClass::aliasList = NULL;
     147    delete CommandChainClass::aliasList;
     148    CommandChainClass::aliasList = NULL;
    149149  }
    150150}
     
    155155 * @returns the CommandClass if found, NULL otherwise
    156156 */
    157 const ShellCommandClass* ShellCommandClass::isRegistered(const char* className)
    158 {
    159   if (ShellCommandClass::commandClassList == NULL)
     157const CommandChainClass* CommandChainClass::isRegistered(const char* className)
     158{
     159  if (CommandChainClass::commandClassList == NULL)
    160160    initCommandClassList();
    161161
    162   tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    163   ShellCommandClass* elem = iterator->firstElement();
     162  tIterator<CommandChainClass>* iterator = CommandChainClass::commandClassList->getIterator();
     163  CommandChainClass* elem = iterator->firstElement();
    164164  while(elem != NULL)
    165165  {
     
    183183 * @returns the CommandClass if found, or a new CommandClass if not
    184184 */
    185 ShellCommandClass* ShellCommandClass::getCommandClass(const char* className)
    186 {
    187   if (ShellCommandClass::commandClassList == NULL)
     185CommandChainClass* CommandChainClass::getCommandClass(const char* className)
     186{
     187  if (CommandChainClass::commandClassList == NULL)
    188188    initCommandClassList();
    189189
    190   tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    191   ShellCommandClass* elem = iterator->firstElement();
     190  tIterator<CommandChainClass>* iterator = CommandChainClass::commandClassList->getIterator();
     191  CommandChainClass* elem = iterator->firstElement();
    192192  while(elem != NULL)
    193193  {
     
    200200  }
    201201  delete iterator;
    202   return new ShellCommandClass(className);
     202  return new CommandChainClass(className);
    203203}
    204204
     
    206206 * initializes the CommandList (if it is NULL)
    207207 */
    208 void ShellCommandClass::initCommandClassList()
    209 {
    210   if (ShellCommandClass::commandClassList == NULL)
    211   {
    212     ShellCommandClass::commandClassList = new tList<ShellCommandClass>;
    213     ShellCommandStatic<ShellCommandBase>::registerCommand("debug", "ShellCommand", ShellCommandBase::debug);
    214   }
    215 }
    216 
    217 void ShellCommandClass::help(const char* className)
     208void CommandChainClass::initCommandClassList()
     209{
     210  if (CommandChainClass::commandClassList == NULL)
     211  {
     212    CommandChainClass::commandClassList = new tList<CommandChainClass>;
     213    CommandChainStatic<CommandChainBase>::registerCommand("debug", "CommandChain", CommandChainBase::debug);
     214  }
     215}
     216
     217void CommandChainClass::help(const char* className)
    218218{
    219219  if (className == NULL)
    220220    return;
    221   if (likely(ShellCommandClass::commandClassList != NULL))
    222   {
    223     tIterator<ShellCommandClass>* itCL = ShellCommandClass::commandClassList->getIterator();
    224     ShellCommandClass* elemCL = itCL->firstElement();
     221  if (likely(CommandChainClass::commandClassList != NULL))
     222  {
     223    tIterator<CommandChainClass>* itCL = CommandChainClass::commandClassList->getIterator();
     224    CommandChainClass* elemCL = itCL->firstElement();
    225225    while(elemCL != NULL)
    226226    {
     
    228228      {
    229229        PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
    230         tIterator<ShellCommandBase>* iterator = elemCL->commandList->getIterator();
    231         const ShellCommandBase* elem = iterator->firstElement();
     230        tIterator<CommandChainBase>* iterator = elemCL->commandList->getIterator();
     231        const CommandChainBase* elem = iterator->firstElement();
    232232        while(elem != NULL)
    233233        {
    234234          PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
    235235          for (unsigned int i = 0; i< elem->paramCount; i++)
    236             PRINT(0)("%s ", ShellCommandBase::paramToString(elem->parameters[i]));
     236            PRINT(0)("%s ", CommandChainBase::paramToString(elem->parameters[i]));
    237237          if (elem->description != NULL)
    238238            PRINT(0)("- %s", elem->description);
     
    256256}
    257257
    258 tList<ShellCommandClass>* ShellCommandClass::commandClassList = NULL;
    259 tList<ShellCommandAlias>* ShellCommandClass::aliasList = NULL;
     258tList<CommandChainClass>* CommandChainClass::commandClassList = NULL;
     259tList<CommandChainAlias>* CommandChainClass::aliasList = NULL;
    260260
    261261/**
     
    266266 * @return self
    267267 */
    268 ShellCommandBase::ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...)
    269 {
    270   this->setClassID(CL_SHELL_COMMAND, "ShellCommand");
     268CommandChainBase::CommandChainBase(const char* commandName, const char* className, unsigned int paramCount, ...)
     269{
     270  this->setClassID(CL_COMMAND_CHAIN, "CommandChain");
    271271  this->setName(commandName);
    272272  this->description = NULL;
     
    274274
    275275//  this->classID = classID;
    276   this->shellClass = ShellCommandClass::getCommandClass(className); //ClassList::IDToString(classID);
     276  this->shellClass = CommandChainClass::getCommandClass(className); //ClassList::IDToString(classID);
    277277  if (this->shellClass != NULL)
    278278    this->shellClass->commandList->add(this);
     
    321321
    322322/**
    323  * deconstructs a ShellCommand
     323 * deconstructs a CommandChain
    324324 * @return
    325325 */
    326 ShellCommandBase::~ShellCommandBase()
     326CommandChainBase::~CommandChainBase()
    327327{
    328328  delete[] this->parameters;
    329   if (this->alias != NULL && ShellCommandClass::aliasList != NULL)
    330   {
    331     ShellCommandClass::aliasList->remove(this->alias);
     329  if (this->alias != NULL && CommandChainClass::aliasList != NULL)
     330  {
     331    CommandChainClass::aliasList->remove(this->alias);
    332332    delete this->alias;
    333333  }
     
    339339 * @param commandName the name of the command itself
    340340 */
    341 void ShellCommandBase::unregisterCommand(const char* commandName, const char* className)
    342 {
    343   if (ShellCommandClass::commandClassList == NULL)
    344     ShellCommandClass::initCommandClassList();
    345 
    346  const ShellCommandClass* checkClass = ShellCommandClass::isRegistered(className);
     341void CommandChainBase::unregisterCommand(const char* commandName, const char* className)
     342{
     343  if (CommandChainClass::commandClassList == NULL)
     344    CommandChainClass::initCommandClassList();
     345
     346 const CommandChainClass* checkClass = CommandChainClass::isRegistered(className);
    347347
    348348 if (checkClass != NULL)
    349349  {
    350     tIterator<ShellCommandBase>* iterator = checkClass->commandList->getIterator();
    351     ShellCommandBase* elem = iterator->firstElement();
     350    tIterator<CommandChainBase>* iterator = checkClass->commandList->getIterator();
     351    CommandChainBase* elem = iterator->firstElement();
    352352    while(elem != NULL)
    353353    {
     
    364364    if (checkClass->commandList->getSize() == 0)
    365365    {
    366       ShellCommandClass::commandClassList->remove(checkClass);
     366      CommandChainClass::commandClassList->remove(checkClass);
    367367      delete checkClass;
    368368    }
     
    380380 * This is checked in the registerCommand-function.
    381381 */
    382 bool ShellCommandBase::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...)
    383 {
    384   if (ShellCommandClass::commandClassList == NULL)
    385   {
    386     ShellCommandClass::initCommandClassList();
     382bool CommandChainBase::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...)
     383{
     384  if (CommandChainClass::commandClassList == NULL)
     385  {
     386    CommandChainClass::initCommandClassList();
    387387    return false;
    388388  }
    389389
    390   const ShellCommandClass* checkClass = ShellCommandClass::isRegistered(className);
     390  const CommandChainClass* checkClass = CommandChainClass::isRegistered(className);
    391391  if (checkClass != NULL)
    392392  {
    393     tIterator<ShellCommandBase>* iterator = checkClass->commandList->getIterator();
    394     ShellCommandBase* elem = iterator->firstElement();
     393    tIterator<CommandChainBase>* iterator = checkClass->commandList->getIterator();
     394    CommandChainBase* elem = iterator->firstElement();
    395395    while(elem != NULL)
    396396   {
     
    418418 */
    419419#include  "stdlibincl.h"
    420 bool ShellCommandBase::execute(const char* executionString)
    421 {
    422   if (ShellCommandClass::commandClassList == NULL)
     420bool CommandChainBase::execute(const char* executionString)
     421{
     422  if (CommandChainClass::commandClassList == NULL)
    423423    return false;
    424424
    425425  long classID = CL_NULL;                 //< the classID retrieved from the Class.
    426   ShellCommandClass* commandClass = NULL; //< the command class this command applies to.
     426  CommandChainClass* commandClass = NULL; //< the command class this command applies to.
    427427  tList<BaseObject>* objectList = NULL;   //< the list of Objects stored in classID
    428428  BaseObject* objectPointer = NULL;       //< a pointer to th Object to Execute the command on
     
    437437  {
    438438    // CHECK FOR ALIAS
    439     if (ShellCommandClass::aliasList != NULL)
    440     {
    441       tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();
    442       ShellCommandAlias* elemAL = itAL->firstElement();
     439    if (CommandChainClass::aliasList != NULL)
     440    {
     441      tIterator<CommandChainAlias>* itAL = CommandChainClass::aliasList->getIterator();
     442      CommandChainAlias* elemAL = itAL->firstElement();
    443443      while(elemAL != NULL)
    444444      {
     
    462462    }
    463463    // looking for a Matching Class
    464     if (likely(ShellCommandClass::commandClassList != NULL))
    465     {
    466       tIterator<ShellCommandClass>* itCL = ShellCommandClass::commandClassList->getIterator();
    467       ShellCommandClass* elemCL = itCL->firstElement();
     464    if (likely(CommandChainClass::commandClassList != NULL))
     465    {
     466      tIterator<CommandChainClass>* itCL = CommandChainClass::commandClassList->getIterator();
     467      CommandChainClass* elemCL = itCL->firstElement();
    468468      while(elemCL != NULL)
    469469      {
     
    507507      if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.getCount() >= 3)))
    508508      {
    509         tIterator<ShellCommandBase>* itCMD = commandClass->commandList->getIterator();
    510         ShellCommandBase* enumCMD = itCMD->firstElement();
     509        tIterator<CommandChainBase>* itCMD = commandClass->commandList->getIterator();
     510        CommandChainBase* enumCMD = itCMD->firstElement();
    511511        while (enumCMD != NULL)
    512512        {
    513513          if (!strcmp(enumCMD->getName(), inputSplits.getString(fktPos)))
    514514          {
    515             if (objectPointer == NULL && enumCMD->functorType == ShellCommand_Objective)
     515            if (objectPointer == NULL && enumCMD->functorType == CommandChain_Objective)
    516516            {
    517517              delete itCMD;
     
    538538 * @param description the description of the Given command
    539539 */
    540 ShellCommandBase* ShellCommandBase::describe(const char* description)
     540CommandChainBase* CommandChainBase::describe(const char* description)
    541541{
    542542  if (this == NULL)
     
    554554 * @returns itself
    555555 */
    556 ShellCommandBase* ShellCommandBase::setAlias(const char* alias)
     556CommandChainBase* CommandChainBase::setAlias(const char* alias)
    557557{
    558558  if (this == NULL)
     
    565565  else
    566566  {
    567     if (ShellCommandClass::aliasList == NULL)
    568       ShellCommandClass::aliasList = new tList<ShellCommandAlias>;
    569 
    570     ShellCommandAlias* aliasCMD = new ShellCommandAlias(alias, this);
    571     ShellCommandClass::aliasList->add(aliasCMD);
     567    if (CommandChainClass::aliasList == NULL)
     568      CommandChainClass::aliasList = new tList<CommandChainAlias>;
     569
     570    CommandChainAlias* aliasCMD = new CommandChainAlias(alias, this);
     571    CommandChainClass::aliasList->add(aliasCMD);
    572572    this->alias = aliasCMD;
    573573  }
     
    584584 * count, [EXACTLY THE SAME AS IF YOU WOULD CALL THE FUNCTION UP TO count ARGUMENTS]
    585585 */
    586 ShellCommandBase* ShellCommandBase::defaultValues(unsigned int count, ...)
     586CommandChainBase* CommandChainBase::defaultValues(unsigned int count, ...)
    587587{
    588588  if (this == NULL)
     
    633633 * prints out nice information about the Shells Commands
    634634 */
    635 void ShellCommandBase::debug()
    636 {
    637   if (ShellCommandClass::commandClassList == NULL)
     635void CommandChainBase::debug()
     636{
     637  if (CommandChainClass::commandClassList == NULL)
    638638  {
    639639    PRINT(0)("No Command registered.\n");
     
    641641  }
    642642
    643   tIterator<ShellCommandClass>* iteratorCL = ShellCommandClass::commandClassList->getIterator();
    644   ShellCommandClass* elemCL = iteratorCL->firstElement();
     643  tIterator<CommandChainClass>* iteratorCL = CommandChainClass::commandClassList->getIterator();
     644  CommandChainClass* elemCL = iteratorCL->firstElement();
    645645  while(elemCL != NULL)
    646646  {
    647647    PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
    648     tIterator<ShellCommandBase>* iterator = elemCL->commandList->getIterator();
    649     const ShellCommandBase* elem = iterator->firstElement();
     648    tIterator<CommandChainBase>* iterator = elemCL->commandList->getIterator();
     649    const CommandChainBase* elem = iterator->firstElement();
    650650    while(elem != NULL)
    651651    {
    652652      PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
    653653      for (unsigned int i = 0; i< elem->paramCount; i++)
    654        printf("%s ", ShellCommandBase::paramToString(elem->parameters[i]));
     654       printf("%s ", CommandChainBase::paramToString(elem->parameters[i]));
    655655      if (elem->description != NULL)
    656656       printf("- %s", elem->description);
     
    670670 * @returns the Name of the Parameter at Hand
    671671 */
    672 const char* ShellCommandBase::paramToString(long parameter)
     672const char* CommandChainBase::paramToString(long parameter)
    673673{
    674674  switch (parameter)
  • trunk/src/lib/event/command_chain.h

    r5460 r5461  
    11/*!
    2  * @file shell_command.h
     2 * @file command_chain.h
    33 * Definition of a on-screen-shell
    44 */
    55
    6 #ifndef _SHELL_COMMAND_H
    7 #define _SHELL_COMMAND_H
     6#ifndef _COMMAND_CHAIN_H
     7#define _COMMAND_CHAIN_H
    88
    99#include "base_object.h"
     
    1515#include <stdarg.h>
    1616
    17 #define     SHELL_COMMAND_MAX_SIZE      //!< The maximum size of a Shell Command
     17#define     COMMAND_CHAIN_MAX_SIZE      //!< The maximum size of a Shell Command
    1818
    1919
     
    2929 *
    3030 * MEANING:
    31  *  ShellCommandBase* someUniqueVarName =
    32  *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
     31 *  CommandChainBase* someUniqueVarName =
     32 *       CommandChain<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
    3333 *
    3434 * In the Shell you would call this Command using:
    3535 * $ ClassName [ObjectName] commandNameInShell [parameters]
    3636 */
    37 #define SHELL_COMMAND(command, class, function) \
    38         ShellCommandBase* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
     37#define COMMAND_CHAIN(command, class, function) \
     38        CommandChainBase* command_chain_##class##_##command = CommandChain<class>::registerCommand(#command, #class, &class::function)
    3939/**
    4040 * an easy to use Macro to create a Command
     
    4444 *
    4545 * MEANING:
    46  *  ShellCommandBase* someUniqueVarName =
    47  *       ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
     46 *  CommandChainBase* someUniqueVarName =
     47 *       CommandChain<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);
    4848 *
    4949 * In the Shell you would call this Command using:
    5050 * $ ClassName [ObjectName] commandNameInShell [parameters]
    5151 */
    52 #define SHELL_COMMAND_STATIC(command, class, function) \
    53                          ShellCommandBase* shell_command_##class##_##command = ShellCommandStatic<class>::registerCommand(#command, #class, function)
     52#define COMMAND_CHAIN_STATIC(command, class, function) \
     53                         CommandChainBase* command_chain_##class##_##command = CommandChainStatic<class>::registerCommand(#command, #class, function)
    5454
    5555
    5656//! an enumerator for the definition of the Type.
    5757typedef enum {
    58   ShellCommand_Objective = 1,
    59   ShellCommand_Static    = 2,
    60 } ShellCommand_Type;
     58  CommandChain_Objective = 1,
     59  CommandChain_Static    = 2,
     60} CommandChain_Type;
    6161
    6262////////////////
    6363// BASE CLASS //
    6464////////////////
    65 class ShellCommandBase;
    66 class ShellCommandAlias;
     65class CommandChainBase;
     66class CommandChainAlias;
    6767
    6868//! A class to hold all Classes that have (once) registered Commands.
    69 class ShellCommandClass : public BaseObject
     69class CommandChainClass : public BaseObject
    7070{
    71   friend class ShellCommandBase;
     71  friend class CommandChainBase;
    7272
    7373  public:
    7474    /** @returns the CommandClassList */
    75     static const tList<ShellCommandClass>* getCommandClassList() { return ShellCommandClass::commandClassList; };
     75    static const tList<CommandChainClass>* getCommandClassList() { return CommandChainClass::commandClassList; };
    7676    static bool getCommandListOfClass(const char* className, tList<const char>* stringList);
    7777    static bool getCommandListOfAlias(tList<const char>* aliasList);
    7878
    79     static ShellCommandClass* getCommandClass(const char* className);
     79    static CommandChainClass* getCommandClass(const char* className);
    8080    static void unregisterAllCommands();
    8181
     
    8383
    8484  private:
    85     ShellCommandClass(const char* className);
    86     ~ShellCommandClass();
    87 
    88     static const ShellCommandClass* isRegistered(const char* className);
     85    CommandChainClass(const char* className);
     86    ~CommandChainClass();
     87
     88    static const CommandChainClass* isRegistered(const char* className);
    8989    static void initCommandClassList();
    9090
     
    9292    const char*                      className;                 //!< The Name of the Class. This should match the ClassName of the Commands Class.
    9393    long                             classID;                   //!< The classID of this Class
    94     tList<ShellCommandBase>*         commandList;               //!< A list of Commands from this Class
    95     static tList<ShellCommandClass>* commandClassList;          //!< A list of Classes
    96     static tList<ShellCommandAlias>* aliasList;                 //!< An Alias to A Command. (only for classes with one Instance)
     94    tList<CommandChainBase>*         commandList;               //!< A list of Commands from this Class
     95    static tList<CommandChainClass>* commandClassList;          //!< A list of Classes
     96    static tList<CommandChainAlias>* aliasList;                 //!< An Alias to A Command. (only for classes with one Instance)
    9797};
    9898
    9999
    100 //! a baseClass for all possible ShellCommands
    101 class ShellCommandBase : public BaseObject
     100//! a baseClass for all possible CommandChains
     101class CommandChainBase : public BaseObject
    102102{
    103   friend class ShellCommandClass;
     103  friend class CommandChainClass;
    104104  public:
    105105    static bool execute (const char* executionString);
    106106
    107     ShellCommandBase* describe(const char* description);
    108     ShellCommandBase* setAlias(const char* alias);
    109     ShellCommandBase* defaultValues(unsigned int count, ...);
     107    CommandChainBase* describe(const char* description);
     108    CommandChainBase* setAlias(const char* alias);
     109    CommandChainBase* defaultValues(unsigned int count, ...);
    110110
    111111    /** @returns the CommandList of the Shell */
     
    115115
    116116  protected:
    117     ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...);
    118     ~ShellCommandBase();
     117    CommandChainBase(const char* commandName, const char* className, unsigned int paramCount, ...);
     118    ~CommandChainBase();
    119119
    120120    /** @returns the Type of this Function (either static or objective) */
    121     inline ShellCommand_Type getType() { return this->functorType; };
     121    inline CommandChain_Type getType() { return this->functorType; };
    122122
    123123    static bool isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...);
     
    129129
    130130  protected:
    131     ShellCommand_Type                functorType;                          //!< The type of Function we've got (either static or objective).
     131    CommandChain_Type                functorType;                          //!< The type of Function we've got (either static or objective).
    132132    void*                            functionPointer;                      //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
    133133    unsigned int                     paramCount;                           //!< the count of parameters.
     
    140140
    141141  private:
    142     ShellCommandClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
    143     ShellCommandAlias*               alias;                                //!< An Alias for the Class.
     142    CommandChainClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
     143    CommandChainAlias*               alias;                                //!< An Alias for the Class.
    144144
    145145    const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
     
    168168// COMMAND REGISTRATION //
    169169//////////////////////////
    170 // SHELLCOMMAND can be redefined as ShellCommand or ShellCommandStatic
     170// SHELLCOMMAND can be redefined as CommandChain or CommandChainStatic
    171171// SHELLCOMMANDEXECUTER can be redefined too.
    172172// SHELLCOMMANDINCLASS
    173173// SHELLCOMMANDTYPE
    174174//! registers a command without any parameters
    175 #define ShellCommandRegister0() \
     175#define CommandChainRegister0() \
    176176  static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)()) \
    177177  { \
     
    182182
    183183//! registers a command with 1 parameter
    184 #define ShellCommandRegister1(t1) \
     184#define CommandChainRegister1(t1) \
    185185  static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \
    186186  { \
     
    191191
    192192//! registers a command with 2 parameters
    193 #define ShellCommandRegister2(t1,t2) \
     193#define CommandChainRegister2(t1,t2) \
    194194  static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT) \
    195195  { \
     
    200200
    201201//! registers a command with 3 parameters
    202 #define ShellCommandRegister3(t1,t2,t3) \
     202#define CommandChainRegister3(t1,t2,t3) \
    203203  static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT) \
    204204  { \
     
    209209
    210210//! registers a command with 4 parameters
    211 #define ShellCommandRegister4(t1,t2,t3,t4) \
     211#define CommandChainRegister4(t1,t2,t3,t4) \
    212212  static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT) \
    213213  { \
     
    218218
    219219//! registers a command with 5 parameters
    220 #define ShellCommandRegister5(t1,t2,t3,t4,t5) \
     220#define CommandChainRegister5(t1,t2,t3,t4,t5) \
    221221  static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT, t5##_TYPE d5 = t5##_DEFAULT) \
    222222  { \
    223223    if (isRegistered(commandName, className, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM)== true) \
    224224      return NULL; \
    225     return new ShellCommand<T>(commandName, className, function, d1, d2, d3, d4, d5); \
     225    return new CommandChain<T>(commandName, className, function, d1, d2, d3, d4, d5); \
    226226  }
    227227
     
    230230/////////////////
    231231//! creates a command that takes no parameters
    232 #define ShellCommandConstructor0() \
     232#define CommandChainConstructor0() \
    233233  void SHELLCOMMANDINCLASS(*functionPointer_0)(); \
    234234  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)()) \
    235   : ShellCommandBase(commandName, className, 0) \
     235  : CommandChainBase(commandName, className, 0) \
    236236  { \
    237237    this->functorType = SHELLCOMMANDTYPE; \
     
    240240
    241241//! creates a command that takes one parameter
    242 #define ShellCommandConstructor1(t1) \
     242#define CommandChainConstructor1(t1) \
    243243  void SHELLCOMMANDINCLASS(*functionPointer_1_##t1)(t1##_TYPE); \
    244244  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE), t1##_TYPE d1) \
    245   : ShellCommandBase(commandName, className, 1, t1##_PARAM, d1) \
     245  : CommandChainBase(commandName, className, 1, t1##_PARAM, d1) \
    246246  { \
    247247    this->functorType = SHELLCOMMANDTYPE; \
     
    250250
    251251//! creates a command that takes two parameters
    252 #define ShellCommandConstructor2(t1,t2) \
     252#define CommandChainConstructor2(t1,t2) \
    253253  void SHELLCOMMANDINCLASS(*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE); \
    254254  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1, t2##_TYPE d2) \
    255   : ShellCommandBase(commandName, className, 2, t1##_PARAM, d1, t2##_PARAM, d2) \
     255  : CommandChainBase(commandName, className, 2, t1##_PARAM, d1, t2##_PARAM, d2) \
    256256  { \
    257257    this->functorType = SHELLCOMMANDTYPE; \
     
    260260
    261261//! creates a command that takes three parameter
    262 #define ShellCommandConstructor3(t1,t2,t3) \
     262#define CommandChainConstructor3(t1,t2,t3) \
    263263  void SHELLCOMMANDINCLASS(*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE); \
    264264  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3) \
    265   : ShellCommandBase(commandName, className, 3, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3) \
     265  : CommandChainBase(commandName, className, 3, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3) \
    266266  { \
    267267    this->functorType = SHELLCOMMANDTYPE; \
     
    270270
    271271//! creates a command that takes four parameter
    272 #define ShellCommandConstructor4(t1,t2,t3,t4) \
     272#define CommandChainConstructor4(t1,t2,t3,t4) \
    273273  void SHELLCOMMANDINCLASS(*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE); \
    274274  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4) \
    275   : ShellCommandBase(commandName, className, 4, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4) \
     275  : CommandChainBase(commandName, className, 4, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4) \
    276276  { \
    277277    this->functorType = SHELLCOMMANDTYPE; \
     
    280280
    281281//! creates a command that takes five parameter
    282 #define ShellCommandConstructor5(t1,t2,t3,t4,t5) \
     282#define CommandChainConstructor5(t1,t2,t3,t4,t5) \
    283283  void SHELLCOMMANDINCLASS(*functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE); \
    284284  SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4, t5##_TYPE d5) \
    285   : ShellCommandBase(commandName, className, 5, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4, t5##_PARAM, d5) \
     285  : CommandChainBase(commandName, className, 5, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4, t5##_PARAM, d5) \
    286286  { \
    287287    this->functorType = SHELLCOMMANDTYPE; \
     
    293293///////////////
    294294//! execute-macro for functions with no parameters
    295 #define ShellCommandExecute0() \
     295#define CommandChainExecute0() \
    296296  if (this->paramCount == 0) \
    297297    SHELLCOMMANDEXECUTER(_0)()
    298298
    299299//! execute-macro for functions with one parameter
    300 #define ShellCommandExecute1(t1) \
     300#define CommandChainExecute1(t1) \
    301301   else if (this->paramCount == 1 && this->parameters[0] == t1##_PARAM) \
    302302    SHELLCOMMANDEXECUTER(_1_##t1)(t1##_FUNC(parameters, t1##_DEFGRAB(0)))
    303303
    304304//! execute-macro for functions with two parameters
    305 #define ShellCommandExecute2(t1,t2) \
     305#define CommandChainExecute2(t1,t2) \
    306306   else if (this->paramCount == 2 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM) \
    307307    SHELLCOMMANDEXECUTER(_2_##t1##_##t2)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)))
    308308
    309309//! execute-macro for functions with three parameters
    310 #define ShellCommandExecute3(t1,t2,t3) \
     310#define CommandChainExecute3(t1,t2,t3) \
    311311   else if (this->paramCount == 3 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM) \
    312312    SHELLCOMMANDEXECUTER(_3_##t1##_##t2##_##t3)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)))
    313313
    314314//! execute-macro for functions with four parameters
    315 #define ShellCommandExecute4(t1,t2,t3,t4) \
     315#define CommandChainExecute4(t1,t2,t3,t4) \
    316316   else if (this->paramCount == 4 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM) \
    317317    SHELLCOMMANDEXECUTER(_4_##t1##_##t2##_##t3##_##t4)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3)))
    318318
    319319//! execute-macro for functions with five parameters
    320 #define ShellCommandExecute5(t1,t2,t3,t4,t5) \
     320#define CommandChainExecute5(t1,t2,t3,t4,t5) \
    321321   else if (this->paramCount == 5 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM && this->parameters[4] == t5##_PARAM) \
    322322    SHELLCOMMANDEXECUTER(_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3)), t5##_FUNC(sub.getString(4), t5##_DEFGRAB(4)))
    323323
    324324
    325 //! keeps information about a ShellCommand
    326 template<class T> class ShellCommand : public ShellCommandBase
     325//! keeps information about a CommandChain
     326template<class T> class CommandChain : public CommandChainBase
    327327{
    328328  public:
     
    333333#undef SHELLCOMMAND
    334334#endif
    335 #define SHELLCOMMAND                       ShellCommand
     335#define SHELLCOMMAND                       CommandChain
    336336#ifdef SHELLCOMMANDEXECUTER
    337337#undef SHELLCOMMANDEXECUTER
     
    345345#undef SHELLCOMMANDTYPE
    346346#endif
    347 #define SHELLCOMMANDTYPE                   ShellCommand_Objective
     347#define SHELLCOMMANDTYPE                   CommandChain_Objective
    348348//! FUNCTOR_LIST is the List of command-registerers
    349 #define FUNCTOR_LIST(x) ShellCommandRegister ## x
     349#define FUNCTOR_LIST(x) CommandChainRegister ## x
    350350#include "functor_list.h"
    351351#undef FUNCTOR_LIST
     
    354354  private:
    355355//! FUNCTOR_LIST is the List of CommandConstructors
    356 #define FUNCTOR_LIST(x) ShellCommandConstructor ## x
     356#define FUNCTOR_LIST(x) CommandChainConstructor ## x
    357357#include "functor_list.h"
    358358#undef FUNCTOR_LIST
     
    362362      SubString sub(parameters, true);
    363363//! FUNCTOR_LIST is the List of Executive Functions
    364 #define FUNCTOR_LIST(x) ShellCommandExecute ## x
     364#define FUNCTOR_LIST(x) CommandChainExecute ## x
    365365#include "functor_list.h"
    366366#undef FUNCTOR_LIST
     
    368368};
    369369
    370 //! keeps information about a ShellCommand, that points to a Static Function
    371 template<class T> class ShellCommandStatic : public ShellCommandBase
     370//! keeps information about a CommandChain, that points to a Static Function
     371template<class T> class CommandChainStatic : public CommandChainBase
    372372{
    373373  public:
     
    378378#undef SHELLCOMMAND
    379379#endif
    380 #define SHELLCOMMAND                      ShellCommandStatic
     380#define SHELLCOMMAND                      CommandChainStatic
    381381#ifdef SHELLCOMMANDEXECUTER
    382382#undef SHELLCOMMANDEXECUTER
     
    390390#undef SHELLCOMMANDTYPE
    391391#endif
    392 #define SHELLCOMMANDTYPE                   ShellCommand_Static
     392#define SHELLCOMMANDTYPE                   CommandChain_Static
    393393
    394394//! FUNCTOR_LIST is the List of command-registerers
    395 #define FUNCTOR_LIST(x) ShellCommandRegister ## x
     395#define FUNCTOR_LIST(x) CommandChainRegister ## x
    396396#include "functor_list.h"
    397397#undef FUNCTOR_LIST
     
    399399  private:
    400400//! FUNCTOR_LIST is the List of CommandConstructors
    401 #define FUNCTOR_LIST(x) ShellCommandConstructor ## x
     401#define FUNCTOR_LIST(x) CommandChainConstructor ## x
    402402#include "functor_list.h"
    403403#undef FUNCTOR_LIST
     
    407407  SubString sub(parameters, true);
    408408//! FUNCTOR_LIST is the List of Executive Functions
    409 #define FUNCTOR_LIST(x) ShellCommandExecute ## x
     409#define FUNCTOR_LIST(x) CommandChainExecute ## x
    410410#include "functor_list.h"
    411411#undef FUNCTOR_LIST
     
    414414
    415415//! A Class, that handles aliases.
    416 class ShellCommandAlias
     416class CommandChainAlias
    417417{
    418   friend class ShellCommandBase;
     418  friend class CommandChainBase;
    419419  public:
    420420    /** @returns the Name of the Alias. */
    421421    const char* getName() const { return this->aliasName; };
    422422    /** @returns the Command, this Alias is asociated with */
    423     ShellCommandBase* getCommand() const { return this->command; };
     423    CommandChainBase* getCommand() const { return this->command; };
    424424
    425425  private:
    426426    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
    427     ShellCommandAlias(const char* aliasName, ShellCommandBase* command) { this->aliasName = aliasName; this->command = command; };
     427    CommandChainAlias(const char* aliasName, CommandChainBase* command) { this->aliasName = aliasName; this->command = command; };
    428428
    429429  private:
    430430    const char*         aliasName;       //!< the name of the Alias
    431     ShellCommandBase*   command;         //!< a pointer to the command, this alias executes.
     431    CommandChainBase*   command;         //!< a pointer to the command, this alias executes.
    432432};
    433433
    434 #endif /* _SHELL_COMMAND_H */
     434#endif /* _COMMAND_CHAIN_H */
Note: See TracChangeset for help on using the changeset viewer.