SpectMorph
Public Member Functions | Static Public Member Functions | List of all members
SpectMorph::GenericIn Class Referenceabstract

Generic Input Stream. More...

#include <smgenericin.hh>

Inheritance diagram for SpectMorph::GenericIn:
SpectMorph::MMapIn SpectMorph::StdioIn SpectMorph::StdioSubIn

Public Member Functions

virtual int get_byte ()=0
 
virtual int read (void *ptr, size_t size)=0
 
virtual bool skip (size_t size)=0
 
virtual size_t get_pos ()=0
 
virtual unsigned char * mmap_mem (size_t &remaining)=0
 
virtual GenericInopen_subfile (size_t pos, size_t len)=0
 

Static Public Member Functions

static GenericInopen (const std::string &filename)
 

Detailed Description

Generic Input Stream.

This class is the abstract base class for different (binary) input streams like "from memory", "from file", ...

Member Function Documentation

virtual int SpectMorph::GenericIn::get_byte ( )
pure virtual

Reads one byte from the input stream.

Returns
the byte if successful, or EOF on end of file

Implemented in SpectMorph::MMapIn, SpectMorph::StdioSubIn, and SpectMorph::StdioIn.

virtual size_t SpectMorph::GenericIn::get_pos ( )
pure virtual

Get input stream position.

Returns
the position in the input stream

Implemented in SpectMorph::MMapIn, SpectMorph::StdioSubIn, and SpectMorph::StdioIn.

virtual unsigned char* SpectMorph::GenericIn::mmap_mem ( size_t &  remaining)
pure virtual

Try to access the memory of a memory-based input stream. This will fail for streams that are not memory mapped. This function is useful because it allows writing faster code than with read(); however, an alternative way of reading the data must be used if this function fails.

Parameters
remainingis set to the number to the number of bytes that are available
Returns
pointer to the memory, or NULL if input is not memory mapped

Implemented in SpectMorph::MMapIn, SpectMorph::StdioSubIn, and SpectMorph::StdioIn.

GenericIn * GenericIn::open ( const std::string &  filename)
static

Open a file for reading, using memory mapping if possible, stdio based reading otherwise.

Returns
the newly created GenericIn object, or NULL on error
virtual GenericIn* SpectMorph::GenericIn::open_subfile ( size_t  pos,
size_t  len 
)
pure virtual

Open a new input stream that contains a part of the original file.

Parameters
posstart position in the input stream (offset like get_pos())
lenlength of the new subfile object
Returns
a GenericIn object with the subfile or NULL on error (open failed)

Implemented in SpectMorph::MMapIn, SpectMorph::StdioSubIn, and SpectMorph::StdioIn.

virtual int SpectMorph::GenericIn::read ( void *  ptr,
size_t  size 
)
pure virtual

Reads a block of binary input data.

Parameters
ptrpointer to the buffer for the data read
sizenumber of bytes to be read
Returns
the number of bytes successfully read or 0; can be less than size on EOF/error

Implemented in SpectMorph::MMapIn, SpectMorph::StdioSubIn, and SpectMorph::StdioIn.

virtual bool SpectMorph::GenericIn::skip ( size_t  size)
pure virtual

Skips a block of input data.

Parameters
sizenumber of bytes to be skipped
Returns
true if the number of bytes was available and could be skipped, false otherwise

Implemented in SpectMorph::MMapIn, SpectMorph::StdioSubIn, and SpectMorph::StdioIn.


The documentation for this class was generated from the following files: