Panda3D
Public Member Functions

StreamWrapper Class Reference

This class provides a locking wrapper around a combination ostream/istream pointer. More...

#include "streamWrapper.h"

Inheritance diagram for StreamWrapper:
IStreamWrapper OStreamWrapper StreamWrapperBase StreamWrapperBase

List of all members.

Public Member Functions

 StreamWrapper (iostream *stream, bool owns_pointer)
 StreamWrapper (iostream &stream)
void acquire ()
 Acquires the internal lock.
int get ()
 Atomically reads a single character from the stream.
iostream * get_iostream () const
 Returns the iostream this object is wrapping.
istream * get_istream () const
 Returns the istream this object is wrapping.
ostream * get_ostream () const
 Returns the ostream this object is wrapping.
bool put (char c)
 Atomically writes a single character to the stream.
void read (char *buffer, streamsize num_bytes, streamsize &read_bytes, bool &eof)
 Atomically reads a number of bytes from the stream.
void read (char *buffer, streamsize num_bytes)
 Atomically reads a number of bytes from the stream, without error detection.
void read (char *buffer, streamsize num_bytes, streamsize &read_bytes)
 Atomically reads a number of bytes from the stream.
void release ()
 Releases the internal lock.
streamsize seek_gpos_eof ()
 Atomically seeks to EOF and returns the gpos there; that is, returns the file size.
void seek_read (streamsize pos, char *buffer, streamsize num_bytes, streamsize &read_bytes, bool &eof)
 Atomically seeks to a particular offset from the beginning of the file, and reads a number of bytes from the stream.
void seek_write (streamsize pos, const char *buffer, streamsize num_bytes, bool &fail)
 Atomically seeks to a particular offset from the beginning of the file, and writes a number of bytes to the stream.
void write (const char *buffer, streamsize num_bytes, bool &fail)
 Atomically writes a number of bytes to the stream.
void write (const char *buffer, streamsize num_bytes)
 Atomically writes a number of bytes to the stream, without error detection.

Detailed Description

This class provides a locking wrapper around a combination ostream/istream pointer.

Definition at line 106 of file streamWrapper.h.


Member Function Documentation

void StreamWrapperBase::acquire ( ) [inline, inherited]

Acquires the internal lock.

User code should call this to take temporary possession of the stream and perform direct I/O operations on it, for instance to make several sequential atomic reads. You may not call any of the StreamWrapper methods while the lock is held, other than release().

Use with extreme caution! This is a very low-level, non-recursive lock. You must call acquire() only once, and you must later call release() exactly once. Failing to do so may result in a hard deadlock with no available debugging features.

Definition at line 47 of file streamWrapper.I.

Referenced by Multifile::flush(), IStreamWrapper::get(), OStreamWrapper::put(), IStreamWrapper::read(), IStreamWrapper::seek_gpos_eof(), IStreamWrapper::seek_read(), OStreamWrapper::seek_write(), and OStreamWrapper::write().

int IStreamWrapper::get ( ) [inline, inherited]

Atomically reads a single character from the stream.

Definition at line 113 of file streamWrapper.I.

References StreamWrapperBase::acquire(), and StreamWrapperBase::release().

iostream * StreamWrapper::get_iostream ( ) const [inline]

Returns the iostream this object is wrapping.

Definition at line 206 of file streamWrapper.I.

istream * IStreamWrapper::get_istream ( ) const [inline, inherited]

Returns the istream this object is wrapping.

Definition at line 103 of file streamWrapper.I.

Referenced by Multifile::flush().

ostream * OStreamWrapper::get_ostream ( ) const [inline, inherited]

Returns the ostream this object is wrapping.

Definition at line 152 of file streamWrapper.I.

bool OStreamWrapper::put ( char  c) [inline, inherited]

Atomically writes a single character to the stream.

Returns true on success, false on failure.

Definition at line 163 of file streamWrapper.I.

References StreamWrapperBase::acquire(), and StreamWrapperBase::release().

void IStreamWrapper::read ( char *  buffer,
streamsize  num_bytes 
) [inherited]

Atomically reads a number of bytes from the stream, without error detection.

If fewer bytes than requested are read, quietly fills the remaining bytes with 0.

Definition at line 47 of file streamWrapper.cxx.

References StreamWrapperBase::acquire(), and StreamWrapperBase::release().

void IStreamWrapper::read ( char *  buffer,
streamsize  num_bytes,
streamsize &  read_bytes 
) [inherited]

Atomically reads a number of bytes from the stream.

Returns the number of bytes actually read.

Definition at line 81 of file streamWrapper.cxx.

References StreamWrapperBase::acquire(), and StreamWrapperBase::release().

void IStreamWrapper::read ( char *  buffer,
streamsize  num_bytes,
streamsize &  read_bytes,
bool &  eof 
) [inherited]

Atomically reads a number of bytes from the stream.

Returns the number of bytes actually read, and whether an eof condition was detected by the operation.

Definition at line 99 of file streamWrapper.cxx.

References StreamWrapperBase::acquire(), and StreamWrapperBase::release().

void StreamWrapperBase::release ( ) [inline, inherited]

Releases the internal lock.

Must be called exactly once following a call to acquire(). See the cautions with acquire().

Definition at line 65 of file streamWrapper.I.

Referenced by Multifile::flush(), IStreamWrapper::get(), OStreamWrapper::put(), IStreamWrapper::read(), IStreamWrapper::seek_gpos_eof(), IStreamWrapper::seek_read(), OStreamWrapper::seek_write(), and OStreamWrapper::write().

streamsize IStreamWrapper::seek_gpos_eof ( ) [inherited]

Atomically seeks to EOF and returns the gpos there; that is, returns the file size.

Note that the EOF might have been moved in another thread by the time this method returns.

Definition at line 140 of file streamWrapper.cxx.

References StreamWrapperBase::acquire(), and StreamWrapperBase::release().

Referenced by SubStreamBuf::seekoff().

void IStreamWrapper::seek_read ( streamsize  pos,
char *  buffer,
streamsize  num_bytes,
streamsize &  read_bytes,
bool &  eof 
) [inherited]

Atomically seeks to a particular offset from the beginning of the file, and reads a number of bytes from the stream.

Returns the number of bytes actually read, and whether an eof condition was detected by the operation.

Definition at line 119 of file streamWrapper.cxx.

References StreamWrapperBase::acquire(), and StreamWrapperBase::release().

Referenced by Multifile::read_subfile(), and SubStreamBuf::underflow().

void OStreamWrapper::seek_write ( streamsize  pos,
const char *  buffer,
streamsize  num_bytes,
bool &  fail 
) [inherited]

Atomically seeks to a particular offset from the beginning of the file, and writes a number of bytes to the stream.

Returns whether a failure condition was detected by the operation.

Definition at line 209 of file streamWrapper.cxx.

References StreamWrapperBase::acquire(), and StreamWrapperBase::release().

void OStreamWrapper::write ( const char *  buffer,
streamsize  num_bytes 
) [inherited]

Atomically writes a number of bytes to the stream, without error detection.

Definition at line 178 of file streamWrapper.cxx.

References StreamWrapperBase::acquire(), and StreamWrapperBase::release().

void OStreamWrapper::write ( const char *  buffer,
streamsize  num_bytes,
bool &  fail 
) [inherited]

Atomically writes a number of bytes to the stream.

Returns whether a failure condition was detected by the operation.

Definition at line 192 of file streamWrapper.cxx.

References StreamWrapperBase::acquire(), and StreamWrapperBase::release().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations