Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5072 in orxonox.OLD for trunk


Ignore:
Timestamp:
Aug 19, 2005, 12:59:46 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: started function implementation for Shell

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/text_engine.cc

    r4857 r5072  
    9595  if (this->text)
    9696    delete []this->text;
    97   this->text = new char[strlen(text)+1];
    98   strcpy(this->text, text);
     97  if (text != NULL)
     98  {
     99    this->text = new char[strlen(text)+1];
     100    strcpy(this->text, text);
     101  }
     102  else
     103  {
     104    this->text = new char[1];
     105    strcpy(this->text, "");
     106  }
    99107
    100108
  • trunk/src/orxonox.cc

    r5037 r5072  
    4949#include "class_list.h"
    5050#include "substring.h"
     51#include "shell.h"
    5152
    5253#include <string.h>
     
    9394  delete GarbageCollector::getInstance();
    9495  FastFactory::deleteAll();
     96  delete Shell::getInstance();
    9597
    9698  delete EventHandler::getInstance();
     
    247249
    248250  CDEngine::getInstance();
     251  Shell::getInstance();
    249252
    250253  return 0;
  • trunk/src/util/shell.cc

    r5069 r5072  
    1818#include "shell.h"
    1919
     20#include "text_engine.h"
     21#include "list.h"
     22
    2023using namespace std;
    2124
     
    2629Shell::Shell ()
    2730{
    28    this->setClassID(CL_SHELL, "Shell");
     31  this->setClassID(CL_SHELL, "Shell");
     32  this->setName("Shell");
     33
     34  this->bufferText = new tList<Text>;
     35  this->buffer = new tList<char>;
     36
     37  this->setBufferSize(100);
     38  this->setBufferDisplaySize(5);
    2939}
    3040
     
    4252}
    4353
    44 
    45 
    46 
    47 void setBufferDisplaySize(unsigned int bufferDisplaySize);
     54void Shell::setBufferDisplaySize(unsigned int bufferDisplaySize)
     55{
     56  this->bufferDisplaySize = bufferDisplaySize;
     57
     58  while (bufferDisplaySize < this->bufferText->getSize())
     59  {
     60    delete this->bufferText->lastElement();
     61    this->bufferText->removeLast();
     62  }
     63  while(bufferDisplaySize > this->bufferText->getSize())
     64  {
     65    Text* newText = TextEngine::getInstance()->createText("fonts/earth.ttf", 30, TEXT_DYNAMIC, 0, 255, 0);
     66    this->bufferText->add(newText);
     67    // add the Text here
     68  }
     69}
    4870
    4971/**
     
    5274void Shell::flushBuffers()
    5375{
    54 
     76  // remove all chars from the BufferTexts.
     77  tIterator<Text>* textIterator = this->bufferText->getIterator();
     78  Text* textElem = textIterator->nextElement();
     79
     80  while (textElem != NULL)
     81  {
     82    textElem->setText(NULL);
     83
     84    textElem = textIterator->nextElement();
     85  }
     86  delete textIterator;
     87
     88
     89  // delete all the Chars in the Buffers
     90  tIterator<char>* charIterator = this->buffer->getIterator();
     91  char* charElem = charIterator->nextElement();
     92
     93  while (charElem != NULL)
     94  {
     95    delete charElem;
     96
     97    charElem = charIterator->nextElement();
     98  }
     99  delete charIterator;
    55100}
    56101
     
    59104 * @param line the Line as in the first argument in printf
    60105 * @param args the arguments as a va_list
     106 *
     107 * @todo optimize
    61108 */
    62109void Shell::addBufferLine(const char* line, va_list args)
    63110{
     111  char tmp[1024];// = new char*
     112  vsprintf(tmp, line, args);
     113
     114  char* newLine = new char[strlen(tmp)+1];
     115  strcpy(newLine, tmp);
     116
     117  this->buffer->add(newLine);
     118
     119  if (this->buffer->getSize() > this->bufferSize)
     120  {
     121    delete this->buffer->firstElement();
     122    this->buffer->remove(this->buffer->firstElement());
     123  }
    64124}
    65125
     
    67127 * moves the buffer around lineCount lines upwards (negative values move down)
    68128 * @param lineCount the Count of lines to move upwards
     129 *
     130 * @todo
    69131 */
    70132void Shell::moveBuffer(int lineCount)
     
    78140const char* Shell::getBufferLine(unsigned int lineNumber)
    79141{
     142  tIterator<char>* charIterator = this->buffer->getIterator();
     143  char* charElem = charIterator->nextElement();
     144
     145  int i = 1;
     146  while (charElem != NULL)
     147  {
     148    if (i++ < lineNumber)
     149    {
     150      delete charIterator;
     151      return charElem;
     152    }
     153
     154    charElem = charIterator->nextElement();
     155  }
     156  delete charIterator;
    80157}
    81158
     
    86163void Shell::flushInputLine()
    87164{
     165  if (likely(this->inputLine != NULL))
     166  {
     167    delete [] this->inputLine;
     168  }
     169  this->inputLine = new char[1];
     170  *this->inputLine = '\0';
     171
    88172}
    89173
     
    94178void Shell::addCharacter(char character)
    95179{
     180  char* addCharLine = new char[strlen(inputLine)+2];
     181
     182  sprintf(addCharLine, "%s%c", this->inputLine, character);
     183  delete this->inputLine;
     184  this->inputLine = addCharLine;
    96185}
    97186
     
    102191void Shell::addCharacters(const char* characters)
    103192{
     193  char* addCharLine = new char[strlen(inputLine)+strlen(characters)+1];
     194
     195  sprintf(addCharLine, "%s%s", this->inputLine, characters);
     196  delete this->inputLine;
     197  this->inputLine = addCharLine;
    104198}
    105199
     
    110204void Shell::removeCharacters(unsigned int characterCount)
    111205{
     206  if (characterCount > strlen(this->inputLine))
     207    characterCount = strlen(this->inputLine);
     208
     209  char* removeCharLine = new char[strlen(inputLine)-characterCount+1];
     210
     211  strncpy(removeCharLine, this->inputLine, strlen(inputLine)-characterCount);
     212  delete this->inputLine;
     213  this->inputLine = removeCharLine;
    112214}
    113215
  • trunk/src/util/shell.h

    r5069 r5072  
    3535    virtual ~Shell();
    3636    /** @returns a Pointer to the only object of this Class */
    37     inline static Shell* getInstance(void) { if (!Shell::singletonRef) Shell::singletonRef = new Shell();  return Shell::singletonRef; };
     37    inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell();  return Shell::singletonRef; };
    3838
    3939
     
    7070  private:
    7171    Shell();
    72     static Shell*          singletonRef;
     72    static Shell*          singletonRef;           //!< The singleton-reference to the only memeber of this class.
    7373
    74     unsigned int           bufferSize;
    75     unsigned int           bufferDisplaySize;
     74    unsigned int           bufferSize;             //!< The Size of the buffer
     75    unsigned int           bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters)
    7676
    77     char*                  inputLine;
     77    char*                  inputLine;              //!< the Char-Array of the Buffer
    7878
    79     tList<char>*           buffer;
     79    tList<char>*           buffer;                 //!< A list of stored char-arrays(strings) to store the history
    8080
    81     tList<Text>*           bufferText;             //!< A list of sored bufferLines of the Shell
     81    tList<Text>*           bufferText;             //!< A list of stored bufferTexts for the display of the buffer
    8282    Text*                  inputLineText;          //!< The inputLine of the Shell
    8383};
Note: See TracChangeset for help on using the changeset viewer.