Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5171 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Sep 7, 2005, 1:08:21 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: some more implementation

Location:
trunk/src/lib
Files:
3 edited

Legend:

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

    r5170 r5171  
    5757}
    5858
    59 const ShellCommandClass* ShellCommandClass::isRegistered(const char* className)
    60 {
    61   if (ShellCommandClass::commandClassList == NULL)
    62     initCommandClassList();
    63 
     59/**
     60 * unregisters all Commands that exist
     61 */
     62void ShellCommandClass::unregisterAllCommands()
     63{
    6464  tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    6565  ShellCommandClass* elem = iterator->firstElement();
    6666  while(elem != NULL)
    6767  {
     68    delete elem;
     69
     70    elem = iterator->nextElement();
     71  }
     72  delete iterator;
     73
     74  delete ShellCommandClass::commandClassList;
     75  ShellCommandClass::commandClassList = NULL;
     76}
     77
     78const ShellCommandClass* ShellCommandClass::isRegistered(const char* className)
     79{
     80  if (ShellCommandClass::commandClassList == NULL)
     81    initCommandClassList();
     82
     83  tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
     84  ShellCommandClass* elem = iterator->firstElement();
     85  while(elem != NULL)
     86  {
    6887    if (!strcmp(className, elem->className))
    6988    {
     89      if (elem->classID == CL_NULL)
     90        elem->classID = ClassList::StringToID(className);
     91
    7092      delete iterator;
    7193      return elem;
     
    178200
    179201/**
    180  * unregisters all Commands that exist
    181  */
    182 void ShellCommandBase::unregisterAllCommands()
    183 {
    184 //   tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator();
    185 //   ShellCommandBase* elem = iterator->firstElement();
    186 //   while(elem != NULL)
    187 //   {
    188 //     delete elem;
    189 //
    190 //     elem = iterator->nextElement();
    191 //   }
    192 //   delete iterator;
    193 //
    194 //   delete ShellCommandBase::commandList;
    195 //   ShellCommandBase::commandList = NULL;
    196 }
    197 
    198 /**
    199202 * unregister an existing commandName
    200203 * @param className the name of the Class the command belongs to.
     
    205208void ShellCommandBase::unregisterCommand(const char* commandName, const char* className)
    206209{
    207   PRINTF(1)("IMPLEMENT THIS\n");
     210  if (ShellCommandClass::commandClassList == NULL)
     211    ShellCommandClass::initCommandClassList();
     212
     213 const  ShellCommandClass* checkClass = ShellCommandClass::isRegistered(className);
     214
     215  if (checkClass != NULL)
     216  {
     217    tIterator<ShellCommandBase>* iterator = checkClass->commandList->getIterator();
     218    ShellCommandBase* elem = iterator->firstElement();
     219    while(elem != NULL)
     220    {
     221      if (!strcmp(commandName, elem->getName()))
     222      {
     223        checkClass->commandList->remove(elem);
     224        delete elem;
     225        break;
     226      }
     227      elem = iterator->nextElement();
     228    }
     229    delete iterator;
     230
     231    if (checkClass->commandList->getSize() == 0)
     232    {
     233      ShellCommandClass::commandClassList->remove(checkClass);
     234      delete checkClass;
     235    }
     236  }
    208237}
    209238
     
    378407  if (ShellCommandClass::commandClassList == NULL)
    379408  {
    380     PRINT(0)("No Command registered so far\n");
     409    PRINT(0)("No Command registered.\n");
    381410    return;
    382411  }
     
    386415  while(elemCL != NULL)
    387416  {
     417    PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
    388418    tIterator<ShellCommandBase>* iterator = elemCL->commandList->getIterator();
    389419    const ShellCommandBase* elem = iterator->firstElement();
    390420    {
    391       PRINT(0)("Class:'%s' registered: \n", elemCL->className);
    392       PRINT(0)("  command:'%s':params:%d: ", elem->getName(), elem->paramCount);
     421      PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
    393422      for (unsigned int i = 0; i< elem->paramCount; i++)
    394423       printf("%s ", ShellCommandBase::paramToString(elem->parameters[i]));
  • trunk/src/lib/shell/shell_command.h

    r5170 r5171  
    4545    static const tList<ShellCommandClass>* getCommandClassList() { return ShellCommandClass::commandClassList; };
    4646    static ShellCommandClass* getCommandClass(const char* className);
     47    static void unregisterAllCommands();
    4748
    4849  private:
     
    5455
    5556  private:
    56   const char*                      className;
    57   ClassID                          classID;
    58   tList<ShellCommandBase>*         commandList;
    59   static tList<ShellCommandClass>* commandClassList;                     //!< A list of Classes
     57    const char*                      className;                 //!< The Name of the Class. This should match the ClassName of the Commands Class.
     58    long                             classID;                   //!< The classID of this Class
     59    tList<ShellCommandBase>*         commandList;               //!< A list of Commands from this Class
     60    static tList<ShellCommandClass>* commandClassList;          //!< A list of Classes
    6061};
    6162
     
    7273    /** @returns the CommandList of the Shell */
    7374
    74     static void unregisterAllCommands();
    7575    static void unregisterCommand(const char* commandName, const char* className);
    7676
  • trunk/src/lib/util/list.h

    r5131 r5171  
    3737  void add(T* entity);
    3838  void addAtBeginning(T* entity); //!< @todo This should be made with an ENUM
    39   void remove(T* entity);
     39  void remove(const T* entity);
    4040  void removeLast();
    4141  void flush();
     
    138138*/
    139139template<class T>
    140 inline void tList<T>::remove(T* entity)
     140inline void tList<T>::remove(const T* entity)
    141141{
    142142  this->currentEl = this->first;
Note: See TracChangeset for help on using the changeset viewer.