Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Sep 18, 2005, 2:39:39 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ShellCommandAlias should really be completed now

Location:
trunk/src/lib/shell
Files:
2 edited

Legend:

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

    r5195 r5196  
    4141  this->classID = CL_NULL;
    4242  this->commandList = new tList<ShellCommandBase>;
    43   this->aliasList = new tList<ShellCommandAlias>;
    4443
    4544  ShellCommandClass::commandClassList->add(this);
     
    9190bool ShellCommandClass::getCommandListOfAlias(tList<const char>* stringList)
    9291{
    93   if (stringList == NULL)
     92  if (stringList == NULL || ShellCommandClass::aliasList == NULL)
    9493    return false;
    9594
    9695  tIterator<ShellCommandAlias>* iterator = ShellCommandClass::aliasList->getIterator();
    97   ShellCommandAlias* elem = iterator->firstElement();
    98   while(elem != NULL)
    99   {
    100     stringList->add(elem->getName());
    101     elem = iterator->nextElement();
    102   }
    103   delete iterator;
    104   return true;
     96   ShellCommandAlias* elem = iterator->firstElement();
     97   while(elem != NULL)
     98   {
     99     stringList->add(elem->getName());
     100     elem = iterator->nextElement();
     101   }
     102   delete iterator;
     103   return true;
    105104}
    106105
     
    126125
    127126  // unregister all aliases (there should be nothing to do here :))
    128   tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();
    129   ShellCommandAlias* elemAL = itAL->firstElement();
    130   while(elemAL != NULL)
    131   {
    132     delete elemAL;
    133     elemAL = itAL->nextElement();
    134   }
    135   delete itAL;
    136   delete ShellCommandClass::aliasList;
    137   ShellCommandClass::aliasList = NULL;
     127  if (ShellCommandClass::aliasList != NULL)
     128  {
     129   tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();
     130   ShellCommandAlias* elemAL = itAL->firstElement();
     131   while(elemAL != NULL)
     132   {
     133     delete elemAL;
     134     elemAL = itAL->nextElement();
     135   }
     136   delete itAL;
     137   delete ShellCommandClass::aliasList;
     138   ShellCommandClass::aliasList = NULL;
     139  }
    138140}
    139141
     
    213215  this->setName(commandName);
    214216  this->description = NULL;
     217  this->alias = NULL;
    215218
    216219//  this->classID = classID;
     
    267270{
    268271  delete[] this->parameters;
     272  if (this->alias != NULL && ShellCommandClass::aliasList != NULL)
     273  {
     274    ShellCommandClass::aliasList->remove(this->alias);
     275    delete this->alias;
     276  }
    269277}
    270278
     
    462470ShellCommandBase* ShellCommandBase::setAlias(const char* alias)
    463471{
    464   ShellCommandAlias* aliasCMD = new ShellCommandAlias(alias, this);
    465   ShellCommandClass::aliasList->add(aliasCMD);
     472  if (this == NULL)
     473    return NULL;
     474
     475  if (this->alias != NULL)
     476  {
     477    PRINTF(2)("not more than one Alias allowed for functions (%s::%s)\n", this->getName(), this->shellClass->getName());
     478  }
     479  else
     480  {
     481    if (ShellCommandClass::aliasList == NULL)
     482      ShellCommandClass::aliasList = new tList<ShellCommandAlias>;
     483
     484    ShellCommandAlias* aliasCMD = new ShellCommandAlias(alias, this);
     485    ShellCommandClass::aliasList->add(aliasCMD);
     486    this->alias = aliasCMD;
     487  }
     488  return this;
    466489}
    467490
  • trunk/src/lib/shell/shell_command.h

    r5195 r5196  
    8585
    8686    /** @returns the CommandList of the Shell */
    87 
    8887    static void unregisterCommand(const char* commandName, const char* className);
    8988
     
    114113  private:
    115114    ShellCommandClass*               shellClass;                           //!< A Pointer to the Shell-Class this Command belongs to.
     115    ShellCommandAlias*               alias;                                //!< An Alias for the Class.
    116116
    117117    const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
     
    319319class ShellCommandAlias
    320320{
     321  friend class ShellCommandBase;
    321322  public:
    322     ShellCommandAlias(const char* aliasName, ShellCommandBase* command) { this->aliasName = aliasName; this->command = command; };
    323 
    324323    const char* getName() const { return this->aliasName; };
    325324    ShellCommandBase* getCommand() const { return this->command; };
     325
     326  private:
     327    ShellCommandAlias(const char* aliasName, ShellCommandBase* command) { this->aliasName = aliasName; this->command = command; };
     328
    326329  private:
    327330    const char*         aliasName;
Note: See TracChangeset for help on using the changeset viewer.