strigi/src/streams
Strigi::BufferedStream< T > Class Template Reference
#include <bufferedstream.h>

Detailed Description
template<class T>
class Strigi::BufferedStream< T >
Abstract class providing a buffered input stream.
You can inherit this class to provide buffered access to a resource. You just need to implement fillBuffer, and BufferedStream will do the rest.
Definition at line 37 of file bufferedstream.h.
Public Member Functions | |
| int32_t | read (const T *&start, int32_t min, int32_t max) |
| int64_t | reset (int64_t pos) |
| virtual int64_t | skip (int64_t ntoskip) |
Protected Member Functions | |
| BufferedStream () | |
| virtual int32_t | fillBuffer (T *start, int32_t space)=0 |
| void | resetBuffer () |
| void | setMinBufSize (int32_t s) |
Constructor & Destructor Documentation
| Strigi::BufferedStream< T >::BufferedStream | ( | ) | [inline, protected] |
Definition at line 100 of file bufferedstream.h.
Member Function Documentation
| virtual int32_t Strigi::BufferedStream< T >::fillBuffer | ( | T * | start, | |
| int32_t | space | |||
| ) | [protected, pure virtual] |
Fill the buffer with the provided data.
This function should be implemented by subclasses. It should write up to space characters from the stream to the buffer position pointed to by start.
If the end of the stream is encountered, -1 should be returned.
If an error occurs, the status should be set to Error, an error message should be set and -1 should be returned.
You should not call this function yourself.
- Parameters:
-
start where the data should be written to space the maximum amount of data to write
- Returns:
- Number of characters written, or -1 on error
Implemented in Strigi::GZipCompressInputStream, and Strigi::ProcessInputStream.
| int32_t Strigi::BufferedStream< T >::read | ( | const T *& | start, | |
| int32_t | min, | |||
| int32_t | max | |||
| ) | [inline, virtual] |
Reads items from the stream and sets start to point to the first item that was read.
Note: unless stated otherwise in the documentation for that method, this pointer will no longer be valid after calling another method of this class. The pointer will also no longer be valid after the class is destroyed.
The functions inherited from StreamBaseBase do not invalidate the pointer.
At least min items will be read from the stream, unless an error occurs or the end of the stream is reached. Under no circumstances will more than max items be read.
If the end of the stream is reached before min items are read, the read is still considered successful and the number of items read will be returned.
- Parameters:
-
start pointer passed by reference that will be set to point to the retrieved array of items. If the end of the stream is encountered or an error occurs, the value of startis undefinedmin the minimal number of items to read from the stream. This value should be larger than 0. If it is 0 or smaller, the result is undefined max the maximal number of items to read from the stream. If this value is smaller than min, there is no limit on the number of items that can be read
- Returns:
- the number of items that were read.
-1is returned if end of the stream has already been reached.-2is returned if an error has occurred
Implements Strigi::StreamBase< T >.
Definition at line 129 of file bufferedstream.h.
| int64_t Strigi::BufferedStream< T >::reset | ( | int64_t | pos | ) | [inline, virtual] |
Repositions this stream to a given position.
A call to StreamBase::reset is only guaranteed to be successful when the requested position lies within the segment of a stream corresponding to a valid pointer obtained from StreamBase::read. In this case, the pointer will not be invalidated.
Calling this function invalidates the data pointer that was obtained from StreamBase::read unless the conditions outlined above apply.
To read n items, leaving the stream at the same position as before, you can do the following:
int64_t start = stream.position(); if ( stream.read(data, min, max) > 0 ) { stream.reset(start); // The data pointer is still valid here }
- Parameters:
-
pos the position in the stream you want to go to, relative to the start of the stream
- Returns:
- the new position in the stream
Implements Strigi::StreamBase< T >.
Definition at line 165 of file bufferedstream.h.
| void Strigi::BufferedStream< T >::resetBuffer | ( | ) | [inline, protected] |
Resets the buffer, allowing it to be used again.
This function resets the buffer, allowing it to be re-used.
Definition at line 69 of file bufferedstream.h.
| void Strigi::BufferedStream< T >::setMinBufSize | ( | int32_t | s | ) | [inline, protected] |
| int64_t Strigi::BufferedStream< T >::skip | ( | int64_t | ntoskip | ) | [inline, virtual] |
Skip ntoskip items.
If an error occurs, or the end of the stream is encountered, fewer than ntoskip items may be skipped. This can be checked by comparing the return value to ntoskip.
Calling this function invalidates the data pointer that was obtained from StreamBase::read.
- Parameters:
-
ntoskip the number of items that should be skipped
- Returns:
- the number of items skipped
Reimplemented from Strigi::StreamBase< T >.
Definition at line 180 of file bufferedstream.h.
The documentation for this class was generated from the following file:
KDE 4.2 API Reference