| Line | |
|---|
| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: GetLine.h |
|---|
| 5 | // Purpose: Common base class for line based file descriptor reading |
|---|
| 6 | // Created: 2011/04/22 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #ifndef GETLINE__H |
|---|
| 11 | #define GETLINE__H |
|---|
| 12 | |
|---|
| 13 | #include <string> |
|---|
| 14 | |
|---|
| 15 | #ifdef BOX_RELEASE_BUILD |
|---|
| 16 | #define GETLINE_BUFFER_SIZE 1024 |
|---|
| 17 | #elif defined WIN32 |
|---|
| 18 | // need enough space for at least one unicode character |
|---|
| 19 | // in UTF-8 when calling console_read() from bbackupquery |
|---|
| 20 | #define GETLINE_BUFFER_SIZE 5 |
|---|
| 21 | #else |
|---|
| 22 | #define GETLINE_BUFFER_SIZE 4 |
|---|
| 23 | #endif |
|---|
| 24 | |
|---|
| 25 | // Just a very large upper bound for line size to avoid |
|---|
| 26 | // people sending lots of data over sockets and causing memory problems. |
|---|
| 27 | #define GETLINE_MAX_LINE_SIZE (1024*256) |
|---|
| 28 | |
|---|
| 29 | // -------------------------------------------------------------------------- |
|---|
| 30 | // |
|---|
| 31 | // Class |
|---|
| 32 | // Name: GetLine |
|---|
| 33 | // Purpose: Common base class for line based file descriptor reading |
|---|
| 34 | // Created: 2011/04/22 |
|---|
| 35 | // |
|---|
| 36 | // -------------------------------------------------------------------------- |
|---|
| 37 | class GetLine |
|---|
| 38 | { |
|---|
| 39 | protected: |
|---|
| 40 | GetLine(); |
|---|
| 41 | |
|---|
| 42 | private: |
|---|
| 43 | GetLine(const GetLine &rToCopy); |
|---|
| 44 | |
|---|
| 45 | public: |
|---|
| 46 | virtual bool IsEOF() {return mEOF;} |
|---|
| 47 | int GetLineNumber() {return mLineNumber;} |
|---|
| 48 | virtual ~GetLine() { } |
|---|
| 49 | |
|---|
| 50 | protected: |
|---|
| 51 | bool GetLineInternal(std::string &rOutput, |
|---|
| 52 | bool Preprocess = false, |
|---|
| 53 | int Timeout = IOStream::TimeOutInfinite); |
|---|
| 54 | virtual int ReadMore(int Timeout = IOStream::TimeOutInfinite) = 0; |
|---|
| 55 | virtual bool IsStreamDataLeft() = 0; |
|---|
| 56 | |
|---|
| 57 | char mBuffer[GETLINE_BUFFER_SIZE]; |
|---|
| 58 | int mLineNumber; |
|---|
| 59 | int mBufferBegin; |
|---|
| 60 | int mBytesInBuffer; |
|---|
| 61 | bool mPendingEOF; |
|---|
| 62 | std::string mPendingString; |
|---|
| 63 | bool mEOF; |
|---|
| 64 | }; |
|---|
| 65 | |
|---|
| 66 | #endif // GETLINE__H |
|---|
| 67 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.