Vault  4.1
Public Member Functions | Static Public Member Functions | Protected Attributes
VIOStream Class Reference

VIOStream is an abstract base class from which classes derive that perform well-typed I/O on raw streams. More...

#include <viostream.h>

Inheritance diagram for VIOStream:
VBinaryIOStream VTextIOStream VMessage

List of all members.

Public Member Functions

 VIOStream (VStream &rawStream)
 Constructs the object with an underlying raw stream.
virtual ~VIOStream ()
 Destructor.
void readGuaranteed (Vu8 *targetBuffer, Vs64 numBytesToRead)
 Reads a specified number of bytes from the stream, and throws a VException if they cannot be read.
Vu8 readGuaranteedByte ()
 Reads one byte from the stream, and throws a VException if it cannot be read.
Vs64 read (Vu8 *targetBuffer, Vs64 numBytesToRead)
 Attempts to read a specified number of bytes from the stream.
Vs64 write (const Vu8 *buffer, Vs64 numBytesToWrite)
 Writes bytes to the stream.
void flush ()
 Flushes any pending or buffered write data to the stream.
bool skip (Vs64 numBytesToSkip)
 Skips forward in the stream a specified number of bytes.
bool seek (Vs64 offset, int whence)
 Seeks in the stream using Unix seek() semantics.
bool seek0 ()
 This is a convenience function that means seek(0, SEEK_SET).
Vs64 getIOOffset () const
 Returns the "current" "offset" in the stream.
Vs64 available () const
 Returns the number of bytes that are available to be read from this stream.
VStreamgetRawStream ()
 Returns a reference to the underlying raw stream; used by the friend function streamCopy() so it can call through to the corresponding VStream friend function and supply it the raw streams.

Static Public Member Functions

static Vs16 streamCompare (VIOStream &streamA, VIOStream &streamB, Vs64 numBytesToCompare)
 Compare 2 streams by ascii values.

Protected Attributes

VStreammRawStream
 The underlying raw stream.

Detailed Description

VIOStream is an abstract base class from which classes derive that perform well-typed I/O on raw streams.

This base class merely delegates its methods to the underlying raw stream. Subclasses provide well-typed read and write APIs that call the base class methods. So you will typically not instantiate a VIOStream (there is no point to doing so!) and will instead instantiate a VBinaryIOStream or a VTextIOStream.

See also:
VBinaryIOStream
VTextIOStream

Definition at line 43 of file viostream.h.


Constructor & Destructor Documentation

VIOStream::VIOStream ( VStream rawStream)

Constructs the object with an underlying raw stream.

Parameters:
rawStreamthe raw stream on which I/O will be performed

Definition at line 14 of file viostream.cpp.


Member Function Documentation

void VIOStream::readGuaranteed ( Vu8 targetBuffer,
Vs64  numBytesToRead 
)

Reads a specified number of bytes from the stream, and throws a VException if they cannot be read.

Parameters:
targetBufferthe buffer to read into
numBytesToReadthe number of bytes to read

Definition at line 19 of file viostream.cpp.

References mRawStream, and VStream::readGuaranteed().

Vu8 VIOStream::readGuaranteedByte ( )

Reads one byte from the stream, and throws a VException if it cannot be read.

Returns:
the byte that was read

Definition at line 23 of file viostream.cpp.

References mRawStream, and VStream::readGuaranteedByte().

Vs64 VIOStream::read ( Vu8 targetBuffer,
Vs64  numBytesToRead 
)

Attempts to read a specified number of bytes from the stream.

Parameters:
targetBufferthe buffer to read into
numBytesToReadthe number of bytes to read
Returns:
the actual number of bytes that could be read

Definition at line 27 of file viostream.cpp.

References mRawStream, and VStream::read().

Vs64 VIOStream::write ( const Vu8 buffer,
Vs64  numBytesToWrite 
)

Writes bytes to the stream.

Parameters:
bufferthe buffer containing the data
numBytesToWritethe number of bytes to write to the stream
Returns:
the actual number of bytes written

