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

void file_output_buffer::write ( const void *  data,
int  nbytes 
) [virtual]

The write method is used to write data to the output stream.

Parameters:
data This argument points to a data structure to be written. Usually an array of bytes.
nbytes This argument indicates the number fo bytes to be written.

Implements file_output.

Definition at line 61 of file buffer.cc.

References blocksize, buffer, deeper, pos, and file_output::write().

{
    while (nbytes > 0)
    {
      //
      // Don't double handle the data if we can avoid it.
      // (But only write `blocksize' bytes at a time.)
      //
      if (pos == 0 && nbytes >= blocksize)
      {
          deeper->write(data, blocksize);
          data = (char *)data + blocksize;
          nbytes -= blocksize;
          continue;
      }

      //
      // Add the data to the end of the buffer.
      //
      int len = blocksize - pos;
      if (len > nbytes)
          len = nbytes;
      if (!buffer)
          buffer = new char[blocksize];
      memcpy(buffer + pos, data, len);
      pos += len;
      if (pos >= blocksize)
      {
          //
          // If the buffer is full,
          // write it out and start again.
          //
          deeper->write(buffer, pos);
          pos = 0;
      }
      data = (char *)data + len;
      nbytes -= len;
    }
}


Generated by  Doxygen 1.6.0   Back to index