Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5636 in orxonox.OLD for trunk/src/lib/shell/shell_command.cc


Ignore:
Timestamp:
Nov 18, 2005, 6:55:18 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: adapting ShellCommand to use Executor.
On the go

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_command.cc

    r5634 r5636  
    4040  this->className = className;
    4141  this->classID = CL_NULL;
    42   this->commandList = new tList<ShellCommandBase>;
     42  this->commandList = new tList<ShellCommand>;
    4343
    4444  ShellCommandClass::commandClassList->add(this);
     
    5050ShellCommandClass::~ShellCommandClass()
    5151{
    52   tIterator<ShellCommandBase>* iterator = this->commandList->getIterator();
    53   ShellCommandBase* elem = iterator->firstElement();
     52  tIterator<ShellCommand>* iterator = this->commandList->getIterator();
     53  ShellCommand* elem = iterator->firstElement();
    5454  while(elem != NULL)
    5555  {
     
    7878    if (!strcmp (elem->getName(), className))
    7979    {
    80       tIterator<ShellCommandBase>* itFkt = elem->commandList->getIterator();
    81       ShellCommandBase* command = itFkt->firstElement();
     80      tIterator<ShellCommand>* itFkt = elem->commandList->getIterator();
     81      ShellCommand* command = itFkt->firstElement();
    8282      while (command != NULL)
    8383      {
     
    120120void ShellCommandClass::unregisterAllCommands()
    121121{
    122   // unregister all commands
     122  if (ShellCommandClass::commandClassList != NULL)
     123  {
     124    // unregister all commands
     125    tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
     126    ShellCommandClass* elem = iterator->firstElement();
     127    while(elem != NULL)
     128    {
     129      delete elem;
     130
     131      elem = iterator->nextElement();
     132    }
     133    delete iterator;
     134
     135    delete ShellCommandClass::commandClassList;
     136    ShellCommandClass::commandClassList = NULL;
     137  }
     138
     139  // unregister all aliases (there should be nothing to do here :))
     140  if (ShellCommandClass::aliasList != NULL)
     141  {
     142    tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();
     143    ShellCommandAlias* elemAL = itAL->firstElement();
     144    while(elemAL != NULL)
     145    {
     146      delete elemAL;
     147      elemAL = itAL->nextElement();
     148    }
     149    delete itAL;
     150    delete ShellCommandClass::aliasList;
     151    ShellCommandClass::aliasList = NULL;
     152  }
     153}
     154
     155/**
     156 * checks if a Class is already registered to the Commands' class-stack
     157 * @param className the Name of the Class to check for
     158 * @returns the CommandClass if found, NULL otherwise
     159 */
     160const ShellCommandClass* ShellCommandClass::isRegistered(const char* className)
     161{
     162  if (ShellCommandClass::commandClassList == NULL)
     163    initCommandClassList();
     164
    123165  tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    124166  ShellCommandClass* elem = iterator->firstElement();
    125167  while(elem != NULL)
    126168  {
    127     delete elem;
    128 
     169    if (!strcmp(className, elem->className))
     170    {
     171      if (elem->classID == CL_NULL)
     172        elem->classID = ClassList::StringToID(className);
     173
     174      delete iterator;
     175      return elem;
     176    }
    129177    elem = iterator->nextElement();
    130178  }
    131179  delete iterator;
    132 
    133   delete ShellCommandClass::commandClassList;
    134   ShellCommandClass::commandClassList = NULL;
    135 
    136   // 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();
    141     while(elemAL != NULL)
    142     {
    143       delete elemAL;
    144       elemAL = itAL->nextElement();
    145     }
    146     delete itAL;
    147     delete ShellCommandClass::aliasList;
    148     ShellCommandClass::aliasList = NULL;
    149   }
    150 }
    151 
    152 /**
    153  * checks if a Class is already registered to the Commands' class-stack
    154  * @param className the Name of the Class to check for
    155  * @returns the CommandClass if found, NULL otherwise
    156  */
    157 const ShellCommandClass* ShellCommandClass::isRegistered(const char* className)
     180  return NULL;
     181}
     182
     183/**
     184 * searches for a CommandClass
     185 * @param className the name of the CommandClass
     186 * @returns the CommandClass if found, or a new CommandClass if not
     187 */
     188ShellCommandClass* ShellCommandClass::getCommandClass(const char* className)
    158189{
    159190  if (ShellCommandClass::commandClassList == NULL)
     
    166197    if (!strcmp(className, elem->className))
    167198    {
    168       if (elem->classID == CL_NULL)
    169         elem->classID = ClassList::StringToID(className);
    170 
    171199      delete iterator;
    172200      return elem;
     
    175203  }
    176204  delete iterator;
    177   return NULL;
    178 }
    179 
    180 /**
    181  * searches for a CommandClass
    182  * @param className the name of the CommandClass
    183  * @returns the CommandClass if found, or a new CommandClass if not
    184  */
    185 ShellCommandClass* ShellCommandClass::getCommandClass(const char* className)
     205  return new ShellCommandClass(className);
     206}
     207
     208/**
     209 * initializes the CommandList (if it is NULL)
     210 */
     211void ShellCommandClass::initCommandClassList()
    186212{
    187213  if (ShellCommandClass::commandClassList == NULL)
    188     initCommandClassList();
    189 
    190   tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    191   ShellCommandClass* elem = iterator->firstElement();
    192   while(elem != NULL)
    193   {
    194     if (!strcmp(className, elem->className))
    195     {
    196       delete iterator;
    197       return elem;
    198     }
    199     elem = iterator->nextElement();
    200   }
    201   delete iterator;
    202   return new ShellCommandClass(className);
    203 }
    204 
    205 /**
    206  * initializes the CommandList (if it is NULL)
    207  */
    208 void ShellCommandClass::initCommandClassList()
    209 {
    210   if (ShellCommandClass::commandClassList == NULL)
    211214  {
    212215    ShellCommandClass::commandClassList = new tList<ShellCommandClass>;
    213     ShellCommandStatic<ShellCommandBase>::registerCommand("debug", "ShellCommand", ShellCommandBase::debug);
     216    ShellCommand::registerCommand("debug", "ShellCommand", new ExecutorStatic<ShellCommand>(ShellCommand::debug));
    214217  }
    215218}
     
    228231      {
    229232        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();
     233        tIterator<ShellCommand>* iterator = elemCL->commandList->getIterator();
     234        const ShellCommand* elem = iterator->firstElement();
    232235        while(elem != NULL)
    233236        {
    234237          PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
    235238          for (unsigned int i = 0; i< elem->paramCount; i++)
    236             PRINT(0)("%s ", ShellCommandBase::paramToString(elem->parameters[i]));
     239            PRINT(0)("%s ", ShellCommand::paramToString(elem->parameters[i]));
    237240          if (elem->description != NULL)
    238241            PRINT(0)("- %s", elem->description);
     
    277280 * @param paramCount the count of parameters this command takes
    278281 */
    279 ShellCommandBase::ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...)
     282ShellCommand::ShellCommand(const char* commandName, const char* className, unsigned int paramCount, ...)
    280283{
    281284  this->setClassID(CL_SHELL_COMMAND, "ShellCommand");
     
    306309 * deconstructs a ShellCommand
    307310 */
    308 ShellCommandBase::~ShellCommandBase()
     311ShellCommand::~ShellCommand()
    309312{
    310313  delete[] this->parameters;
     
    318321
    319322/**
     323 * registers a new ShellCommand
     324 */
     325ShellCommand* ShellCommand::registerCommand(const char* commandName, const char* className, Executor* executor)
     326{
     327  return NULL;
     328
     329}
     330
     331
     332
     333
     334/**
    320335 * unregister an existing commandName
    321336 * @param className the name of the Class the command belongs to.
    322337 * @param commandName the name of the command itself
    323338 */
    324 void ShellCommandBase::unregisterCommand(const char* commandName, const char* className)
     339void ShellCommand::unregisterCommand(const char* commandName, const char* className)
    325340{
    326341  if (ShellCommandClass::commandClassList == NULL)
     
    331346 if (checkClass != NULL)
    332347  {
    333     tIterator<ShellCommandBase>* iterator = checkClass->commandList->getIterator();
    334     ShellCommandBase* elem = iterator->firstElement();
     348    tIterator<ShellCommand>* iterator = checkClass->commandList->getIterator();
     349    ShellCommand* elem = iterator->firstElement();
    335350    while(elem != NULL)
    336351    {
     
    363378 * This is checked in the registerCommand-function.
    364379 */
    365 bool ShellCommandBase::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...)
     380bool ShellCommand::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...)
    366381{
    367382  if (ShellCommandClass::commandClassList == NULL)
     
    374389  if (checkClass != NULL)
    375390  {
    376     tIterator<ShellCommandBase>* iterator = checkClass->commandList->getIterator();
    377     ShellCommandBase* elem = iterator->firstElement();
     391    tIterator<ShellCommand>* iterator = checkClass->commandList->getIterator();
     392    ShellCommand* elem = iterator->firstElement();
    378393    while(elem != NULL)
    379394   {
     
    400415 * @return true on success, false otherwise.
    401416 */
    402 bool ShellCommandBase::execute(const char* executionString)
     417bool ShellCommand::execute(const char* executionString)
    403418{
    404419  if (ShellCommandClass::commandClassList == NULL)
     
    489504      if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.getCount() >= 3)))
    490505      {
    491         tIterator<ShellCommandBase>* itCMD = commandClass->commandList->getIterator();
    492         ShellCommandBase* enumCMD = itCMD->firstElement();
     506        tIterator<ShellCommand>* itCMD = commandClass->commandList->getIterator();
     507        ShellCommand* enumCMD = itCMD->firstElement();
    493508        while (enumCMD != NULL)
    494509        {
     
    520535 * @param description the description of the Given command
    521536 */
    522 ShellCommandBase* ShellCommandBase::describe(const char* description)
     537ShellCommand* ShellCommand::describe(const char* description)
    523538{
    524539  if (this == NULL)
     
    536551 * @returns itself
    537552 */
    538 ShellCommandBase* ShellCommandBase::setAlias(const char* alias)
     553ShellCommand* ShellCommand::setAlias(const char* alias)
    539554{
    540555  if (this == NULL)
     
    566581 * count, [EXACTLY THE SAME AS IF YOU WOULD CALL THE FUNCTION UP TO count ARGUMENTS]
    567582 */
    568 ShellCommandBase* ShellCommandBase::defaultValues(unsigned int count, ...)
     583ShellCommand* ShellCommand::defaultValues(unsigned int count, ...)
    569584{
    570585  if (this == NULL)
     
    615630 * prints out nice information about the Shells Commands
    616631 */
    617 void ShellCommandBase::debug()
     632void ShellCommand::debug()
    618633{
    619634  if (ShellCommandClass::commandClassList == NULL)
     
    628643  {
    629644    PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
    630     tIterator<ShellCommandBase>* iterator = elemCL->commandList->getIterator();
    631     const ShellCommandBase* elem = iterator->firstElement();
     645    tIterator<ShellCommand>* iterator = elemCL->commandList->getIterator();
     646    const ShellCommand* elem = iterator->firstElement();
    632647    while(elem != NULL)
    633648    {
    634649      PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
    635650      for (unsigned int i = 0; i< elem->paramCount; i++)
    636        printf("%s ", ShellCommandBase::paramToString(elem->parameters[i]));
     651       printf("%s ", ShellCommand::paramToString(elem->parameters[i]));
    637652      if (elem->description != NULL)
    638653       printf("- %s", elem->description);
     
    652667 * @returns the Name of the Parameter at Hand
    653668 */
    654 const char* ShellCommandBase::paramToString(long parameter)
     669const char* ShellCommand::paramToString(long parameter)
    655670{
    656671  return MultiType::MultiTypeToString((MT_Type)parameter);
Note: See TracChangeset for help on using the changeset viewer.