UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
TapeReader Class Reference

#include <TapeReader.hpp>

Public Types

enum  ReadStatus {
  Normal, EndOfBlock, EndOfFile, EndOfTape,
  ReadError
}
 

Public Member Functions

 TapeReader (const char *szPath, int nSize=TapeReaderBlockSize)
 
virtual ~TapeReader ()
 
int read (ReadStatus &status, void *buffer, int req_size=0)
 
void undo_read (void *buffer, int undo_size)
 
void set_block_mode (bool bFlag)
 
bool get_block_mode () const
 
int get_max_block_size () const
 
void set_max_errors (int nErrors)
 
int get_max_errors () const
 
bool is_tape () const
 

Protected Member Functions

int read (void *buf, int req_size)
 

Static Protected Member Functions

static int open (const char *szPath, bool &bTape)
 

Protected Attributes

int fdTape
 
bool bBlockMode
 
bool bTapeDevice
 
ReadStatus ePrevStatus
 
int nMaxBlockSize
 
int nMaxErrors
 
char * pBlockBuffer
 
int nDataOffset
 
int nDataSize
 

Detailed Description

Object for reading the tape or several files.

Member Enumeration Documentation

Enumerator
Normal 

All data are in buffer.

EndOfBlock 

End of block is reached, so actual data are shorter than expected.

EndOfFile 

Data are absent since end of tape file is reached.

EndOfTape 

Data are absent since end to end of tape is reached.

ReadError 

Data are absent due to error.

Constructor & Destructor Documentation

TapeReader::TapeReader ( const char *  szPath,
int  nSize = TapeReaderBlockSize 
)

Create object for reading given tape (or other medium). Maximum block size is set here for tape devices too (64K by default).

In case of disk file reading szPath is a mask like /path/A*B for matching all files "AaB", "A12B", "AabcB" etc in directory /path. Each file is supposed to be equivalent to tape file. Block boundary is not detected. Buffer size is allocated to the maximum size among matched files. Unique subpart of filename of the current file can be accessed via file_signature().

virtual TapeReader::~TapeReader ( )
virtual

Destroy the object and release all catched resources.

Member Function Documentation

bool TapeReader::get_block_mode ( ) const

Get block mode flag. True means reading is performed by blocks. False means no EndOfBlock status will be ever returned by read() method.

int TapeReader::get_max_block_size ( ) const

Get maximum tape block size in bytes.

int TapeReader::get_max_errors ( ) const

Get maximum number of reading errors.

bool TapeReader::is_tape ( ) const

Get the tape device flag. True in case of tape device and false in case of other (normal) file.

static int TapeReader::open ( const char *  szPath,
bool &  bTape 
)
staticprotected

Open the tape or other medium and return file descriptor. bTape contains whether file is tape (character oriented device) or other type. 'static' since the method does not use and touch internal object state.

int TapeReader::read ( ReadStatus status,
void *  buffer,
int  req_size = 0 
)

Read requested number of bytes inside the block (in case of block mode is on). Actual number of bytes in data buffer is returned.

int TapeReader::read ( void *  buf,
int  req_size 
)
protected

Read needed number of bytes from file. Tries to read several times in case of tape. Returns number of actually bytes read or error hint (-1). errno contains error code as usual.

void TapeReader::set_block_mode ( bool  bFlag)

Set block mode flag. True means reading is performed by blocks. False means no EndOfBlock status will be ever returned by read() method.

void TapeReader::set_max_errors ( int  nErrors)

Setup maximum number of reading errors until ReadError will be returned.

void TapeReader::undo_read ( void *  buffer,
int  undo_size 
)

Put given bytes back to read buffer. Number of bytes should be less than size of internal block.

Member Data Documentation

bool TapeReader::bBlockMode
protected

Block mode flag.

bool TapeReader::bTapeDevice
protected

Tape device flag.

ReadStatus TapeReader::ePrevStatus
protected

Previous actual device read status.

int TapeReader::fdTape
protected

File descriptor of opened tape

int TapeReader::nDataOffset
protected

Offset to unread data bytes in the buffer.

int TapeReader::nDataSize
protected

Actual number of bytes in the buffer.

int TapeReader::nMaxBlockSize
protected

Maximum length of tape record.

int TapeReader::nMaxErrors
protected

Maximum allowed number of read errors.

char* TapeReader::pBlockBuffer
protected

Preallocated buffer for the most long tape record.


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