Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5174 in orxonox.OLD for trunk/src/lib/shell/shell_buffer.cc


Ignore:
Timestamp:
Sep 11, 2005, 10:30:38 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ShellBuffer is extern to Shell now… (But NOT used in Shell yet)

File:
1 edited

Legend:

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

    r5173 r5174  
    1717
    1818#include "shell_buffer.h"
     19#include "debug.h"
     20#include "list.h"
     21
     22#include "stdlibincl.h"
    1923
    2024using namespace std;
     
    2731ShellBuffer::ShellBuffer ()
    2832{
    29 // this->setClassID(CL_PROTO_ID, "ProtoClass");
     33  this->keepBufferArray[0] = '\0';
     34  this->keepBuffer = false;
     35  this->buffer = new tList<char>;
    3036
    31    /* If you make a new class, what is most probably the case when you write this file
    32       don't forget to:
    33        1. Add the new file new_class.cc to the ./src/Makefile.am
    34        2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS
    35 
    36       Advanced Topics:
    37       - if you want to let your object be managed via the ObjectManager make sure to read
    38         the object_manager.h header comments. You will use this most certanly only if you
    39         make many objects of your class, like a weapon bullet.
    40    */
     37  this->setBufferSize(10);
    4138}
    4239
     40ShellBuffer* ShellBuffer::singletonRef = NULL;
    4341
    4442/**
     
    4745ShellBuffer::~ShellBuffer ()
    4846{
    49   // delete what has to be deleted here
     47
     48  delete buffer;
     49
     50  ShellBuffer::singletonRef = NULL;
    5051}
     52
     53/**
     54 * deletes all the Buffers
     55 */
     56void ShellBuffer::flushBuffers()
     57{
     58  // delete all the Chars in the Buffers
     59  tIterator<char>* charIterator = this->buffer->getIterator();
     60  char* charElem = charIterator->firstElement();
     61  while (charElem != NULL)
     62  {
     63    delete charElem;
     64
     65    charElem = charIterator->nextElement();
     66  }
     67  delete charIterator;
     68  delete this->buffer;
     69  this->buffer = new tList<char>;
     70}
     71
     72/**
     73 * adds a new Line to the List of Buffers
     74 * @param line the Line as in the first argument in printf
     75 */
     76bool ShellBuffer::addBufferLineStatic(const char* line, ...)
     77{
     78  va_list arguments;
     79  va_start(arguments, line);
     80
     81#if DEBUG < 3
     82  if (ShellBuffer::singletonRef == NULL)
     83#endif
     84
     85//  vprintf(line, arguments);
     86#if DEBUG < 3
     87  else
     88#else
     89  if (ShellBuffer::singletonRef != NULL)
     90#endif
     91    ShellBuffer::singletonRef->addBufferLine(line, arguments);
     92  return true;
     93}
     94
     95/**
     96 * add a Line to the List of Buffers
     97 * @param line
     98 * @param arguments
     99 *
     100 * This function Adds one line to the buffer.
     101 * and displays the line as the First Line of the display-buffer
     102 */
     103void ShellBuffer::addBufferLine(const char* line, va_list arguments)
     104{
     105  vsprintf(this->bufferArray, line, arguments);
     106
     107  char* inputEnd;
     108  char* newLineBegin;
     109  char* newLineEnd;
     110
     111   // check if we have something left in the buffers
     112  if (unlikely(this->keepBuffer))
     113  {
     114    strcat(this->keepBufferArray, this->bufferArray);
     115    inputEnd = this->keepBufferArray + strlen(this->keepBufferArray);
     116    newLineBegin = this->keepBufferArray;
     117    this->keepBuffer = false;
     118  }
     119  else
     120  {
     121    inputEnd = this->bufferArray + strlen(this->bufferArray);
     122    newLineBegin = this->bufferArray;
     123  }
     124
     125   // adding all the new Lines
     126  while (newLineBegin < inputEnd)
     127  {
     128    newLineEnd = strchr(newLineBegin, '\n');
     129    if (newLineEnd != NULL && *newLineEnd == '\n')
     130      *newLineEnd = '\0';
     131    else
     132    {
     133//       newLineEnd = newLineBegin + strlen(newLineBegin);
     134      strcpy(this->keepBufferArray, newLineBegin);
     135      this->keepBuffer = true;
     136      break;
     137    }
     138
     139    char* addLine = new char[strlen(newLineBegin)+1];
     140    strcpy(addLine, newLineBegin);
     141
     142    this->buffer->add(addLine);
     143
     144    if (this->buffer->getSize() > this->bufferSize)
     145    {
     146      delete this->buffer->firstElement();
     147      this->buffer->remove(this->buffer->firstElement());
     148    }
     149
     150    newLineBegin = newLineEnd+1;
     151  }
     152}
     153
     154/**
     155 * moves the buffer around lineCount lines upwards (negative values move down)
     156 * @param lineCount the Count of lines to move upwards
     157 *
     158 * @todo
     159 */
     160void ShellBuffer::moveBuffer(unsigned int lineCount)
     161{
     162}
     163
     164/**
     165 * @param lineNumber the n-th line from the bottom
     166 * @returns the Buffer at Line lineNumber
     167 */
     168const char* ShellBuffer::getBufferLine(unsigned int lineNumber)
     169{
     170  tIterator<char>* charIterator = this->buffer->getIterator();
     171  char* charElem = charIterator->firstElement();
     172
     173  int i = 1;
     174  while (charElem != NULL)
     175  {
     176    if (i++ < lineNumber)
     177    {
     178      delete charIterator;
     179      return charElem;
     180    }
     181
     182    charElem = charIterator->nextElement();
     183  }
     184  delete charIterator;
     185}
Note: See TracChangeset for help on using the changeset viewer.