| [4838] | 1 | /*! | 
|---|
| [5173] | 2 | * @file shell_buffer.h | 
|---|
|  | 3 | * @brief The Shell buffer Tasks | 
|---|
| [3245] | 4 | */ | 
|---|
| [1853] | 5 |  | 
|---|
| [5173] | 6 | #ifndef _SHELL_BUFFER_H | 
|---|
|  | 7 | #define _SHELL_BUFFER_H | 
|---|
| [1853] | 8 |  | 
|---|
| [5173] | 9 | #include <stdarg.h> | 
|---|
|  | 10 |  | 
|---|
|  | 11 | #define      SHELL_BUFFER_SIZE       16384         //!< The Size of the input-buffers (should be large enough to carry any kind of input) | 
|---|
|  | 12 |  | 
|---|
| [4838] | 13 | // FORWARD DECLARATION | 
|---|
| [5173] | 14 | template<class T> class tList; | 
|---|
|  | 15 | template<class T> class tIterator; | 
|---|
| [5175] | 16 | #ifndef NULL | 
|---|
|  | 17 | #define NULL 0            //!< a pointer to NULL | 
|---|
|  | 18 | #endif | 
|---|
| [3543] | 19 |  | 
|---|
| [3955] | 20 | //! A class for ... | 
|---|
| [5173] | 21 | class ShellBuffer { | 
|---|
| [1853] | 22 |  | 
|---|
| [1904] | 23 | public: | 
|---|
| [5173] | 24 | virtual ~ShellBuffer(); | 
|---|
| [5174] | 25 | /** @returns a Pointer to the only object of this Class */ | 
|---|
|  | 26 | inline static ShellBuffer* getInstance() { if (!ShellBuffer::singletonRef) ShellBuffer::singletonRef = new ShellBuffer();  return ShellBuffer::singletonRef; }; | 
|---|
| [5175] | 27 | /** @returns true if this class is instanciated, false otherwise */ | 
|---|
| [5176] | 28 | inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?false:true; }; | 
|---|
| [1853] | 29 |  | 
|---|
| [5173] | 30 | // BUFFER // | 
|---|
|  | 31 | /** @param bufferSize the new Buffer-Size */ | 
|---|
|  | 32 | void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; | 
|---|
|  | 33 | void flushBuffers(); | 
|---|
|  | 34 | static bool addBufferLineStatic(const char* line, ...); | 
|---|
|  | 35 | void addBufferLine(const char* line, va_list arg); | 
|---|
|  | 36 | void moveBuffer(unsigned int lineCount); | 
|---|
| [5175] | 37 | // void moveBufferTo(unsigned int lineNumber); | 
|---|
| [5173] | 38 | const char* getBufferLine(unsigned int lineNumber); | 
|---|
| [5176] | 39 | /** @returns the Buffer Iterator, that enables externals to walk through the Buffer */ | 
|---|
|  | 40 | inline tIterator<char>* getBufferIterator() const { return bufferIterator; }; | 
|---|
| [5177] | 41 | /** @returns the Count of lines processed by the Shell. */ | 
|---|
| [5176] | 42 | inline long getLineCount() const { return this->lineCount; }; | 
|---|
| [5173] | 43 |  | 
|---|
| [5177] | 44 | void debug() const; | 
|---|
|  | 45 |  | 
|---|
| [5174] | 46 | private: | 
|---|
|  | 47 | ShellBuffer(); | 
|---|
| [5173] | 48 |  | 
|---|
| [3245] | 49 |  | 
|---|
| [5174] | 50 | private: | 
|---|
|  | 51 | static ShellBuffer*      singletonRef;                       //!< The singleton-reference to the only memeber of this class. | 
|---|
|  | 52 | unsigned int             bufferSize;                         //!< The Size of the buffer | 
|---|
|  | 53 | tList<char>*             buffer;                             //!< A list of stored char-arrays(strings) to store the history | 
|---|
|  | 54 | tIterator<char>*         bufferIterator;                     //!< An iterator for the Shells main buffer. | 
|---|
|  | 55 |  | 
|---|
| [5173] | 56 | char                     bufferArray[SHELL_BUFFER_SIZE];     //!< a BUFFER for fast writing | 
|---|
|  | 57 | char                     keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell. | 
|---|
| [5174] | 58 | bool                     keepBuffer;                         //!< if the keepbuffer contains unfinished lines. | 
|---|
| [5173] | 59 |  | 
|---|
| [5174] | 60 | unsigned long            lineCount;                          //!< how many Lines have been written out so far. | 
|---|
| [1853] | 61 | }; | 
|---|
|  | 62 |  | 
|---|
| [5173] | 63 | #endif /* _SHELL_BUFFER_H */ | 
|---|