Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: the Buffer is moving pretty smoothly :)

File size: 2.8 KB
Line 
1/*!
2 * @file shell_buffer.h
3 * @brief The Shell buffer Tasks
4 * @see debug.h
5*/
6
7#ifndef _SHELL_BUFFER_H
8#define _SHELL_BUFFER_H
9
10#include <list>
11
12#define      SHELL_BUFFER_SIZE       16384         //!< The Size of the input-buffers (should be large enough to carry any kind of input)
13
14namespace OrxShell
15{
16  // FORWARD DECLARATION
17  class Shell;
18
19  //! A class handling output from orxonox via debug.h
20  /**
21   * the ShellBuffer redirects output from PRINTF(x) to the Shell and STDOUT
22   * the ShellBuffer is a front-filling queue of limited length, that has the
23   * youngest added Entry at the beginning, and the oldest at the end.
24   */
25  class ShellBuffer
26  {
27
28  public:
29    virtual ~ShellBuffer();
30    /** @returns a Pointer to the only object of this Class */
31    inline static ShellBuffer* getInstance() { if (!ShellBuffer::singletonRef) ShellBuffer::singletonRef = new ShellBuffer();  return ShellBuffer::singletonRef; };
32    /** @returns true if this class is instanciated, false otherwise */
33    inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?false:true; };
34
35    void registerShell(Shell* shell);
36    void unregisterShell(Shell* shell);
37
38    static bool addBufferLineStatic(const char* line, ...);
39    void addBufferLine(const char* line, va_list arg);
40
41    // BUFFER //
42    /** @param bufferSize the new Buffer-Size */
43    void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; };
44    void flush();
45
46    /** @returns the List of stings from the Buffer */
47    const std::list<std::string>& getBuffer() const { return this->buffer; };
48    /** @returns the Count of lines processed by the Shell. */
49    inline unsigned long getLineCount() const { return this->lineCount; };
50
51    void debug() const;
52
53  private:
54    ShellBuffer();
55
56  private:
57    static ShellBuffer*           singletonRef;                       //!< The singleton-reference to the only memeber of this class.
58    unsigned int                  bufferSize;                         //!< The Size of the buffer
59
60    Shell*                        shell;                              //!< the Registered Shell.
61    char                          bufferArray[SHELL_BUFFER_SIZE];     //!< a BUFFER for fast writing
62    char                          keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell.
63    bool                          keepBuffer;                         //!< if the keepbuffer contains unfinished lines.
64
65    unsigned long                 lineCount;                          //!< how many Lines have been written out so far.
66
67    // The Beginning of buffer (buffer.front()) is the last added line.
68    static std::list<std::string> buffer;                             //!< A list of stored char-arrays(strings) to store the history
69  };
70
71}
72
73#endif /* _SHELL_BUFFER_H */
Note: See TracBrowser for help on using the repository browser.