DD::Image::FileReader Class Reference

Inherits DD::Image::Reader.

List of all members.

Public Member Functions

 FileReader (Read *, int fd, const unsigned char *buffer, FILE_OFFSET buflength)
 ~FileReader ()
int lock (FILE_OFFSET offset, int min_length, int length)
int lock (FILE_OFFSET offset, int l)
int lock (FILE_OFFSET offset, unsigned l)
const unsigned char & byte (FILE_OFFSET n) const
const unsigned char * at (FILE_OFFSET n) const
void unlock ()
int read (void *p, FILE_OFFSET offset, int min_, int max_)
int read (void *p, FILE_OFFSET offset, int l)
int read (void *p, FILE_OFFSET offset, unsigned l)
bool readAllLinesRequested () const

Related Functions

(Note that these are not member functions.)
typedef unsigned long FILE_OFFSET

Detailed Description

Reader subclass to read Unix files. This Reader subclass will read Unix files as blocks of memory and tries to be somewhat multi-threaded and have as little overhead as possible. This is used by most of the file formats.


Constructor & Destructor Documentation

FileReader::FileReader ( Read i,
int  fd,
const unsigned char *  buffer,
FILE_OFFSET  buflength 
)

The constructor takes the block of memory already read by Read and preserves it.

FileReader::~FileReader ( )

The destructor closes the file.


Member Function Documentation

int FileReader::lock ( FILE_OFFSET  offset,
int  min_length,
int  length 
)

lock() makes byte(n) work for any value between offset and offset+length. All bytes between the last one in the file and length are set to zero. If less than min_length bytes are available it produces an error. You must call unlock exactly once to free the block (and cannot call lock() again until then).

References DD::Image::Reader::filename(), DD::Image::Lock::lock(), DD::Image::Lock::unlock(), and DD::Image::SignalLock::wait().

int DD::Image::FileReader::lock ( FILE_OFFSET  offset,
int  l 
) [inline]

Same as lock(offset,l,l), the minimum length needed to produce an error is equal to the maximum length.

References lock().

Referenced by lock().

int DD::Image::FileReader::lock ( FILE_OFFSET  offset,
unsigned  l 
) [inline]

Same as lock(offset, int(l)) to avoid type warnings for code that uses unsigned values as offsets into the file.

References lock().

Referenced by lock().

const unsigned char & DD::Image::FileReader::byte ( FILE_OFFSET  n) const [inline]

After calling lock() you can access any byte in the locked range by calling this fast inline function. Attempts to access bytes outside the currently lock()'ed range will return garbage.

To get 16-bit unsigned quantities, use msb16(at(n)) or lsb16(at(n)). To get 32-bit unsigned quantities use msb32(at(n)) or lsb32(at(n)).

const unsigned char * DD::Image::FileReader::at ( FILE_OFFSET  n) const [inline]

Return a pointer to an object in the locked region. This will work as long as you know the object does not cross a "page boundary", in the current version these pages are 32K in size.

void FileReader::unlock ( )

Call this when you are done using byte() to call a locked region of the file. This will allow this or other threads to lock a different region.

References DD::Image::Lock::lock(), DD::Image::SignalLock::signal(), and DD::Image::Lock::unlock().

int FileReader::read ( void *  p,
FILE_OFFSET  offset,
int  min_,
int  max_ 
)

Read directly from the file into some memory of your own. If less than length bytes are available the block is padded with zero. The number of bytes read (0 if there is an error) is returned. If less than min_length are available it produces an error.

References DD::Image::Lock::lock(), and DD::Image::Lock::unlock().

int DD::Image::FileReader::read ( void *  p,
FILE_OFFSET  offset,
int  l 
) [inline]

Same as read(p,offset,l,l), the minimum length needed to produce an error is equal to the maximum length.

References read().

Referenced by read().

int DD::Image::FileReader::read ( void *  p,
FILE_OFFSET  offset,
unsigned  l 
) [inline]

Same as read(p,offset,int(l)) to avoid type warnings for code that uses unsigned values as offsets into the file.

References read().

Referenced by read().

bool FileReader::readAllLinesRequested ( ) const

Whether reading all lines (as opposed to reading individual scanlines) has been requested. For performance reasons, it is sometimes preferable to read from the input file in larger chunks. When this function returns true, the user has indicated that they would prefer to read all of the requested lines from the file in one go. It's then up to the individual FileReader whether it chooses to obey this request or not.

References DD::Image::Op::outputContext().


Friends And Related Function Documentation

typedef unsigned long FILE_OFFSET [related]

This type may need to be replaced on 64-bit file systems.