Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Nov 26, 2005, 2:20:58 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ClassList is now in std::list style
ShellCommand is now in std::list style

File:
1 edited

Legend:

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

    r5656 r5779  
    4747  this->shellClass = ShellCommandClass::getCommandClass(className); //ClassList::IDToString(classID);
    4848  if (this->shellClass != NULL)
    49     this->shellClass->commandList->add(this);
     49    this->shellClass->commandList.push_back(this);
    5050}
    5151
     
    8282void ShellCommand::unregisterCommand(const char* commandName, const char* className)
    8383{
    84   if (ShellCommandClass::commandClassList == NULL)
     84  /// FIXME
     85/*  if (ShellCommandClass::commandClassList == NULL)
    8586    ShellCommandClass::initCommandClassList();
    8687
     
    8990 if (checkClass != NULL)
    9091  {
    91     tIterator<ShellCommand>* iterator = checkClass->commandList->getIterator();
    92     ShellCommand* elem = iterator->firstElement();
    93     while(elem != NULL)
    94     {
    95       if (!strcmp(commandName, elem->getName()))
    96       {
    97         checkClass->commandList->remove(elem);
    98         delete elem;
     92    std::list<ShellCommand*>::iterator elem;
     93    for (elem = checkClass->commandList.begin(); elem != checkClass->commandList.end(); elem++)
     94    {
     95      if (!strcmp(commandName, (*elem)->getName()))
     96      {
     97        delete (*elem);
     98        checkClass->commandList.remove(*elem);
    9999        break;
    100100      }
    101       elem = iterator->nextElement();
    102     }
    103     delete iterator;
    104 
    105     if (checkClass->commandList->getSize() == 0)
     101    }
     102
     103    if (checkClass->commandList->size() == 0)
    106104    {
    107105      ShellCommandClass::commandClassList->remove(checkClass);
    108106      delete checkClass;
    109107    }
    110   }
     108  }*/
    111109}
    112110
     
    132130  if (checkClass != NULL)
    133131  {
    134     tIterator<ShellCommand>* iterator = checkClass->commandList->getIterator();
    135     ShellCommand* elem = iterator->firstElement();
    136     while(elem != NULL)
    137    {
    138      if (!strcmp(commandName, elem->getName()))
    139      {
    140        PRINTF(2)("Command already registered\n");
    141        delete iterator;
    142        return true;
    143       }
    144      elem = iterator->nextElement();
    145    }
    146    delete iterator;
     132    std::list<ShellCommand*>::const_iterator elem;
     133    for (elem = checkClass->commandList.begin(); elem != checkClass->commandList.end(); elem++)
     134    {
     135      if (!strcmp(commandName, (*elem)->getName()))
     136      {
     137        PRINTF(2)("Command '%s::%s' already registered\n", className, commandName);
     138        return true;
     139      }
     140    }
    147141   return false;
    148142  }
     
    163157    return false;
    164158
    165   long classID = CL_NULL;                 //< the classID retrieved from the Class.
    166   ShellCommandClass* commandClass = NULL; //< the command class this command applies to.
    167   tList<BaseObject>* objectList = NULL;   //< the list of Objects stored in classID
    168   BaseObject* objectPointer = NULL;       //< a pointer to th Object to Execute the command on
    169   bool emptyComplete = false;             //< if the completion input is empty string. e.g ""
    170   unsigned int fktPos = 1;                //< the position of the function (needed for finding it)
    171 //  long completeType = SHELLC_NONE;      //< the Type we'd like to complete.
     159  long classID = CL_NULL;                      //< the classID retrieved from the Class.
     160  ShellCommandClass* commandClass = NULL;      //< the command class this command applies to.
     161  std::list<BaseObject*>* objectList = NULL;   //< the list of Objects stored in classID
     162  BaseObject* objectPointer = NULL;            //< a pointer to th Object to Execute the command on
     163  bool emptyComplete = false;                  //< if the completion input is empty string. e.g ""
     164  unsigned int fktPos = 1;                     //< the position of the function (needed for finding it)
     165//  long completeType = SHELLC_NONE;           //< the Type we'd like to complete.
    172166  SubString inputSplits(executionString, " \t\n,");
    173167
     
    179173    if (ShellCommandClass::aliasList != NULL)
    180174    {
    181       tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();
    182       ShellCommandAlias* elemAL = itAL->firstElement();
    183       while(elemAL != NULL)
    184       {
    185         if (elemAL->getName() != NULL && !strcmp(elemAL->getName(), inputSplits.getString(0)) && elemAL->getCommand() != NULL &&
    186             elemAL->getCommand()->shellClass != NULL )
     175      list<ShellCommandAlias*>::iterator alias;
     176      for (alias = ShellCommandClass::aliasList->begin(); alias != ShellCommandClass::aliasList->end(); alias++ )
     177      {
     178        if ((*alias)->getName() != NULL && !strcmp((*alias)->getName(), inputSplits.getString(0)) && (*alias)->getCommand() != NULL &&
     179            (*alias)->getCommand()->shellClass != NULL )
    187180        {
    188           objectList = ClassList::getList(elemAL->getCommand()->shellClass->getName());
     181          objectList = ClassList::getList((*alias)->getCommand()->shellClass->getName());
    189182          if (objectList != NULL)
    190183          {
    191184            if (inputSplits.getCount() > 1)
    192               elemAL->getCommand()->executor->execute(objectList->firstElement(), executionString+inputSplits.getOffset(1));
     185              (*alias)->getCommand()->executor->execute(objectList->front(), executionString+inputSplits.getOffset(1));
    193186            else
    194               elemAL->getCommand()->executor->execute(objectList->firstElement(), "");
    195             delete itAL;
     187              (*alias)->getCommand()->executor->execute(objectList->front(), "");
     188           return true;
     189          }
     190        }
     191      }
     192    }
     193    // looking for a Matching Class
     194    if (likely(ShellCommandClass::commandClassList != NULL))
     195    {
     196      list<ShellCommandClass*>::iterator commandClassIT;
     197      for (commandClassIT = ShellCommandClass::commandClassList->begin(); commandClassIT != ShellCommandClass::commandClassList->end(); commandClassIT++)
     198      {
     199        if ((*commandClassIT)->getName() && !strcasecmp(inputSplits.getString(0), (*commandClassIT)->getName()))
     200        {
     201          //elemCL->getName();
     202          classID = ClassList::StringToID((*commandClassIT)->getName());
     203          commandClass = (*commandClassIT);
     204          objectList = ClassList::getList(classID);
     205          break;
     206        }
     207      }
     208    }
     209
     210    if (commandClass != NULL && inputSplits.getCount() >= 2)
     211    {
     212      if (objectList != NULL)
     213      {
     214        // Checking for a Match in the Objects of classID (else take the first)
     215        list<BaseObject*>::const_iterator object;
     216        for (object = objectList->begin(); object != objectList->end(); object++)
     217        {
     218          if ((*object)->getName() != NULL && !strcasecmp((*object)->getName(), inputSplits.getString(1)))
     219          {
     220            objectPointer = (*object);
     221            fktPos = 2;
     222            break;
     223          }
     224         }
     225
     226      //
     227        if (objectPointer == NULL)
     228          objectPointer = objectList->front();
     229      }
     230      // match a function.
     231      if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.getCount() >= 3)))
     232      {
     233        list<ShellCommand*>::iterator cmdIT;
     234        for (cmdIT = commandClass->commandList.begin(); cmdIT != commandClass->commandList.end(); cmdIT++)
     235        {
     236          if (!strcmp((*cmdIT)->getName(), inputSplits.getString(fktPos)))
     237          {
     238            if (objectPointer == NULL && (*cmdIT)->executor->getType() & Executor_Objective)
     239              return false;
     240            if (inputSplits.getCount() > fktPos+1)
     241              (*cmdIT)->executor->execute(objectPointer, executionString+inputSplits.getOffset(fktPos +1));
     242            else
     243              (*cmdIT)->executor->execute(objectPointer, "");
    196244            return true;
    197245          }
    198246        }
    199         elemAL = itAL->nextElement();
    200       }
    201       delete itAL;
    202     }
    203     // looking for a Matching Class
    204     if (likely(ShellCommandClass::commandClassList != NULL))
    205     {
    206       tIterator<ShellCommandClass>* itCL = ShellCommandClass::commandClassList->getIterator();
    207       ShellCommandClass* elemCL = itCL->firstElement();
    208       while(elemCL != NULL)
    209       {
    210         if (elemCL->getName() && !strcasecmp(inputSplits.getString(0), elemCL->getName()))
    211         {
    212           //elemCL->getName();
    213           classID = ClassList::StringToID(elemCL->getName());
    214           commandClass = elemCL;
    215           objectList = ClassList::getList(classID);
    216           break;
    217         }
    218         elemCL = itCL->nextElement();
    219       }
    220       delete itCL;
    221     }
    222 
    223     if (commandClass != NULL && inputSplits.getCount() >= 2)
    224     {
    225       if (objectList != NULL)
    226       {
    227         // Checking for a Match in the Objects of classID (else take the first)
    228         tIterator<BaseObject>* itBO = objectList->getIterator();
    229         BaseObject* enumBO = itBO->firstElement();
    230         while(enumBO)
    231         {
    232           if (enumBO->getName() != NULL && !strcasecmp(enumBO->getName(), inputSplits.getString(1)))
    233           {
    234             objectPointer = enumBO;
    235             fktPos = 2;
    236             break;
    237           }
    238           enumBO = itBO->nextElement();
    239          }
    240          delete itBO;
    241 
    242       //
    243         if (objectPointer == NULL)
    244           objectPointer = objectList->firstElement();
    245       }
    246       // match a function.
    247       if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.getCount() >= 3)))
    248       {
    249         tIterator<ShellCommand>* itCMD = commandClass->commandList->getIterator();
    250         ShellCommand* enumCMD = itCMD->firstElement();
    251         while (enumCMD != NULL)
    252         {
    253           if (!strcmp(enumCMD->getName(), inputSplits.getString(fktPos)))
    254           {
    255             if (objectPointer == NULL && enumCMD->executor->getType() & Executor_Objective)
    256             {
    257               delete itCMD;
    258               return false;
    259             }
    260             if (inputSplits.getCount() > fktPos+1)
    261               enumCMD->executor->execute(objectPointer, executionString+inputSplits.getOffset(fktPos +1));
    262             else
    263               enumCMD->executor->execute(objectPointer, "");
    264             delete itCMD;
    265             return true;
    266           }
    267 
    268           enumCMD = itCMD->nextElement();
    269         }
    270         delete itCMD;
    271247      }
    272248    }
     
    306282  {
    307283    if (ShellCommandClass::aliasList == NULL)
    308       ShellCommandClass::aliasList = new tList<ShellCommandAlias>;
     284      ShellCommandClass::aliasList = new std::list<ShellCommandAlias*>;
    309285
    310286    ShellCommandAlias* aliasCMD = new ShellCommandAlias(alias, this);
    311     ShellCommandClass::aliasList->add(aliasCMD);
     287    ShellCommandClass::aliasList->push_back(aliasCMD);
    312288    this->alias = aliasCMD;
    313289  }
     
    348324  }
    349325
    350   tIterator<ShellCommandClass>* iteratorCL = ShellCommandClass::commandClassList->getIterator();
    351   ShellCommandClass* elemCL = iteratorCL->firstElement();
    352   while(elemCL != NULL)
    353   {
    354     PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
    355     tIterator<ShellCommand>* iterator = elemCL->commandList->getIterator();
    356     const ShellCommand* elem = iterator->firstElement();
    357     while(elem != NULL)
    358     {
    359       PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->executor->getParamCount());
     326  list<ShellCommandClass*>::iterator classIT;
     327  for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
     328  {
     329    PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className, (*classIT)->commandList.size());
     330
     331    list<ShellCommand*>::iterator cmdIT;
     332    for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++)
     333    {
     334      PRINT(0)("  command:'%s' : params:%d: ", (*cmdIT)->getName(), (*cmdIT)->executor->getParamCount());
    360335      /// FIXME
    361336      /*      for (unsigned int i = 0; i< elem->paramCount; i++)
    362337       printf("%s ", ShellCommand::paramToString(elem->parameters[i]));*/
    363       if (elem->description != NULL)
    364        printf("- %s", elem->description);
     338      if ((*cmdIT)->description != NULL)
     339       printf("- %s", (*cmdIT)->description);
    365340      printf("\n");
    366341
    367       elem = iterator->nextElement();
    368     }
    369     delete iterator;
    370     elemCL = iteratorCL->nextElement();
    371   }
    372   delete iteratorCL;
     342    }
     343  }
    373344}
    374345
Note: See TracChangeset for help on using the changeset viewer.