Definition at line 31 of file viostream.cpp.

References mRawStream, and VStream::write().

void VIOStream::flush ( )

Flushes any pending or buffered write data to the stream.

Until you call flush, you cannot guarantee that your data has actually been written to the underlying physical stream.

Definition at line 35 of file viostream.cpp.

References VStream::flush(), and mRawStream.

bool VIOStream::skip ( Vs64  numBytesToSkip)

Skips forward in the stream a specified number of bytes.

For memory and file streams, this means advancing the i/o offset by the specified number of bytes; for socket streams, this means reading and discarding the specified number of bytes.

Parameters:
numBytesToSkipthe number of bytes to skip

Definition at line 39 of file viostream.cpp.

References mRawStream, and VStream::skip().

bool VIOStream::seek ( Vs64  offset,
int  whence 
)

Seeks in the stream using Unix seek() semantics.

VSocketStream has some restrictions in the kinds of seek that are allowed; if you specify an illegal socket seek operation, a VException is thrown.

The following table shows the valid seek parameters for the different stream types:

  SEEK_SET SEEK_CUR offset>=0 SEEK_CUR offset<0 SEEK_END
VMemoryStream yes yes yes yes
VAbstractFileStream-derived yes yes yes yes
VSocketStream no yes no no
Parameters:
offsetthe offset, meaning depends on whence value
whenceSEEK_SET, SEEK_CUR, or SEEK_END
Returns:
true if the seek was successful

Definition at line 43 of file viostream.cpp.

References mRawStream, and VStream::seek().

bool VIOStream::seek0 ( )

This is a convenience function that means seek(0, SEEK_SET).

In other words, seek to the start of the stream. It has the same restrictions as noted in seek() above.

Returns:
true if the seek was successful

Definition at line 47 of file viostream.cpp.

References mRawStream, and VStream::seek0().

Vs64 VIOStream::getIOOffset ( ) const

Returns the "current" "offset" in the stream.

Those scare quotes are there because those terms do not quite have consistent or uniform meaning and behavior for all stream types, so you need to be a little careful in using this feature. For buffered file streams, the current offset is simply the i/o mark relative to the start of the file. For memory streams, the current offset is also the i/o mark, relative to the start of the buffer. But for socket streams and unbuffered file streams, there are limitations. Socket streams have no buffer, so the current offset is simply the accumulated number of bytes that have been read and/or written; when used with a socket stream, this function is most useful as a way to determine how much data you have read since last looking at the offset, without having to keep track of each individual read operation (which you might not be able to). Unbuffered file streams have no ability to determine the current i/o mark, yet allow seeking; so there is no way for the class to keep track of the current offset on its own; so, for unbuffered file streams, getIOOffset() throws an exception because it is an illegal operation.

Definition at line 51 of file viostream.cpp.

References VStream::getIOOffset(), and mRawStream.

Vs64 VIOStream::available ( ) const

Returns the number of bytes that are available to be read from this stream.

For file and memory streams, this means the number of bytes from the current i/o mark until the end of the file or buffer. For socket streams, this means the number of bytes that can be read without blocking (that is, the number of bytes that are waiting to be read on the socket at this time).

Returns:
the number of bytes currently available for reading

Definition at line 55 of file viostream.cpp.

References VStream::available(), and mRawStream.

VStream & VIOStream::getRawStream ( )

Returns a reference to the underlying raw stream; used by the friend function streamCopy() so it can call through to the corresponding VStream friend function and supply it the raw streams.

Also used by some debugging functions.

Returns:
a reference to the underlying raw stream

Definition at line 59 of file viostream.cpp.

References mRawStream.

Vs16 VIOStream::streamCompare ( VIOStream streamA,
VIOStream streamB,
Vs64  numBytesToCompare 
) [static]

Compare 2 streams by ascii values.

The streams will be restored to their current positions upon return.

Returns:
-1 if streamA < streamB, 0 if streamA == streamB, otherwise returns 1

Definition at line 64 of file viostream.cpp.

References CONST_S64, getIOOffset(), read(), and seek().


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

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.