JASSv2
|
Read data from an input stream. More...
#include <instream.h>
Public Member Functions | |
instream (allocator *memory=nullptr, instream *source=nullptr) | |
Constructor. More... | |
virtual | ~instream () |
Destructor. More... | |
virtual void | read (document &buffer)=0 |
Read at most buffer.contents.size() bytes of data into buffer, resizing on eof. More... | |
size_t | fetch (void *buffer, size_t bytes) |
fetch() generates a document object, sets its contents to the passed buffer, calls read() and returns the number of bytes of data read More... | |
Protected Attributes | |
allocator * | memory |
Any and all memory allocation must happen using this object. | |
instream * | source |
If this object is reading from another instream then this is that instream. | |
Read data from an input stream.
This is the abstract base class for reading data from an input source. If the indexer, for example, needs to read from a file then an instance of a subclass of this class can be used and once created the user need not know where the data is coming from. Its an abstraction over input streams of a generic interface to get data.
There are two "kinds" of these objects. Ones that read from a stream such as a file, and ones that generate documents ready for indexing. They share the same interface so that its possible to chain them together to form pipelines such as read_file | de-zip | de-tar | index.
The constructor of a complex pipeline does not want to keep track of each and every pointer to parts of the stream - and to free them on competion so this object deletes the predecessor in the pipeline if deleted. This propegates down the pipeline which is eventially cleaned up bottom up.
An example tying documents, instreams, and parsing to count the number of document and non-unique symbols is:
Constructor.
memory | [in] If this object needs to allocate memory (for example, a buffer) then it should be allocated from this pool. |
source | [in] This object reads data from source before processing and passingin via read(). |
|
inlinevirtual |
Destructor.
This destructor not only cleans up this object but also any object that is earlier in the pipeline - so a deletion of the root of the pipeline will delete the entire pipeline.
|
inline |
|
pure virtual |
Read at most buffer.contents.size() bytes of data into buffer, resizing on eof.
buffer | [out] buffer.contents.size() bytes of data are read from source into buffer which is resized to the number of bytes read. |
Implemented in JASS::instream_document_trec, JASS::instream_file, and JASS::instream_memory.