Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/shell/shell_buffer.h @ 7315

Last change on this file since 7315 was 7315, checked in by bensch, 18 years ago

orxonox/trunk: more std::string style in the Shell

File size: 2.6 KB
RevLine 
[4838]1/*!
[5173]2 * @file shell_buffer.h
3 * @brief The Shell buffer Tasks
[5246]4 * @see debug.h
[3245]5*/
[1853]6
[5173]7#ifndef _SHELL_BUFFER_H
8#define _SHELL_BUFFER_H
[1853]9
[5173]10#include <stdarg.h>
[5781]11#include <list>
[7314]12#include <SDL_thread.h>
[5173]13
14#define      SHELL_BUFFER_SIZE       16384         //!< The Size of the input-buffers (should be large enough to carry any kind of input)
15
[4838]16// FORWARD DECLARATION
[5206]17class Shell;
[5784]18
[5175]19#ifndef NULL
20#define NULL 0            //!< a pointer to NULL
21#endif
[3543]22
[5246]23//! A class handling output from orxonox via debug.h
[5173]24class ShellBuffer {
[1853]25
[1904]26 public:
[5173]27  virtual ~ShellBuffer();
[5174]28  /** @returns a Pointer to the only object of this Class */
29  inline static ShellBuffer* getInstance() { if (!ShellBuffer::singletonRef) ShellBuffer::singletonRef = new ShellBuffer();  return ShellBuffer::singletonRef; };
[5175]30  /** @returns true if this class is instanciated, false otherwise */
[5176]31  inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?false:true; };
[1853]32
[5206]33  void registerShell(Shell* shell);
34  void unregisterShell(Shell* shell);
35
[5173]36  // BUFFER //
37  /** @param bufferSize the new Buffer-Size */
38  void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; };
[5246]39  void flush();
[5173]40  static bool addBufferLineStatic(const char* line, ...);
41  void addBufferLine(const char* line, va_list arg);
[5246]42  /** @returns the List of stings from the Buffer */
[7315]43  const std::list<std::string>& getBuffer() const { return this->buffer; };
[5246]44 /** @returns the Count of lines processed by the Shell. */
[5176]45  inline long getLineCount() const { return this->lineCount; };
[5173]46
[5177]47  void debug() const;
48
[5174]49  private:
50    ShellBuffer();
[5173]51
[5174]52  private:
[5781]53    static ShellBuffer*      singletonRef;                       //!< The singleton-reference to the only memeber of this class.
54    unsigned int             bufferSize;                         //!< The Size of the buffer
[7315]55    std::list<std::string>   buffer;                             //!< A list of stored char-arrays(strings) to store the history
[5174]56
[5781]57    Shell*                   shell;                              //!< the Registered Shell.
58    char                     bufferArray[SHELL_BUFFER_SIZE];     //!< a BUFFER for fast writing
59    char                     keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell.
60    bool                     keepBuffer;                         //!< if the keepbuffer contains unfinished lines.
[5173]61
[5781]62    unsigned long            lineCount;                          //!< how many Lines have been written out so far.
[7314]63
64    static SDL_mutex*        bufferMutex;                        //!< Only one thread may write into the ShellBuffer at a time.
[1853]65};
66
[5173]67#endif /* _SHELL_BUFFER_H */
Note: See TracBrowser for help on using the repository browser.