Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Sep 19, 2005, 12:31:56 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Shell no more singleton, and ShellInput is now derive from Text correctly

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

Legend:

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

    r5204 r5206  
    5050  this->setName("Shell");
    5151
     52  // register the shell at the ShellBuffer
     53  ShellBuffer::getInstance()->registerShell(this);
     54
     55
    5256  // Element2D and generals
    5357  this->setAbsCoor2D(3, -400);
     
    7175}
    7276
    73 Shell* Shell::singletonRef = NULL;
    74 
    7577/**
    7678 * standard deconstructor
     
    8587  // delete the inputLine
    8688  delete this->shellInput;
    87 
    88   Shell::singletonRef = NULL;
     89  ShellBuffer::getInstance()->unregisterShell(this);
    8990}
    9091
     
    198199      this->bufferText[i]->setText(NULL, true);
    199200    }
    200 
    201 
    202     // BUFFER FLUSHING
     201  // BUFFER FLUSHING
    203202}
    204203
     
    240239}
    241240
    242 
    243 
    244241/**
    245242 * listens for some event
     
    322319}
    323320
    324 
    325 
    326321// void Shell::testI (int i)
    327322// {
  • trunk/src/lib/shell/shell.h

    r5204 r5206  
    3636
    3737  public:
     38    Shell();
    3839    virtual ~Shell();
    39     /** @returns a Pointer to the only object of this Class */
    40     inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell();  return Shell::singletonRef; };
    41     /** @returns true if this class is instanciated, false otherwise */
    42     inline static bool isInstanciated() { return (Shell::singletonRef == NULL)?false:true; };
    4340
    4441    void activate();
     
    7572
    7673  private:
    77     Shell();
    78     static Shell*            singletonRef;           //!< The singleton-reference to the only memeber of this class.
    7974
    8075    // GENERAL
  • trunk/src/lib/shell/shell_buffer.cc

    r5183 r5206  
    3333{
    3434  ShellBuffer::singletonRef = this;
     35  this->shell = NULL;
    3536
    3637  this->lineCount = 0;
     
    5051ShellBuffer::~ShellBuffer ()
    5152{
    52   if (Shell::isInstanciated())
    53     delete Shell::getInstance();
     53  if (this->shell != NULL)
     54    delete this->shell;
    5455
    5556  this->flushBuffers();
     
    5859
    5960  ShellBuffer::singletonRef = NULL;
     61}
     62
     63/**
     64 * registers the Shell to the Buffer
     65 * @param shell the Shell to register.
     66 */
     67void ShellBuffer::registerShell(Shell* shell)
     68{
     69  if (this->shell == NULL)
     70    this->shell = shell;
     71  else
     72    PRINTF(1)("already registered a Shell to the ShellBuffer\n");
     73}
     74
     75/**
     76 * unregisters the Shell from the Buffer
     77 * @param shell the Shell to unregister.
     78 */
     79void ShellBuffer::unregisterShell(Shell* shell)
     80{
     81  if (this->shell == shell)
     82    this->shell = NULL;
     83  else
     84    PRINTF(1)("cannot unregister shell, because it is not registered to the ShellBuffer\n");
    6085}
    6186
     
    150175    this->lineCount++;
    151176    this->buffer->add(addLine);
    152     if (Shell::isInstanciated() && Shell::getInstance()->isActive())
    153       Shell::getInstance()->printToDisplayBuffer(addLine);
     177    if (likely (this->shell != NULL) && unlikely (this->shell->isActive()))
     178      this->shell->printToDisplayBuffer(addLine);
    154179
    155180    if (this->buffer->getSize() > this->bufferSize)
  • trunk/src/lib/shell/shell_buffer.h

    r5177 r5206  
    1212
    1313// FORWARD DECLARATION
     14class Shell;
    1415template<class T> class tList;
    1516template<class T> class tIterator;
     
    2728  /** @returns true if this class is instanciated, false otherwise */
    2829  inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?false:true; };
     30
     31  void registerShell(Shell* shell);
     32  void unregisterShell(Shell* shell);
    2933
    3034  // BUFFER //
     
    5458   tIterator<char>*         bufferIterator;                     //!< An iterator for the Shells main buffer.
    5559
     60   Shell*                   shell;                              //!< the Registered Shell.
    5661   char                     bufferArray[SHELL_BUFFER_SIZE];     //!< a BUFFER for fast writing
    5762   char                     keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell.
Note: See TracChangeset for help on using the changeset viewer.