| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: IOStreamGetLine.h |
|---|
| 5 | // Purpose: Line based file descriptor reading |
|---|
| 6 | // Created: 2003/07/24 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #ifndef IOSTREAMGETLINE__H |
|---|
| 11 | #define IOSTREAMGETLINE__H |
|---|
| 12 | |
|---|
| 13 | #include <string> |
|---|
| 14 | |
|---|
| 15 | #include "GetLine.h" |
|---|
| 16 | #include "IOStream.h" |
|---|
| 17 | |
|---|
| 18 | // -------------------------------------------------------------------------- |
|---|
| 19 | // |
|---|
| 20 | // Class |
|---|
| 21 | // Name: IOStreamGetLine |
|---|
| 22 | // Purpose: Line based stream reading |
|---|
| 23 | // Created: 2003/07/24 |
|---|
| 24 | // |
|---|
| 25 | // -------------------------------------------------------------------------- |
|---|
| 26 | class IOStreamGetLine : public GetLine |
|---|
| 27 | { |
|---|
| 28 | public: |
|---|
| 29 | IOStreamGetLine(IOStream &Stream); |
|---|
| 30 | virtual ~IOStreamGetLine(); |
|---|
| 31 | private: |
|---|
| 32 | IOStreamGetLine(const IOStreamGetLine &rToCopy); |
|---|
| 33 | |
|---|
| 34 | public: |
|---|
| 35 | bool GetLine(std::string &rOutput, bool Preprocess = false, int Timeout = IOStream::TimeOutInfinite); |
|---|
| 36 | |
|---|
| 37 | // Call to detach, setting file pointer correctly to last bit read. |
|---|
| 38 | // Only works for lseek-able file descriptors. |
|---|
| 39 | void DetachFile(); |
|---|
| 40 | |
|---|
| 41 | virtual bool IsStreamDataLeft() |
|---|
| 42 | { |
|---|
| 43 | return mrStream.StreamDataLeft(); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | // For doing interesting stuff with the remaining data... |
|---|
| 47 | // Be careful with this! |
|---|
| 48 | const void *GetBufferedData() const {return mBuffer + mBufferBegin;} |
|---|
| 49 | int GetSizeOfBufferedData() const {return mBytesInBuffer - mBufferBegin;} |
|---|
| 50 | void IgnoreBufferedData(int BytesToIgnore); |
|---|
| 51 | IOStream &GetUnderlyingStream() {return mrStream;} |
|---|
| 52 | |
|---|
| 53 | protected: |
|---|
| 54 | int ReadMore(int Timeout = IOStream::TimeOutInfinite); |
|---|
| 55 | |
|---|
| 56 | private: |
|---|
| 57 | IOStream &mrStream; |
|---|
| 58 | }; |
|---|
| 59 | |
|---|
| 60 | #endif // IOSTREAMGETLINE__H |
|---|
| 61 | |
|---|