Logo Search packages:      
Sourcecode: djvulibre version File versions  Download package

int ByteStream::Memory::seek ( long  offset,
int  whence = SEEK_SET,
bool  nothrow = false 
) [virtual]

Sets the current position for reading or writing the ByteStream. Class ByteStream# provides a default implementation able to seek forward by calling function read# until reaching the desired position. Subclasses implementing better seek capabilities must override this default implementation. The new current position is computed by applying displacement offset# to the position represented by argument whence#. The following values are recognized for argument whence#: {description} [SEEK_SET#] Argument offset# indicates the position relative to the beginning of the ByteStream. [SEEK_CUR#] Argument offset# is a signed displacement relative to the current position. [SEEK_END#] Argument offset# is a displacement relative to the end of the file. It is then advisable to provide a negative value for offset#. {description} Results are undefined whenever the new position is greater than the total size of the ByteStream.

{ Error reporting}: If seek()# succeeds, #0# is returned. Otherwise it either returns #-1# (if nothrow# is set to FALSE#) or throws the {GException} exception.

Reimplemented from ByteStream.

Definition at line 909 of file ByteStream.cpp.

  int nwhere = 0;
  switch (whence)
    case SEEK_SET: nwhere = 0; break;
    case SEEK_CUR: nwhere = where; break;
    case SEEK_END: nwhere = bsize; break;
    default: G_THROW( ERR_MSG("bad_arg") "\tByteStream::Memory::seek()");      // Illegal argument in ByteStream::Memory::seek()
  nwhere += offset;
  if (nwhere<0)
    G_THROW( ERR_MSG("ByteStream.seek_error2") );                          //  Attempt to seek before the beginning of the file
  where = nwhere;
  return 0;

Generated by  Doxygen 1.6.0   Back to index