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

Detailed Description
template<class T>
class Strigi::StreamBase< T >
Base class for stream read access to a data source.
This class is based on the interface java.io.InputStream. It provides a uniform interface for accessing streamed resources.
The main difference with the Java equivalent is a performance improvement. When reading data, data is not copied into a buffer provided by the caller, but a pointer to the read data is provided. This makes this interface especially useful for deriving from it and implementing filters or transformers.
Definition at line 114 of file streambase.h.
Public Member Functions | |
| virtual int32_t | read (const T *&start, int32_t min, int32_t max)=0 |
| virtual int64_t | reset (int64_t pos)=0 |
| virtual int64_t | skip (int64_t ntoskip) |
| StreamBase () | |
| virtual | ~StreamBase () |
Constructor & Destructor Documentation
| Strigi::StreamBase< T >::StreamBase | ( | ) | [inline] |
Definition at line 116 of file streambase.h.
| virtual Strigi::StreamBase< T >::~StreamBase | ( | ) | [inline, virtual] |
Definition at line 117 of file streambase.h.
Member Function Documentation
| virtual int32_t Strigi::StreamBase< T >::read | ( | const T *& | start, | |
| int32_t | min, | |||
| int32_t | max | |||
| ) | [pure 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
Implemented in Strigi::BufferedStream< T >, Strigi::DataEventInputStream, Strigi::FileReader, Strigi::StringStream< T >, Strigi::StringTerminatedSubStream, Strigi::SubInputStream, Strigi::BufferedStream< wchar_t >, and Strigi::BufferedStream< char >.
| virtual int64_t Strigi::StreamBase< T >::reset | ( | int64_t | pos | ) | [pure 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
Implemented in Strigi::BufferedStream< T >, Strigi::DataEventInputStream, Strigi::FileReader, Strigi::StringStream< T >, Strigi::StringTerminatedSubStream, Strigi::SubInputStream, Strigi::BufferedStream< wchar_t >, and Strigi::BufferedStream< char >.
| int64_t Strigi::StreamBase< 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 in Strigi::BufferedStream< T >, Strigi::DataEventInputStream, Strigi::StringStream< T >, Strigi::SubInputStream, Strigi::BufferedStream< wchar_t >, and Strigi::BufferedStream< char >.
Definition at line 204 of file streambase.h.
The documentation for this class was generated from the following file:
KDE 4.2 API Reference