Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7389 in orxonox.OLD


Ignore:
Timestamp:
Apr 26, 2006, 11:39:51 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: new and improved ShellCommandAlias

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

Legend:

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

    r7388 r7389  
    5454  ShellCommand::~ShellCommand()
    5555  {
    56     if (this->alias != NULL && ShellCommandClass::aliasList != NULL)
    57     {
    58       ShellCommandClass::aliasList->remove(this->alias);
     56    if (this->alias != NULL)
    5957      delete this->alias;
    60     }
    6158    delete this->executor;
    6259  }
     
    172169    {
    173170      // CHECK FOR ALIAS
    174       if (ShellCommandClass::aliasList != NULL)
    175       {
    176         std::list<ShellCommandAlias*>::iterator alias;
    177         for (alias = ShellCommandClass::aliasList->begin(); alias != ShellCommandClass::aliasList->end(); alias++ )
    178         {
    179           if (inputSplits.getString(0) == (*alias)->getName() && (*alias)->getCommand() != NULL &&
    180               (*alias)->getCommand()->shellClass != NULL )
    181           {
    182             objectList = ClassList::getList((*alias)->getCommand()->shellClass->getName());
    183             if (objectList != NULL)
    184             {
    185               (*(*alias)->getCommand()->executor)(objectList->front(), inputSplits.getSubSet(1).join()); /// TODO CHECK IF OK
    186               return true;
    187             }
    188             /// TODO CHECK FOR STATIC functions.
    189           }
     171      std::vector<ShellCommandAlias*>::iterator alias;
     172      for (alias = ShellCommandAlias::aliasList.begin(); alias != ShellCommandAlias::aliasList.end(); alias++ )
     173      {
     174        if (inputSplits.getString(0) == (*alias)->getName() && (*alias)->getCommand() != NULL &&
     175            (*alias)->getCommand()->shellClass != NULL )
     176        {
     177          objectList = ClassList::getList((*alias)->getCommand()->shellClass->getName());
     178          if (objectList != NULL)
     179          {
     180            (*(*alias)->getCommand()->executor)(objectList->front(), inputSplits.getSubSet(1).join());
     181            return true;
     182          }
     183          /// TODO CHECK FOR STATIC functions.
    190184        }
    191185      }
     
    271265
    272266  /**
    273    * adds an Alias to this Command
     267   * @brief adds an Alias to this Command
    274268   * @param alias the name of the Alias to set
    275269   * @returns itself
     
    286280    else
    287281    {
    288       if (ShellCommandClass::aliasList == NULL)
    289         ShellCommandClass::aliasList = new std::list<ShellCommandAlias*>;
    290 
    291282      ShellCommandAlias* aliasCMD = new ShellCommandAlias(alias, this);
    292       ShellCommandClass::aliasList->push_back(aliasCMD);
     283      ShellCommandAlias::aliasList.push_back(aliasCMD);
    293284      this->alias = aliasCMD;
    294285    }
     
    357348  }
    358349
     350
     351  ShellCommandAlias::ShellCommandAlias(const std::string& aliasName, ShellCommand* command)
     352  {
     353    this->aliasName = aliasName;
     354    this->command = command;
     355    ShellCommandAlias::aliasList.push_back(this);
     356  };
     357
     358  ShellCommandAlias::~ShellCommandAlias()
     359  {
     360    std::vector<ShellCommandAlias*>::iterator delA = std::find(aliasList.begin(), aliasList.end(), this);
     361    if (delA != aliasList.end())
     362      ShellCommandAlias::aliasList.push_back(this);
     363
     364  }
     365
     366  std::vector<ShellCommandAlias*> ShellCommandAlias::aliasList;
     367  /**
     368  * @brief collects the Aliases registered to the ShellCommands
     369  * @param stringList a List to paste the Aliases into.
     370  * @returns true on success, false otherwise
     371   */
     372  bool ShellCommandAlias::getCommandListOfAlias(std::list<std::string>& stringList)
     373  {
     374    std::vector<ShellCommandAlias*>::iterator alias;
     375    for (alias = ShellCommandAlias::aliasList.begin(); alias != ShellCommandAlias::aliasList.end(); alias++)
     376      stringList.push_back((*alias)->getName());
     377    return true;
     378  }
     379
     380
    359381}
  • trunk/src/lib/shell/shell_command.h

    r7388 r7389  
    101101    /** @returns the Command, this Alias is asociated with */
    102102    ShellCommand* getCommand() const { return this->command; };
     103    static bool getCommandListOfAlias(std::list<std::string>& stringList);
    103104
    104105  private:
    105106    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
    106     ShellCommandAlias(const std::string& aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
    107 
     107    ShellCommandAlias(const std::string& aliasName, ShellCommand* command);
     108    ~ShellCommandAlias();
    108109  private:
    109110    std::string     aliasName;       //!< the name of the Alias
    110111    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
     112
     113    static std::vector<ShellCommandAlias*> aliasList; //!< A list of Aliases to A Commands.
    111114  };
    112115
  • trunk/src/lib/shell/shell_command_class.cc

    r7388 r7389  
    2626namespace OrxShell
    2727{
    28 
    2928  std::list<ShellCommandClass*>* ShellCommandClass::commandClassList = NULL;
    30   std::list<ShellCommandAlias*>* ShellCommandClass::aliasList = NULL;
    3129
    3230  /**
     
    7977
    8078  /**
    81    * collects the Aliases registered to the ShellCommands
    82    * @param stringList a List to paste the Aliases into.
    83    * @returns true on success, false otherwise
    84    */
    85   bool ShellCommandClass::getCommandListOfAlias(std::list<std::string>& stringList)
    86   {
    87     if (ShellCommandClass::aliasList == NULL)
    88       return false;
    89 
    90     std::list<ShellCommandAlias*>::iterator alias;
    91     for (alias = ShellCommandClass::aliasList->begin(); alias != ShellCommandClass::aliasList->end(); alias++)
    92       stringList.push_back((*alias)->getName());
    93     return true;
    94   }
    95 
    96   /**
    97    * unregisters all Commands that exist
     79   * @brief unregisters all Commands that exist
    9880   */
    9981  void ShellCommandClass::unregisterAllCommands()
     
    10991    }
    11092
    111     // unregister all aliases (there should be nothing to do here :))
    112     if (ShellCommandClass::aliasList != NULL)
    113     {
    114       std::list<ShellCommandAlias*>::iterator alias;
    115       for (alias = ShellCommandClass::aliasList->begin(); alias != ShellCommandClass::aliasList->end(); alias++)
    116         delete (*alias);
    117       delete ShellCommandClass::aliasList;
    118       ShellCommandClass::aliasList = NULL;
    119     }
    120   }
    121 
    122   /**
    123    * checks if a Class is already registered to the Commands' class-stack
     93  }
     94
     95  /**
     96   * @brief checks if a Class is already registered to the Commands' class-stack
    12497   * @param className the Name of the Class to check for
    12598   * @returns the CommandClass if found, NULL otherwise
     
    222195  {
    223196    std::vector<ShellCommand*>::iterator delC = std::find(this->commandList.begin(), this->commandList.end(), command);
    224     this->commandList.erase(delC);
     197    if (delC != this->commandList.end())
     198      this->commandList.erase(delC);
    225199  }
    226200
  • trunk/src/lib/shell/shell_command_class.h

    r7388 r7389  
    2727
    2828    static bool getCommandListOfClass(const std::string& className, std::list<std::string>& stringList);
    29     static bool getCommandListOfAlias(std::list<std::string>& aliasList);
    3029
    3130    static ShellCommandClass* getCommandClass(const std::string& className);
     
    4948    std::vector<ShellCommand*>             commandList;               //!< A list of Commands from this Class
    5049    static std::list<ShellCommandClass*>*  commandClassList;          //!< A list of Classes
    51     static std::list<ShellCommandAlias*>*  aliasList;                 //!< A list of Aliases to A Commands.
    5250  };
    5351
  • trunk/src/lib/shell/shell_completion.cc

    r7388 r7389  
    166166  {
    167167    std::list<std::string> aliasList;
    168     ShellCommandClass::getCommandListOfAlias(aliasList);
     168    ShellCommandAlias::getCommandListOfAlias(aliasList);
    169169    //printf("%s\n", boList->firstElement()->getName());
    170170    if (!this->addToCompleteList(aliasList, aliasBegin, AliasCompletion))
Note: See TracChangeset for help on using the changeset viewer.