Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5461 in orxonox.OLD for trunk/src/lib/event/command_chain.cc


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

File:
1 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)
Note: See TracChangeset for help on using the changeset viewer.