Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Apr 27, 2006, 1:33:23 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: list to vector

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

Legend:

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

    r7389 r7394  
    2727namespace OrxShell
    2828{
    29 
    30   /**
    31    * constructs and registers a new Command
     29  SHELL_COMMAND_STATIC(debug, ShellCommand, ShellCommand::debug);
     30
     31
     32  /**
     33   * @brief constructs and registers a new Command
    3234   * @param commandName the name of the Command
    3335   * @param className the name of the class to apply this command to
     
    5052
    5153  /**
    52    * deconstructs a ShellCommand
     54   * @brief deconstructs a ShellCommand
    5355   */
    5456  ShellCommand::~ShellCommand()
     
    106108
    107109  /**
    108    * checks if a command has already been registered.
     110   * @brief checks if a command has already been registered.
    109111   * @param commandName the name of the Command
    110112   * @param className the name of the Class the command should apply to.
     
    116118  bool ShellCommand::isRegistered(const std::string& commandName, const std::string& className)
    117119  {
    118     if (ShellCommandClass::commandClassList == NULL)
    119     {
    120       ShellCommandClass::initCommandClassList();
    121       return false;
    122     }
    123 
    124120    const ShellCommandClass* checkClass = ShellCommandClass::isRegistered(className);
    125121    if (checkClass != NULL)
     
    142138
    143139  /**
    144    * executes commands
     140   * @brief executes commands
    145141   * @param executionString the string containing the following input
    146142   * ClassName [ObjectName] functionName [parameter1[,parameter2[,...]]]
     
    149145  bool ShellCommand::execute(const std::string& executionString)
    150146  {
    151     if (ShellCommandClass::commandClassList == NULL)
    152       return false;
    153 
    154147    long classID = CL_NULL;                      //< the classID retrieved from the Class.
    155148    ShellCommandClass* commandClass = NULL;      //< the command class this command applies to.
     
    186179
    187180      // looking for a Matching Class
    188       if (likely(ShellCommandClass::commandClassList != NULL))
    189       {
    190         std::list<ShellCommandClass*>::iterator commandClassIT;
    191         for (commandClassIT = ShellCommandClass::commandClassList->begin(); commandClassIT != ShellCommandClass::commandClassList->end(); commandClassIT++)
    192         {
    193           if ((*commandClassIT)->getName() && inputSplits[0] == (*commandClassIT)->getName())
    194           {
    195             //elemCL->getName();
    196             classID = ClassList::StringToID((*commandClassIT)->getName());
    197             commandClass = (*commandClassIT);
    198             objectList = ClassList::getList((ClassID)classID);
    199             break;
    200           }
     181      std::vector<ShellCommandClass*>::iterator commandClassIT;
     182      for (commandClassIT = ShellCommandClass::commandClassList.begin(); commandClassIT != ShellCommandClass::commandClassList.end(); commandClassIT++)
     183      {
     184        if ((*commandClassIT)->getName() && inputSplits[0] == (*commandClassIT)->getName())
     185        {
     186          //elemCL->getName();
     187          classID = ClassList::StringToID((*commandClassIT)->getName());
     188          commandClass = (*commandClassIT);
     189          objectList = ClassList::getList((ClassID)classID);
     190          break;
    201191        }
    202192      }
     
    312302  void ShellCommand::debug()
    313303  {
    314     if (ShellCommandClass::commandClassList == NULL)
    315     {
    316       PRINT(0)("No Command registered.\n");
    317       return;
    318     }
    319 
    320     std::list<ShellCommandClass*>::iterator classIT;
    321     for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
     304    std::vector<ShellCommandClass*>::iterator classIT;
     305    for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++)
    322306    {
    323307      PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size());
  • trunk/src/lib/shell/shell_command_class.cc

    r7390 r7394  
    2626namespace OrxShell
    2727{
    28   std::list<ShellCommandClass*>* ShellCommandClass::commandClassList = NULL;
     28  std::vector<ShellCommandClass*> ShellCommandClass::commandClassList;
    2929
    3030  /**
     
    4040    this->classID = CL_NULL;
    4141
    42     ShellCommandClass::commandClassList->push_back(this);
     42    ShellCommandClass::commandClassList.push_back(this);
    4343  }
    4444
     
    7979  void ShellCommandClass::unregisterAllCommands()
    8080  {
    81     if (ShellCommandClass::commandClassList != NULL)
    82     {
    83       // unregister all commands and Classes
    84       std::list<ShellCommandClass*>::iterator classIT;
    85       for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    86         delete (*classIT);
    87       delete ShellCommandClass::commandClassList;
    88       ShellCommandClass::commandClassList = NULL;
    89     }
    90 
     81    // unregister all commands and Classes
     82    std::vector<ShellCommandClass*>::iterator classIT;
     83    for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++)
     84      delete (*classIT);
    9185  }
    9286
     
    10094  bool ShellCommandClass::getCommandListOfClass(const std::string& className, std::list<std::string>& stringList)
    10195  {
    102     std::list<ShellCommandClass*>::iterator elem;
    103     for(elem = ShellCommandClass::commandClassList->begin(); elem != ShellCommandClass::commandClassList->end(); elem++)
     96    std::vector<ShellCommandClass*>::iterator elem;
     97    for(elem = ShellCommandClass::commandClassList.begin(); elem != ShellCommandClass::commandClassList.end(); elem++)
    10498    {
    10599      if (className == (*elem)->getName())
     
    121115  const ShellCommandClass* ShellCommandClass::isRegistered(const std::string& className)
    122116  {
    123     if (ShellCommandClass::commandClassList == NULL)
    124       initCommandClassList();
    125 
    126     std::list<ShellCommandClass*>::const_iterator classIT;
    127     for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
     117    std::vector<ShellCommandClass*>::const_iterator classIT;
     118    for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++)
    128119    {
    129120      if (className == (*classIT)->className)
     
    145136  ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className)
    146137  {
    147     if (ShellCommandClass::commandClassList == NULL)
    148       initCommandClassList();
    149 
    150     std::list<ShellCommandClass*>::iterator classIT;
    151     for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    152     {
     138    std::vector<ShellCommandClass*>::iterator classIT;
     139    for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++)
    153140      if (className == (*classIT)->className)
    154       {
    155141        return (*classIT);
    156       }
    157     }
    158142    return new ShellCommandClass(className);
    159   }
    160 
    161   /**
    162    * @brief initializes the CommandList (if it is NULL)
    163    */
    164   void ShellCommandClass::initCommandClassList()
    165   {
    166     if (ShellCommandClass::commandClassList == NULL)
    167     {
    168       ShellCommandClass::commandClassList = new std::list<ShellCommandClass*>;
    169       ShellCommand::registerCommand("debug", "ShellCommand", ExecutorStatic<ShellCommand>(ShellCommand::debug));
    170     }
    171143  }
    172144
     
    177149  void ShellCommandClass::help(const std::string& className)
    178150  {
    179     if (likely(ShellCommandClass::commandClassList != NULL))
     151    std::vector<ShellCommandClass*>::iterator classIT;
     152    for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++)
    180153    {
    181       std::list<ShellCommandClass*>::iterator classIT;
    182       for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
     154      if (className == (*classIT)->className)
    183155      {
    184         if (className == (*classIT)->className)
     156        PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size());
     157        std::vector<ShellCommand*>::const_iterator cmdIT;
     158        for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++)
    185159        {
    186           PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size());
    187           std::vector<ShellCommand*>::const_iterator cmdIT;
    188           for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++)
    189           {
    190             PRINT(0)("  command:'%s' : params:%d: ", (*cmdIT)->getName(), (*cmdIT)->executor->getParamCount());
    191             /// FIXME
    192             /*          for (unsigned int i = 0; i< elem->paramCount; i++)
    193               PRINT(0)("%s ", ShellCommand::paramToString(elem->parameters[i]));*/
    194             if (!(*cmdIT)->description.empty())
    195               PRINT(0)("- %s", (*cmdIT)->description.c_str());
    196             PRINT(0)("\n");
    197           }
    198           return;
     160          PRINT(0)("  command:'%s' : params:%d: ", (*cmdIT)->getName(), (*cmdIT)->executor->getParamCount());
     161          /// FIXME
     162          /*          for (unsigned int i = 0; i< elem->paramCount; i++)
     163            PRINT(0)("%s ", ShellCommand::paramToString(elem->parameters[i]));*/
     164          if (!(*cmdIT)->description.empty())
     165            PRINT(0)("- %s", (*cmdIT)->description.c_str());
     166          PRINT(0)("\n");
    199167        }
     168        return;
    200169      }
    201       PRINTF(3)("Class %s not found in Command's classes\n", className.c_str());
    202170    }
    203     else
    204     {
    205       PRINTF(1)("List of commandClasses does not exist");
    206     }
     171    PRINTF(3)("Class %s not found in Command's classes\n", className.c_str());
    207172  }
    208173
  • trunk/src/lib/shell/shell_command_class.h

    r7389 r7394  
    2424  public:
    2525    /** @returns the CommandClassList */
    26     static const std::list<ShellCommandClass*>* getCommandClassList() { return ShellCommandClass::commandClassList; };
     26    static const std::vector<ShellCommandClass*>& getCommandClassList() { return ShellCommandClass::commandClassList; };
    2727
    2828    static bool getCommandListOfClass(const std::string& className, std::list<std::string>& stringList);
     
    3838
    3939    static const ShellCommandClass* isRegistered(const std::string& className);
    40     static void initCommandClassList();
    4140
    4241    void registerCommand(ShellCommand* command);
     
    4746    long                                   classID;                   //!< The classID of this Class
    4847    std::vector<ShellCommand*>             commandList;               //!< A list of Commands from this Class
    49     static std::list<ShellCommandClass*>*  commandClassList;          //!< A list of Classes
     48
     49    static std::vector<ShellCommandClass*> commandClassList;          //!< A list of Classes
    5050  };
    5151
Note: See TracChangeset for help on using the changeset viewer.