Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7742 in orxonox.OLD for trunk/src/lib/shell/shell_command_class.cc


Ignore:
Timestamp:
May 20, 2006, 3:53:37 PM (19 years ago)
Author:
bensch
Message:

trying to fix a strange bug of the static initialisation

File:
1 edited

Legend:

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

    r7411 r7742  
    2424#include "compiler.h"
    2525
     26
     27
    2628namespace OrxShell
    2729{
    28   std::vector<ShellCommandClass*> ShellCommandClass::commandClassList;
     30  CmdClassList ShellCommandClass::commandClassList;
    2931
    3032  /**
     
    4042    this->classID = CL_NULL;
    4143
     44    printf("::: %d\n", commandClassList.size());
    4245    ShellCommandClass::commandClassList.push_back(this);
     46    printf("::: %d\n", commandClassList.size());
    4347  }
    4448
     
    5054    while(!this->commandList.empty())
    5155      delete this->commandList.back();
     56    CmdClassList::iterator delClass = std::find(ShellCommandClass::commandClassList.begin(), ShellCommandClass::commandClassList.end(), this);
     57    if (delClass != ShellCommandClass::commandClassList.end())
     58      ShellCommandClass::commandClassList.erase(delClass);
    5259  }
    5360
     
    5764  void ShellCommandClass::registerCommand(ShellCommand* command)
    5865  {
     66    printf("::::::::::: ADDED COMMAND:: '%s'\n", command->getName());
    5967    this->commandList.push_back(command);
    60   }
    61 
    62   /**
    63    * @brief unregister command.
     68    this->help();
     69  }
     70
     71  /**
     72   * @brief Unregisters a command.
    6473   * @param command the Command to unregister.
    6574   */
    6675  void ShellCommandClass::unregisterCommand(ShellCommand* command)
    6776  {
    68     std::vector<ShellCommand*>::iterator delC = std::find(this->commandList.begin(), this->commandList.end(), command);
     77    CmdList::iterator delC = std::find(this->commandList.begin(), this->commandList.end(), command);
    6978    if (delC != this->commandList.end())
    7079      this->commandList.erase(delC);
     
    7786  {
    7887    // unregister all commands and Classes
    79     std::vector<ShellCommandClass*>::iterator classIT;
    80     for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++)
    81       delete (*classIT);
     88    CmdClassList::iterator classIT;
     89
     90    while (!ShellCommandClass::commandClassList.empty())
     91      delete ShellCommandClass::commandClassList.back();
    8292  }
    8393
     
    91101  bool ShellCommandClass::getCommandListOfClass(const std::string& className, std::list<std::string>& stringList)
    92102  {
    93     std::vector<ShellCommandClass*>::iterator elem;
     103    CmdClassList::const_iterator elem;
    94104    for(elem = ShellCommandClass::commandClassList.begin(); elem != ShellCommandClass::commandClassList.end(); elem++)
    95105    {
    96106      if (className == (*elem)->getName())
    97107      {
    98         std::vector<ShellCommand*>::iterator command;
     108        CmdList::iterator command;
    99109        for(command = (*elem)->commandList.begin(); command != (*elem)->commandList.end(); command++)
    100110          stringList.push_back((*command)->getName());
     111        return true;
    101112      }
    102113    }
    103     return true;
     114    return false;
    104115  }
    105116
     
    110121   * @returns the CommandClass if found, NULL otherwise
    111122   */
    112   const ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className)
    113   {
    114     std::vector<ShellCommandClass*>::const_iterator classIT;
     123  ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className)
     124  {
     125    CmdClassList::const_iterator classIT;
    115126    for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++)
    116127      if (className == (*classIT)->className)
     
    144155  ShellCommandClass* ShellCommandClass::acquireCommandClass(const std::string& className)
    145156  {
    146     std::vector<ShellCommandClass*>::iterator classIT;
    147     for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++)
    148       if (className == (*classIT)->className)
    149         return (*classIT);
     157    ShellCommandClass* cmdClass = ShellCommandClass::getCommandClass(className);
     158    if (cmdClass != NULL)
     159      return (cmdClass);
    150160    return new ShellCommandClass(className);
    151161  }
     
    157167  void ShellCommandClass::help(const std::string& className)
    158168  {
    159     std::vector<ShellCommandClass*>::iterator classIT;
     169    if (className.empty())
     170      PRINT(0)("===== Displaying %d registered Classes:\n", ShellCommandClass::commandClassList.size());
     171
     172
     173    CmdClassList::iterator classIT;
    160174    for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++)
    161175    {
    162       if (className == (*classIT)->className)
     176      if (className.empty() || className == (*classIT)->className)
    163177      {
    164178        PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size());
    165         std::vector<ShellCommand*>::const_iterator cmdIT;
     179        CmdList::const_iterator cmdIT;
    166180        for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++)
    167181        {
     
    174188          PRINT(0)("\n");
    175189        }
    176         return;
     190        if (likely(!className.empty()))
     191          return;
    177192      }
    178193    }
    179     PRINTF(3)("Class %s not found in Command's classes\n", className.c_str());
    180   }
    181 
     194    PRINTF(3)("Class '%s' not found in Command's classes\n", className.c_str());
     195  }
    182196}
    183197
Note: See TracChangeset for help on using the changeset viewer.