Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File:
1 edited

Legend:

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

    r9406 r9869  
    2121
    2222#include "debug.h"
    23 #include "class_list.h"
    2423#include "compiler.h"
    2524
     
    2827namespace OrxShell
    2928{
    30   CmdClassList* ShellCommandClass::commandClassList = NULL;
     29  ObjectListDefinition(ShellCommandClass);
     30
     31  CmdClassList* ShellCommandClass::_commandClassList = NULL;
    3132
    3233  /**
     
    3536   */
    3637  ShellCommandClass::ShellCommandClass(const std::string& className)
    37       : className(className)
    38   {
    39     this->setClassID(CL_SHELL_COMMAND_CLASS, "ShellCommandClass");
     38      : _className(className)
     39  {
     40    this->registerObject(this, ShellCommandClass::_objectList);
    4041    this->setName(className);
    4142
    42     this->classID = CL_NULL;
    43 
    44     if (ShellCommandClass::commandClassList == NULL)
    45       ShellCommandClass::commandClassList = new CmdClassList;
    46     ShellCommandClass::commandClassList->push_back(this);
     43    if (ShellCommandClass::_commandClassList == NULL)
     44      ShellCommandClass::_commandClassList = new CmdClassList;
     45    ShellCommandClass::_commandClassList->push_back(this);
    4746  }
    4847
     
    5251  ShellCommandClass::~ShellCommandClass()
    5352  {
    54     while(!this->commandList.empty())
    55       delete this->commandList.back();
    56 
    57     if (ShellCommandClass::commandClassList != NULL)
    58     {
    59       CmdClassList::iterator delClass = std::find(ShellCommandClass::commandClassList->begin(), ShellCommandClass::commandClassList->end(), this);
    60       if (delClass != ShellCommandClass::commandClassList->end())
    61         ShellCommandClass::commandClassList->erase(delClass);
     53    while(!this->_commandList.empty())
     54      delete this->_commandList.back();
     55
     56    if (ShellCommandClass::_commandClassList != NULL)
     57    {
     58      CmdClassList::iterator delClass = std::find(ShellCommandClass::_commandClassList->begin(), ShellCommandClass::_commandClassList->end(), this);
     59      if (delClass != ShellCommandClass::_commandClassList->end())
     60        ShellCommandClass::_commandClassList->erase(delClass);
    6261    }
    6362  }
     
    6867  void ShellCommandClass::registerCommand(ShellCommand* command)
    6968  {
    70     this->commandList.push_back(command);
     69    this->_commandList.push_back(command);
    7170  }
    7271
     
    7776  void ShellCommandClass::unregisterCommand(ShellCommand* command)
    7877  {
    79     CmdList::iterator delC = std::find(this->commandList.begin(), this->commandList.end(), command);
    80     if (delC != this->commandList.end())
    81       this->commandList.erase(delC);
     78    CmdList::iterator delC = std::find(this->_commandList.begin(), this->_commandList.end(), command);
     79    if (delC != this->_commandList.end())
     80      this->_commandList.erase(delC);
    8281  }
    8382
     
    8988    // unregister all commands and Classes
    9089    CmdClassList::iterator classIT;
    91     if (ShellCommandClass::commandClassList == NULL)
     90    if (ShellCommandClass::_commandClassList == NULL)
    9291      return;
    9392
    94     while (!ShellCommandClass::commandClassList->empty())
    95       delete ShellCommandClass::commandClassList->back();
    96     delete ShellCommandClass::commandClassList;
    97     ShellCommandClass::commandClassList = NULL;
     93    while (!ShellCommandClass::_commandClassList->empty())
     94      delete ShellCommandClass::_commandClassList->back();
     95    delete ShellCommandClass::_commandClassList;
     96    ShellCommandClass::_commandClassList = NULL;
    9897  }
    9998
     
    107106  bool ShellCommandClass::getCommandListOfClass(const std::string& className, std::list<std::string>& stringList)
    108107  {
    109     if (ShellCommandClass::commandClassList == NULL)
     108    if (ShellCommandClass::_commandClassList == NULL)
    110109      return false;
    111110
    112111
    113112    CmdClassList::const_iterator elem;
    114     for(elem = ShellCommandClass::commandClassList->begin(); elem != ShellCommandClass::commandClassList->end(); elem++)
     113    for(elem = ShellCommandClass::_commandClassList->begin(); elem != ShellCommandClass::_commandClassList->end(); elem++)
    115114    {
    116115      if (className == (*elem)->getName())
    117116      {
    118117        CmdList::iterator command;
    119         for(command = (*elem)->commandList.begin(); command != (*elem)->commandList.end(); command++)
     118        for(command = (*elem)->_commandList.begin(); command != (*elem)->_commandList.end(); command++)
    120119          stringList.push_back((*command)->getName());
    121120        return true;
     
    133132  ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className)
    134133  {
    135     if (ShellCommandClass::commandClassList == NULL)
     134    if (ShellCommandClass::_commandClassList == NULL)
    136135      return false;
    137136
    138137
    139138    CmdClassList::const_iterator classIT;
    140     for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    141       if (className == (*classIT)->className)
     139    for (classIT = ShellCommandClass::_commandClassList->begin(); classIT != ShellCommandClass::_commandClassList->end(); classIT++)
     140      if (className == (*classIT)->_className)
    142141        return (*classIT);
    143142    return NULL;
     
    152151  {
    153152    return (ShellCommandClass::getCommandClass(className) != NULL);
    154   }
    155 
    156   ClassID ShellCommandClass::getClassID()
    157   {
    158     if (this->classID == CL_NULL)
    159       this->classID = ClassList::StringToID(this->className);
    160     return this->classID;
    161153  }
    162154
     
    181173  void ShellCommandClass::help(const std::string& className)
    182174  {
    183     if (ShellCommandClass::commandClassList == NULL)
     175    if (ShellCommandClass::_commandClassList == NULL)
    184176    {
    185177      PRINT(0)("No Commands Registered\n");
     
    187179    }
    188180    if (className.empty())
    189       PRINT(0)("===== Displaying %d registered Classes:\n", ShellCommandClass::commandClassList->size());
     181      PRINT(0)("===== Displaying %d registered Classes:\n", ShellCommandClass::_commandClassList->size());
    190182
    191183
    192184    CmdClassList::iterator classIT;
    193     for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    194     {
    195       if (className.empty() || className == (*classIT)->className)
     185    for (classIT = ShellCommandClass::_commandClassList->begin(); classIT != ShellCommandClass::_commandClassList->end(); classIT++)
     186    {
     187      if (className.empty() || className == (*classIT)->_className)
    196188      {
    197         PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size());
     189        PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->_className.c_str(), (*classIT)->_commandList.size());
    198190        CmdList::const_iterator cmdIT;
    199         for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++)
     191        for (cmdIT = (*classIT)->_commandList.begin(); cmdIT != (*classIT)->_commandList.end(); cmdIT++)
    200192        {
    201193          PRINT(0)("  command:'%s' : params:%d: ", (*cmdIT)->getCName(), (*cmdIT)->executor->getParamCount());
Note: See TracChangeset for help on using the changeset viewer.