Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5174 in orxonox.OLD for trunk/src


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)

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/debug.h

    r5076 r5174  
    2727
    2828#include "confincl.h"
    29 #include "shell.h"
     29#include "shell_buffer.h"
    3030
    3131#include <stdio.h>
     
    100100//#ifdef
    101101#define PRINTF(x)        PRINT(x)
    102 #define PRINT_EXEC       Shell::addBufferLineStatic
     102#define PRINT_EXEC       ShellBuffer::addBufferLineStatic
    103103
    104104#ifndef PRINTF
  • trunk/src/lib/shell/shell.cc

    r5173 r5174  
    4343  this->setName("Shell");
    4444
    45   this->keepBufferArray[0] = '\0';
    46   this->keepBuffer = false;
    4745
    4846  this->bActive = false;
    49   this->buffer = new tList<char>;
    5047  this->bufferIterator = this->buffer->getIterator();
    5148
     
    5754
    5855  //this->bufferSize = 0;
    59   this->bufferText = NULL;
    60   this->setBufferSize(10);
    61   this->bufferDisplaySize = 10;
    6256  this->setAbsCoor2D(3, -400);
    6357  this->delayed = 0;
     
    9589  delete this->inputLine;
    9690
    97   // delete all the Chars in the Buffers
     91  // delete all the Strings in the Buffers
    9892  char* charElem = this->bufferIterator->firstElement();
    9993  while (charElem != NULL)
  • trunk/src/lib/shell/shell.h

    r5173 r5174  
    99#include "element_2d.h"
    1010#include "event_listener.h"
    11 #include "shell_buffer.h"
     11//#include "shell_buffer.h"
    1212
    1313#include <stdarg.h>
     14
     15#define      SHELL_BUFFER_SIZE       16384
    1416
    1517// FORWARD DECLARATION
  • 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}
  • trunk/src/lib/shell/shell_buffer.h

    r5173 r5174  
    1414template<class T> class tList;
    1515template<class T> class tIterator;
    16 class Text;
    1716
    1817//! A class for ...
     
    2019
    2120 public:
    22   ShellBuffer();
    2321  virtual ~ShellBuffer();
    24 
     22  /** @returns a Pointer to the only object of this Class */
     23  inline static ShellBuffer* getInstance() { if (!ShellBuffer::singletonRef) ShellBuffer::singletonRef = new ShellBuffer();  return ShellBuffer::singletonRef; };
    2524
    2625  // BUFFER //
    2726  /** @param bufferSize the new Buffer-Size */
    2827  void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; };
    29   void setBufferDisplaySize(unsigned int bufferDisplaySize);
    3028  void flushBuffers();
    3129  static bool addBufferLineStatic(const char* line, ...);
    3230  void addBufferLine(const char* line, va_list arg);
    33   void printToDisplayBuffer(const char* text);
    3431  void moveBuffer(unsigned int lineCount);
    3532//    void moveBufferTo(unsigned int lineNumber);
    3633  const char* getBufferLine(unsigned int lineNumber);
    3734
     35  private:
     36    ShellBuffer();
    3837
    39  private:
    40    unsigned int             bufferSize;             //!< The Size of the buffer
    41    unsigned int             bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters)
    42    tList<char>*             buffer;                 //!< A list of stored char-arrays(strings) to store the history
    43    tIterator<char>*         bufferIterator;         //!< An iterator for the Shells main buffer.
    4438
    45    Text**                   bufferText;             //!< A list of stored bufferTexts for the display of the buffer
     39  private:
     40   static ShellBuffer*      singletonRef;                       //!< The singleton-reference to the only memeber of this class.
     41   unsigned int             bufferSize;                         //!< The Size of the buffer
     42   tList<char>*             buffer;                             //!< A list of stored char-arrays(strings) to store the history
     43   tIterator<char>*         bufferIterator;                     //!< An iterator for the Shells main buffer.
     44
    4645   char                     bufferArray[SHELL_BUFFER_SIZE];     //!< a BUFFER for fast writing
    4746   char                     keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell.
    48    bool                     keepBuffer;             //!< if the keepbuffer contains unfinished lines.
     47   bool                     keepBuffer;                         //!< if the keepbuffer contains unfinished lines.
    4948
     49   unsigned long            lineCount;                          //!< how many Lines have been written out so far.
    5050};
    5151
  • trunk/src/lib/shell/shell_command.cc

    r5172 r5174  
    2525#include <stdarg.h>
    2626#include <stdio.h>
     27#include <string.h>
    2728
    2829using namespace std;
  • trunk/src/story_entities/world.cc

    r5117 r5174  
    3939#include "text_engine.h"
    4040#include "load_param.h"
     41#include "shell.h"
    4142
    4243#include "track_manager.h"
     
    115116World::~World ()
    116117{
    117   delete Shell::getInstance();
     118  delete ShellBuffer::getInstance();
    118119  PRINTF(3)("World::~World() - deleting current world\n");
    119120
     
    195196
    196197  /* init the world interface */
    197   Shell::getInstance();
     198  ShellBuffer::getInstance();
    198199
    199200  LightManager::getInstance();
Note: See TracChangeset for help on using the changeset viewer.