Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

Location:
trunk/src/lib/shell
Files:
6 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
  • trunk/src/lib/shell/shell_command.h

    r5690 r5779  
    108108
    109109  private:
    110     const char*         aliasName;       //!< the name of the Alias
     110    const char*     aliasName;       //!< the name of the Alias
    111111    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
    112112};
  • trunk/src/lib/shell/shell_command_class.cc

    r5644 r5779  
    2929using namespace std;
    3030
    31 tList<ShellCommandClass>* ShellCommandClass::commandClassList = NULL;
    32 tList<ShellCommandAlias>* ShellCommandClass::aliasList = NULL;
     31std::list<ShellCommandClass*>* ShellCommandClass::commandClassList = NULL;
     32std::list<ShellCommandAlias*>* ShellCommandClass::aliasList = NULL;
    3333
    3434/**
     
    4343  this->className = className;
    4444  this->classID = CL_NULL;
    45   this->commandList = new tList<ShellCommand>;
    46 
    47   ShellCommandClass::commandClassList->add(this);
     45
     46  ShellCommandClass::commandClassList->push_back(this);
    4847}
    4948
     
    5352ShellCommandClass::~ShellCommandClass()
    5453{
    55   tIterator<ShellCommand>* iterator = this->commandList->getIterator();
    56   ShellCommand* elem = iterator->firstElement();
    57   while(elem != NULL)
    58   {
    59     delete elem;
    60     elem = iterator->nextElement();
    61   }
    62   delete iterator;
    63   delete this->commandList;
     54  while(this->commandList.size() > 0)
     55  {
     56    delete this->commandList.front();
     57    this->commandList.pop_front();
     58  }
    6459}
    6560
     
    7065 * @returns true on success, false otherwise
    7166 */
    72 bool ShellCommandClass::getCommandListOfClass(const char* className, tList<const char>* stringList)
     67bool ShellCommandClass::getCommandListOfClass(const char* className, std::list<const char*>* stringList)
    7368{
    7469  if (stringList == NULL || className == NULL)
    7570    return false;
    7671
    77   tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    78   ShellCommandClass* elem = iterator->firstElement();
    79   while(elem != NULL)
    80   {
    81     if (!strcmp (elem->getName(), className))
    82     {
    83       tIterator<ShellCommand>* itFkt = elem->commandList->getIterator();
    84       ShellCommand* command = itFkt->firstElement();
    85       while (command != NULL)
    86       {
    87         stringList->add(command->getName());
    88         command = itFkt->nextElement();
    89       }
    90       delete itFkt;
    91     }
    92 
    93     elem = iterator->nextElement();
    94   }
    95   delete iterator;
     72  list<ShellCommandClass*>::iterator elem;
     73  for(elem = ShellCommandClass::commandClassList->begin(); elem != ShellCommandClass::commandClassList->end(); elem++)
     74  {
     75    if (!strcmp ((*elem)->getName(), className))
     76    {
     77      list<ShellCommand*>::iterator command;
     78      for(command = (*elem)->commandList.begin(); command != (*elem)->commandList.end(); command++)
     79        stringList->push_back((*command)->getName());
     80    }
     81  }
    9682  return true;
    9783}
     
    10288 * @returns true on success, false otherwise
    10389 */
    104 bool ShellCommandClass::getCommandListOfAlias(tList<const char>* stringList)
     90bool ShellCommandClass::getCommandListOfAlias(std::list<const char*>* stringList)
    10591{
    10692  if (stringList == NULL || ShellCommandClass::aliasList == NULL)
    10793    return false;
    10894
    109   tIterator<ShellCommandAlias>* iterator = ShellCommandClass::aliasList->getIterator();
    110    ShellCommandAlias* elem = iterator->firstElement();
    111    while(elem != NULL)
    112    {
    113      stringList->add(elem->getName());
    114      elem = iterator->nextElement();
    115    }
    116    delete iterator;
    117    return true;
     95  list<ShellCommandAlias*>::iterator alias;
     96  for (alias = ShellCommandClass::aliasList->begin(); alias != ShellCommandClass::aliasList->end(); alias++)
     97    stringList->push_back((*alias)->getName());
     98  return true;
    11899}
    119100
     
    123104void ShellCommandClass::unregisterAllCommands()
    124105{
    125   if (ShellCommandClass::commandClassList != NULL)
     106  /// FIXME
     107
     108  /*  if (ShellCommandClass::commandClassList != NULL)
    126109  {
    127110    // unregister all commands
     
    153136    delete ShellCommandClass::aliasList;
    154137    ShellCommandClass::aliasList = NULL;
    155   }
     138  }*/
    156139}
    157140
     
    166149    initCommandClassList();
    167150
    168   tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    169   ShellCommandClass* elem = iterator->firstElement();
    170   while(elem != NULL)
    171   {
    172     if (!strcmp(className, elem->className))
    173     {
    174       if (elem->classID == CL_NULL)
    175         elem->classID = ClassList::StringToID(className);
    176 
    177       delete iterator;
    178       return elem;
    179     }
    180     elem = iterator->nextElement();
    181   }
    182   delete iterator;
     151  list<ShellCommandClass*>::const_iterator classIT;
     152  for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
     153  {
     154    if (!strcmp(className, (*classIT)->className))
     155    {
     156      if ((*classIT)->classID == CL_NULL)
     157        (*classIT)->classID = ClassList::StringToID(className);
     158
     159      return (*classIT);
     160    }
     161  }
    183162  return NULL;
    184163}
     
    194173    initCommandClassList();
    195174
    196   tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    197   ShellCommandClass* elem = iterator->firstElement();
    198   while(elem != NULL)
    199   {
    200     if (!strcmp(className, elem->className))
    201     {
    202       delete iterator;
    203       return elem;
    204     }
    205     elem = iterator->nextElement();
    206   }
    207   delete iterator;
     175  list<ShellCommandClass*>::iterator classIT;
     176  for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
     177  {
     178    if (!strcmp(className, (*classIT)->className))
     179    {
     180      return (*classIT);
     181    }
     182  }
    208183  return new ShellCommandClass(className);
    209184}
     
    216191  if (ShellCommandClass::commandClassList == NULL)
    217192  {
    218     ShellCommandClass::commandClassList = new tList<ShellCommandClass>;
     193    ShellCommandClass::commandClassList = new std::list<ShellCommandClass*>;
    219194    ShellCommand::registerCommand("debug", "ShellCommand", ExecutorStatic<ShellCommand>(ShellCommand::debug));
    220195  }
     
    231206  if (likely(ShellCommandClass::commandClassList != NULL))
    232207  {
    233     tIterator<ShellCommandClass>* itCL = ShellCommandClass::commandClassList->getIterator();
    234     ShellCommandClass* elemCL = itCL->firstElement();
    235     while(elemCL != NULL)
    236     {
    237       if (elemCL->className && !strcasecmp(className, elemCL->className))
     208    list<ShellCommandClass*>::iterator classIT;
     209    for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
     210    {
     211      if ((*classIT)->className && !strcasecmp(className, (*classIT)->className))
    238212      {
    239         PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
    240         tIterator<ShellCommand>* iterator = elemCL->commandList->getIterator();
    241         const ShellCommand* elem = iterator->firstElement();
    242         while(elem != NULL)
     213        PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className, (*classIT)->commandList.size());
     214        list<ShellCommand*>::const_iterator cmdIT;
     215        for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++)
    243216        {
    244           PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->executor->getParamCount());
     217          PRINT(0)("  command:'%s' : params:%d: ", (*cmdIT)->getName(), (*cmdIT)->executor->getParamCount());
    245218          /// FIXME
    246219          /*          for (unsigned int i = 0; i< elem->paramCount; i++)
    247220            PRINT(0)("%s ", ShellCommand::paramToString(elem->parameters[i]));*/
    248           if (elem->description != NULL)
    249             PRINT(0)("- %s", elem->description);
     221          if ((*cmdIT)->description != NULL)
     222            PRINT(0)("- %s", (*cmdIT)->description);
    250223          PRINT(0)("\n");
    251           elem = iterator->nextElement();
    252224        }
    253         delete iterator;
    254 
    255         delete itCL;
    256225        return;
    257226      }
    258       elemCL = itCL->nextElement();
    259     }
    260     delete itCL;
     227    }
    261228    PRINTF(3)("Class %s not found in Command's classes\n", className);
    262229  }
  • trunk/src/lib/shell/shell_command_class.h

    r5639 r5779  
    88
    99#include "base_object.h"
     10#include <list>
    1011
    1112
     
    2627  public:
    2728    /** @returns the CommandClassList */
    28     static const tList<ShellCommandClass>* getCommandClassList() { return ShellCommandClass::commandClassList; };
    29     static bool getCommandListOfClass(const char* className, tList<const char>* stringList);
    30     static bool getCommandListOfAlias(tList<const char>* aliasList);
     29    static const std::list<ShellCommandClass*>* getCommandClassList() { return ShellCommandClass::commandClassList; };
     30    static bool getCommandListOfClass(const char* className, std::list<const char*>* stringList);
     31    static bool getCommandListOfAlias(std::list<const char*>* aliasList);
    3132
    3233    static ShellCommandClass* getCommandClass(const char* className);
     
    4344
    4445  private:
    45     const char*                      className;                 //!< The Name of the Class. This should match the ClassName of the Commands Class.
    46     long                             classID;                   //!< The classID of this Class
    47     tList<ShellCommand>*             commandList;               //!< A list of Commands from this Class
    48     static tList<ShellCommandClass>* commandClassList;          //!< A list of Classes
    49     static tList<ShellCommandAlias>* aliasList;                 //!< An Alias to A Command. (only for classes with one Instance)
     46    const char*                            className;                 //!< The Name of the Class. This should match the ClassName of the Commands Class.
     47    long                                   classID;                   //!< The classID of this Class
     48    std::list<ShellCommand*>               commandList;               //!< A list of Commands from this Class
     49    static std::list<ShellCommandClass*>* commandClassList;          //!< A list of Classes
     50    static std::list<ShellCommandAlias*>* aliasList;                 //!< An Alias to A Command. (only for classes with one Instance)
    5051};
    5152
  • trunk/src/lib/shell/shell_completion.cc

    r5656 r5779  
    6363bool ShellCompletion::autoComplete(ShellInput* input)
    6464{
    65   const char* completionLine;      //< the inputLine we complete.
    66 
    67   long classID;                    //< the classID retrieved from the Class.
    68   tList<BaseObject>* objectList;   //< the list of Objects stored in classID
    69   bool emptyComplete = false;      //< if the completion input is empty string. e.g ""
    70   long completeType = SHELLC_NONE; //< the Type we'd like to complete.
    71   const char* completeString;      //< the string to complete.
     65  const char* completionLine;           //< the inputLine we complete.
     66
     67  long classID;                         //< the classID retrieved from the Class.
     68  std::list<BaseObject*>* objectList;   //< the list of Objects stored in classID
     69  bool emptyComplete = false;           //< if the completion input is empty string. e.g ""
     70  long completeType = SHELLC_NONE;      //< the Type we'd like to complete.
     71  const char* completeString;           //< the string to complete.
    7272
    7373
     
    159159  if (unlikely(classBegin == NULL))
    160160    return false;
    161   const tList<const char>* clList = ClassList::getClassList();
     161  const std::list<const char*>* clList = ClassList::getClassList();
    162162  if (clList != NULL)
    163163  {
     
    180180  if (unlikely(objectBegin == NULL))
    181181    return false;
    182   const tList<BaseObject>* boList = ClassList::getList(classID);
     182  const std::list<BaseObject*>* boList = ClassList::getList(classID);
    183183  if (boList != NULL)
    184184  {
     
    203203  if (unlikely(functionBegin == NULL))
    204204    return false;
    205   tList<const char> fktList;
     205  std::list<const char*> fktList;
    206206  ShellCommandClass::getCommandListOfClass(className, &fktList);
    207207  //printf("%s\n", boList->firstElement()->getName());
     
    220220  if (unlikely(aliasBegin == NULL))
    221221    return false;
    222   tList<const char> aliasList;
     222  std::list<const char*> aliasList;
    223223  ShellCommandClass::getCommandListOfAlias(&aliasList);
    224224  //printf("%s\n", boList->firstElement()->getName());
     
    241241  if (completionList == NULL || this->input == NULL )
    242242    return false;
    243   if (completionList->getSize() == 0)
    244     return false;
    245 
    246   ShellC_Element* addElem = completionList->firstElement();
     243  if (completionList->size() == 0)
     244    return false;
     245
     246  ShellC_Element* addElem = completionList->front();
    247247  const char* addString = addElem->name;
    248248  unsigned int addLength = 0;
     
    252252  if (addString != NULL)
    253253    addLength = strlen(addString);
    254   tIterator<ShellC_Element>* charIterator = completionList->getIterator();
    255   ShellC_Element* charElem = charIterator->firstElement();
     254
    256255  SHELLC_TYPE changeType = SHELLC_NONE;
    257   while (charElem != NULL)
    258   {
    259     if (charElem->type != changeType)
     256  list<ShellC_Element*>::iterator charIT;
     257  for (charIT = completionList->begin(); charIT != completionList->end(); charIT++)
     258  {
     259    if ((*charIT)->type != changeType)
    260260    {
    261261      if (changeType != SHELLC_NONE)
    262262        PRINT(0)("\n");
    263       PRINT(0)("%s: ", ShellCompletion::typeToString(charElem->type));
    264       changeType = charElem->type;
    265     }
    266     PRINTF(0)("%s ", charElem->name);
     263      PRINT(0)("%s: ", ShellCompletion::typeToString((*charIT)->type));
     264      changeType = (*charIT)->type;
     265    }
     266    PRINTF(0)("%s ", (*charIT)->name);
    267267    for (unsigned int i = inputLenght; i < addLength; i++)
    268       if (addString[i] != charElem->name[i])
     268      if (addString[i] != (*charIT)->name[i])
    269269      {
    270270       addLength = i;
    271271//       break;
    272272      }
    273     charElem = charIterator->nextElement();
    274   }
    275   delete charIterator;
     273  }
    276274  PRINT(0)("\n");
    277275
     
    287285     this->input->addCharacters(adder);
    288286
    289       if (completionList->getSize() == 1)
     287      if (completionList->size() == 1)
    290288      {
    291289        if ( addBack != NULL )
     
    305303 * !! The strings MUST NOT be deleted !!
    306304 */
    307 bool ShellCompletion::addToCompleteList(const tList<const char>* inputList, const char* completionBegin, SHELLC_TYPE type)
     305bool ShellCompletion::addToCompleteList(const std::list<const char*>* inputList, const char* completionBegin, SHELLC_TYPE type)
    308306{
    309307  if (inputList == NULL || completionBegin == NULL)
     
    311309  unsigned int searchLength = strlen(completionBegin);
    312310
    313   tIterator<const char>* iterator = inputList->getIterator();
    314   const char* enumString = iterator->firstElement();
    315   while (enumString != NULL)
    316   {
    317     if (strlen(enumString) >= searchLength &&
    318         !strncasecmp(enumString, completionBegin, searchLength))
    319     {
    320       printf("%s\n", enumString);
     311  list<const char*>::const_iterator string;
     312  for (string = inputList->begin(); string != inputList->end(); string++)
     313  {
     314    if (strlen(*string) >= searchLength &&
     315        !strncasecmp(*string, completionBegin, searchLength))
     316    {
     317      printf("%s\n", *string);
    321318      ShellC_Element* newElem = new ShellC_Element;
    322       newElem->name = enumString;
     319      newElem->name = *string;
    323320      newElem->type = type;
    324       this->completionList->add(newElem);
    325     }
    326     enumString = iterator->nextElement();
    327   }
    328   delete iterator;
    329 
     321      this->completionList->push_back(newElem);
     322    }
     323  }
    330324  return true;
    331325}
     
    337331 * !! The strings MUST NOT be deleted !!
    338332 */
    339 bool ShellCompletion::addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin, SHELLC_TYPE type)
     333bool ShellCompletion::addToCompleteList(const std::list<BaseObject*>* inputList, const char* completionBegin, SHELLC_TYPE type)
    340334{
    341335  if (inputList == NULL || completionBegin == NULL)
     
    343337  unsigned int searchLength = strlen(completionBegin);
    344338
    345   tIterator<BaseObject>* iterator = inputList->getIterator();
    346   BaseObject* enumBO = iterator->firstElement();
    347   while (enumBO != NULL)
    348   {
    349     if (enumBO->getName() != NULL &&
    350         strlen(enumBO->getName()) >= searchLength &&
    351         !strncasecmp(enumBO->getName(), completionBegin, searchLength))
     339  list<BaseObject*>::const_iterator bo;
     340  for(bo = inputList->begin(); bo != inputList->end(); bo++)
     341  {
     342    if ((*bo)->getName() != NULL &&
     343        strlen((*bo)->getName()) >= searchLength &&
     344        !strncasecmp((*bo)->getName(), completionBegin, searchLength))
    352345    {
    353346      ShellC_Element* newElem = new ShellC_Element;
    354       newElem->name = enumBO->getName();
     347      newElem->name = (*bo)->getName();
    355348      newElem->type = type;
    356       this->completionList->add(newElem);
    357     }
    358     enumBO = iterator->nextElement();
    359   }
    360   delete iterator;
     349      this->completionList->push_back(newElem);
     350    }
     351  }
    361352
    362353  return true;
     
    372363  if (this->completionList != NULL)
    373364  {
    374     tIterator<ShellC_Element>* elemIT = this->completionList->getIterator();
    375     ShellC_Element* elem = elemIT->firstElement();
    376     while (elem != NULL)
    377     {
    378       delete elem;
    379       elem = elemIT->nextElement();
    380     }
    381     delete this->completionList;
    382   }
    383   this->completionList = new tList<ShellC_Element>;
     365    while (this->completionList->size() > 0)
     366    {
     367      delete this->completionList->front();
     368      this->completionList->pop_front();
     369    }
     370  }
    384371}
    385372
  • trunk/src/lib/shell/shell_completion.h

    r5371 r5779  
    99#ifndef _SHELL_COMPLETION_H
    1010#define _SHELL_COMPLETION_H
     11
     12#include <list>
    1113
    1214// FORWARD DECLARATION
     
    5153  bool generalComplete(const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
    5254
    53   bool addToCompleteList(const tList<const char>* inputList, const char* completionBegin, SHELLC_TYPE type);
    54   bool addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin, SHELLC_TYPE type);
     55  bool addToCompleteList(const std::list<const char*>* inputList, const char* completionBegin, SHELLC_TYPE type);
     56  bool addToCompleteList(const std::list<BaseObject*>* inputList, const char* completionBegin, SHELLC_TYPE type);
    5557  void emptyCompletionList();
    5658
     
    5860
    5961 private:
    60    tList<ShellC_Element>*   completionList;          //!< A list of completions, that are io.
    61    ShellInput*              input;                   //!< the input this completion works on.
     62   std::list<ShellC_Element*>*  completionList;          //!< A list of completions, that are io.
     63   ShellInput*                  input;                   //!< the input this completion works on.
    6264};
    6365
Note: See TracChangeset for help on using the changeset viewer.