Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5175 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Sep 11, 2005, 11:21:56 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: cleaner outtakes of the ShellBuffer

Location:
trunk/src
Files:
6 edited

Legend:

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

    r5174 r5175  
    1818#include "shell.h"
    1919#include "shell_command.h"
     20#include "shell_buffer.h"
     21
    2022
    2123#include "text_engine.h"
     
    4345  this->setName("Shell");
    4446
    45 
    46   this->bActive = false;
    47   this->bufferIterator = this->buffer->getIterator();
    48 
    49   this->inputHistory = new tList<char>;
    50   //this->commandList = new tList<ShellCommand>;
    51 
     47  this->setAbsCoor2D(3, -400);
    5248  this->textSize = 15;
    5349  this->lineSpacing = 5;
    54 
    55   //this->bufferSize = 0;
    56   this->setAbsCoor2D(3, -400);
     50  this->bActive = false;
     51
     52
     53  // BUFFER
     54  this->bufferText = NULL;
     55  this->setBufferDisplaySize(10);
     56
     57  // INPUT LINE
    5758  this->delayed = 0;
    5859  this->setRepeatDelay(.3, .05);
     
    6263  this->inputLine = new char[1];
    6364  this->inputLine[0] = '\0';
     65  this->inputHistory = new tList<char>;
     66  //this->commandList = new tList<ShellCommand>;
    6467
    6568  this->rebuildText();
     
    8992  delete this->inputLine;
    9093
    91   // delete all the Strings in the Buffers
    92   char* charElem = this->bufferIterator->firstElement();
    93   while (charElem != NULL)
    94   {
    95     delete charElem;
    96     charElem = this->bufferIterator->nextElement();
    97   }
    98   delete this->bufferIterator;
    99 
    100 //  if (this->completionList != NULL)
    101     //delete this->completionList;
    102 
    10394  Shell::singletonRef = NULL;
    10495}
     
    118109  this->setRelCoorSoft2D(0, 0, 1, 5);
    119110
    120   this->bufferIterator->lastElement();
     111  ShellBuffer::getInstance()->getBufferIterator()->lastElement();
    121112  for (int i = 0; i < this->bufferDisplaySize; i++)
    122     this->bufferText[i]->setText(this->bufferIterator->prevElement(), true);
     113    this->bufferText[i]->setText(ShellBuffer::getInstance()->getBufferIterator()->prevElement(), true);
    123114}
    124115
     
    135126  this->setRelCoorSoft2D(0, -400, 1, 5);
    136127
    137   this->bufferIterator->lastElement();
     128  ShellBuffer::getInstance()->getBufferIterator()->lastElement();
    138129  for (int i = 0; i < this->bufferDisplaySize; i++)
    139     this->bufferText[i]->setText(this->bufferIterator->prevElement(), false);
     130    this->bufferText[i]->setText(ShellBuffer::getInstance()->getBufferIterator()->prevElement(), false);
    140131}
    141132
     
    207198 * deletes all the Buffers
    208199 */
    209 void Shell::flushBuffers()
     200void Shell::flush()
    210201{
    211202  // remove all chars from the BufferTexts.
     
    216207    }
    217208
    218   // delete all the Chars in the Buffers
    219   tIterator<char>* charIterator = this->buffer->getIterator();
    220   char* charElem = charIterator->firstElement();
    221   while (charElem != NULL)
    222   {
    223     delete charElem;
    224 
    225     charElem = charIterator->nextElement();
    226   }
    227   delete charIterator;
    228   delete this->buffer;
    229   this->buffer = new tList<char>;
    230 }
    231 
    232 /**
    233  * adds a new Line to the List of Buffers
    234  * @param line the Line as in the first argument in printf
    235  */
    236 bool Shell::addBufferLineStatic(const char* line, ...)
    237 {
    238   va_list arguments;
    239   va_start(arguments, line);
    240 
    241 #if DEBUG < 3
    242   if (Shell::singletonRef == NULL)
    243 #endif
    244 
    245   vprintf(line, arguments);
    246 #if DEBUG < 3
    247   else
    248 #else
    249   if (Shell::singletonRef != NULL)
    250 #endif
    251     Shell::singletonRef->addBufferLine(line, arguments);
    252   return true;
    253 }
    254 
    255 /**
    256  * add a Line to the List of Buffers
    257  * @param line
    258  * @param arguments
    259  *
    260  * This function Adds one line to the buffer.
    261  * and displays the line as the First Line of the display-buffer
    262  */
    263 void Shell::addBufferLine(const char* line, va_list arguments)
    264 {
    265    vsprintf(this->bufferArray, line, arguments);
    266 
    267    char* inputEnd;
    268    char* newLineBegin;
    269    char* newLineEnd;
    270 
    271    // check if we have something left in the buffers
    272    if (unlikely(this->keepBuffer))
    273    {
    274      strcat(this->keepBufferArray, this->bufferArray);
    275      inputEnd = this->keepBufferArray + strlen(this->keepBufferArray);
    276      newLineBegin = this->keepBufferArray;
    277      this->keepBuffer = false;
    278    }
    279    else
    280    {
    281      inputEnd = this->bufferArray + strlen(this->bufferArray);
    282      newLineBegin = this->bufferArray;
    283    }
    284 
    285    // adding all the new Lines
    286    while (newLineBegin < inputEnd)
    287    {
    288      newLineEnd = strchr(newLineBegin, '\n');
    289      if (newLineEnd != NULL && *newLineEnd == '\n')
    290        *newLineEnd = '\0';
    291      else
    292      {
    293 //       newLineEnd = newLineBegin + strlen(newLineBegin);
    294        strcpy(this->keepBufferArray, newLineBegin);
    295        this->keepBuffer = true;
    296        break;
    297      }
    298 
    299      char* addLine = new char[strlen(newLineBegin)+1];
    300      strcpy(addLine, newLineBegin);
    301 
    302      this->buffer->add(addLine);
    303 
    304      if (this->buffer->getSize() > this->bufferSize)
    305      {
    306        delete this->buffer->firstElement();
    307        this->buffer->remove(this->buffer->firstElement());
    308      }
    309 
    310      if (this->bActive)
    311      {
    312        this->printToDisplayBuffer(addLine);
    313      }
    314      newLineBegin = newLineEnd+1;
    315    }
     209
     210    // BUFFER FLUSHING
    316211}
    317212
     
    345240
    346241/**
    347  * moves the buffer around lineCount lines upwards (negative values move down)
    348  * @param lineCount the Count of lines to move upwards
    349  *
    350  * @todo
    351  */
    352 void Shell::moveBuffer(unsigned int lineCount)
    353 {
    354 }
    355 
    356 /**
    357  * @param lineNumber the n-th line from the bottom
    358  * @returns the Buffer at Line lineNumber
    359  */
    360 const char* Shell::getBufferLine(unsigned int lineNumber)
    361 {
    362   tIterator<char>* charIterator = this->buffer->getIterator();
    363   char* charElem = charIterator->firstElement();
    364 
    365   int i = 1;
    366   while (charElem != NULL)
    367   {
    368     if (i++ < lineNumber)
    369     {
    370       delete charIterator;
    371       return charElem;
    372     }
    373 
    374     charElem = charIterator->nextElement();
    375   }
    376   delete charIterator;
    377 }
    378 
    379 /**
    380242 * deletes the InputLine
    381243 */
     
    446308bool Shell::executeCommand()
    447309{
    448   this->addBufferLineStatic("Execute Command: %s\n", this->inputLine);
     310  ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine);
    449311
    450312  char* newCommand = new char[strlen(this->inputLine)+1];
     
    464326void Shell::clear()
    465327{
    466   this->flushBuffers();
    467   this->addBufferLine("orxonox - shell\n ==================== \n", NULL);
     328  this->flush();
     329  ShellBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL);
    468330}
    469331
     
    858720
    859721
    860   char* tmpChar = this->bufferIterator->firstElement();
     722  char* tmpChar = ShellBuffer::getInstance()->getBufferIterator()->firstElement();
    861723  while(tmpChar != NULL)
    862724  {
    863725    printf(tmpChar);
    864     tmpChar = this->bufferIterator->nextElement();
     726    tmpChar = ShellBuffer::getInstance()->getBufferIterator()->nextElement();
    865727  }
    866728}
  • trunk/src/lib/shell/shell.h

    r5174 r5175  
    3939    /** @returns a Pointer to the only object of this Class */
    4040    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)?true:false; };
    4143
    4244    void activate();
     
    4648    void rebuildText();
    4749
    48     // BUFFER //
    49     /** @param bufferSize the new Buffer-Size */
    50     void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; };
     50    // BUFFERS
    5151    void setBufferDisplaySize(unsigned int bufferDisplaySize);
    52     void flushBuffers();
    53     static bool addBufferLineStatic(const char* line, ...);
    54     void addBufferLine(const char* line, va_list arg);
     52    void flush();
    5553    void printToDisplayBuffer(const char* text);
    56     void moveBuffer(unsigned int lineCount);
    57 //    void moveBufferTo(unsigned int lineNumber);
    58     const char* getBufferLine(unsigned int lineNumber);
    5954
    6055    // InputLine
     
    10398    static Shell*            singletonRef;           //!< The singleton-reference to the only memeber of this class.
    10499
    105     unsigned int             bufferSize;             //!< The Size of the buffer
    106100    unsigned int             bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters)
    107101
     102    // HANDLING TEXT INPUT
    108103    Text*                    inputLineText;          //!< The inputLine of the Shell
    109104    char*                    inputLine;              //!< the Char-Array of the Buffer
     
    112107    float                    delayed;                //!< how much of the delay is remaining.
    113108    int                      pressedKey;             //!< the pressed key that will be repeated.
    114 
    115     tList<char>*             buffer;                 //!< A list of stored char-arrays(strings) to store the history
    116     tIterator<char>*         bufferIterator;         //!< An iterator for the Shells main buffer.
    117109
    118110    tList<char>*             inputHistory;           //!< The history of given commands.
     
    124116    bool                     bActive;                //!< if the shell is active;
    125117
    126     char                     bufferArray[SHELL_BUFFER_SIZE];     //!< a BUFFER for fast writing
    127     char                     keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell.
    128     bool                     keepBuffer;             //!< if the keepbuffer contains unfinished lines.
    129 
    130118    // completion
    131119    tList<const char>*       completionList;          //!< A list of completions, that are io.
  • trunk/src/lib/shell/shell_buffer.cc

    r5174 r5175  
    1919#include "debug.h"
    2020#include "list.h"
     21#include "shell.h"
    2122
    2223#include "stdlibincl.h"
     
    3132ShellBuffer::ShellBuffer ()
    3233{
     34  ShellBuffer::singletonRef = this;
     35
     36  this->lineCount = 0;
    3337  this->keepBufferArray[0] = '\0';
    3438  this->keepBuffer = false;
    3539  this->buffer = new tList<char>;
     40  this->bufferIterator = this->buffer->getIterator();
    3641
    3742  this->setBufferSize(10);
     
    4550ShellBuffer::~ShellBuffer ()
    4651{
     52  if (Shell::isInstanciated())
     53    delete Shell::getInstance();
    4754
     55  this->flushBuffers();
     56  delete bufferIterator;
    4857  delete buffer;
    4958
     
    5766{
    5867  // delete all the Chars in the Buffers
    59   tIterator<char>* charIterator = this->buffer->getIterator();
    60   char* charElem = charIterator->firstElement();
     68  char* charElem = bufferIterator->firstElement();
    6169  while (charElem != NULL)
    6270  {
    6371    delete charElem;
    6472
    65     charElem = charIterator->nextElement();
     73    charElem = bufferIterator->nextElement();
    6674  }
    67   delete charIterator;
     75  delete this->bufferIterator;
    6876  delete this->buffer;
    6977  this->buffer = new tList<char>;
     78  this->bufferIterator = this->buffer->getIterator();
    7079}
    7180
     
    141150
    142151    this->buffer->add(addLine);
     152    this->lineCount++;
    143153
    144154    if (this->buffer->getSize() > this->bufferSize)
  • trunk/src/lib/shell/shell_buffer.h

    r5174 r5175  
    1414template<class T> class tList;
    1515template<class T> class tIterator;
     16#ifndef NULL
     17#define NULL 0            //!< a pointer to NULL
     18#endif
    1619
    1720//! A class for ...
     
    2225  /** @returns a Pointer to the only object of this Class */
    2326  inline static ShellBuffer* getInstance() { if (!ShellBuffer::singletonRef) ShellBuffer::singletonRef = new ShellBuffer();  return ShellBuffer::singletonRef; };
     27  /** @returns true if this class is instanciated, false otherwise */
     28  inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?true:false; };
    2429
    2530  // BUFFER //
     
    3035  void addBufferLine(const char* line, va_list arg);
    3136  void moveBuffer(unsigned int lineCount);
    32 //    void moveBufferTo(unsigned int lineNumber);
     37// void moveBufferTo(unsigned int lineNumber);
    3338  const char* getBufferLine(unsigned int lineNumber);
     39  inline tIterator<char>*  getBufferIterator() const { return bufferIterator; };
    3440
    3541  private:
  • trunk/src/orxonox.cc

    r5171 r5175  
    5151#include "shell.h"
    5252#include "shell_command.h"
     53#include "shell_buffer.h"
    5354
    5455#include <string.h>
  • trunk/src/story_entities/world.cc

    r5174 r5175  
    116116World::~World ()
    117117{
    118   delete ShellBuffer::getInstance();
     118  delete Shell::getInstance();
    119119  PRINTF(3)("World::~World() - deleting current world\n");
    120120
     
    196196
    197197  /* init the world interface */
    198   ShellBuffer::getInstance();
     198  Shell::getInstance();
    199199
    200200  LightManager::getInstance();
Note: See TracChangeset for help on using the changeset viewer.