WWC snapshot of http://www.alw.nih.gov/Docs/NIHCL/nihcl_30.html taken on Sat Jun 10 19:13:51 1995

Go to the previous, next section.

OIOistream--Abstract Class for Stream Object Input

SYNOPSIS

#include <nihcl/OIOstream.h>

BASE CLASS

OIOin

DERIVED CLASSES

OIOnihin

RELATED CLASSES

OIOostream

DESCRIPTION

Class OIOistream is the abstract base class for classes implementing various formats of object input from istreams for the readFrom() function. It defines virtual member functions for reading the fundamental data types, arrays of fundamental data types, and C-style (null-terminated) character strings. It also defines virtual member functions for setting and accessing the input format precision and field width.

Since all input functions are virtual, derived classes can easily interpret a variety of formats from an istream. This is a more flexible form of object I/O than the file descriptor object I/O provided by classes OIOofd and OIOifd, but is less efficient.

CONSTRUCTORS

OIOistream(istream& s, unsigned capacity =1024)
Constructs an OIOistream for the istream s with an initial object capacity of capacity objects (see class ReadFromTbl).

INPUT FUNCTIONS

virtual OIOin& operator>>(char*)
Reads characters from the istream associated with this OIOistream into the array pointed to by the right argument until a whitespace character is read. The whitespace character is also stored. A terminating zero byte is always stored, even if no characters are read. If width() is non-zero, it is interpreted as the size of the array, and a maximum of width()-1 characters will be read, not including the terminating zero byte.

virtual OIOin& operator>>(char&)
virtual OIOin& operator>>(unsigned char&)
virtual OIOin& operator>>(short&)
virtual OIOin& operator>>(unsigned short&)
virtual OIOin& operator>>(int&)
virtual OIOin& operator>>(unsigned int&)
virtual OIOin& operator>>(long&)
virtual OIOin& operator>>(unsigned long&)
virtual OIOin& operator>>(float&)
virtual OIOin& operator>>(double&)
Reads the right operand from the istream associated with this OIOistream via
istream::operator>>() and returns a reference to this OIOistream.

virtual int get()
Reads a single char from the istream associated with this OIOistream via
istream::get() and returns it as the result.

virtual OIOin& get(char& c)
virtual OIOin& get(unsigned char& c)
Reads the next byte from the istream associated with this OIOistream via
istream::get(char) or istream::get(unsigned char) into the argument c and returns a reference to this OIOistream.

virtual OIOin& get(char* val, unsigned size)
virtual OIOin& get(unsigned char* val, unsigned size)
Reads size characters, in hexadecimal, into the array pointed to by val from the istream associated with this OIOistream via istream::operator>>(int) and returns a reference to this OIOistream.

virtual OIOin& get(short* val, unsigned size)
virtual OIOin& get(unsigned short* val, unsigned size)
virtual OIOin& get(int* val, unsigned size)
virtual OIOin& get(unsigned int* val, unsigned size)
virtual OIOin& get(long* val, unsigned size)
virtual OIOin& get(unsigned long* val, unsigned size)
virtual OIOin& get(float* val, unsigned size)
virtual OIOin& get(double* val, unsigned size)
Reads size elements into the array pointed to by val from the istream associated with this OIOistream via istream::operator>>() and returns a reference to this OIOistream.

virtual OIOin& get(streambuf& sb, char delim ='\n')
Reads characters from the istream associated with this OIOistream and stores them into the streambuf sb. Stops if End Of File is encountered, if a store into sb fails, or if delim is encountered (delim is not removed from the istream). Returns a reference to this OIOistream.

virtual OIOin& getCString(char* s, unsigned maxlen)
Reads a C-style (null-terminated) string stored by OIOostream::putCString() from the istream associated with this OIOistream into the memory pointed to by s. Raises an NIHCL_STROV exception if the string length, including the null terminator, would exceed maxlen. Raises an NIHCL_RDEOF exception if End Of File is encountered. Raises an NIHCL_RDFAIL exception if a read fails. Raises an NIHCL_RDSYNERR exception if the string syntax is incorrect. Returns a reference to this OIOistream if successful.

virtual int precision(int n)
Sets the number of significant digits inserted by the floating point inserter to n and returns the previous value.

virtual int precision()
Returns the number of significant digits inserted by the floating point inserter.

virtual int width(int n)
Sets the field width to n and returns the previous value.

virtual int width()
Returns the current field width.

CONVERSION OPERATORS

operator istream&()
Returns a reference to the istream associated with this OIOistream.

PROTECTED MEMBERS

Protected Member Variables

istream* strm;          // input stream

Object I/O

virtual Object* readObject(const Class& expected) = 0
Reads an object stored by OIOostream::storeObject() from the istream associated with this OIOistream.

Raises an NIHCL_RDUNKCLASS exception if the class descriptor of the object to be read has not been linked with the program.

Raises an NIHCL_RDWRONGCLASS exception if the class of the object read is not an instance of class expected or an instance of a derived class of expected.

Raises an NIHCL_RDBADSIG exception if the signature of the class of the object read does not match the signature of the class descriptor of the same name that has been linked with the program. This is to detect an attempt to read an object stored by an outdated version of the class.

Returns a pointer to the object read if successful.

Auxiliary Functions

void checkRead() const
Returns if the state of the istream associated with this OIOistream is good. Raises an NIHCL_RDEOF exception if End Of File has been reached. Raises an NIHCL_RDFAIL exception otherwise.

OIOistream& putback(char c)
Puts back the argument character c onto the istream associated with this OIOistream and returns a reference to this OIOistream.

void syntaxErr(const char* expect, char was) const
Raises an NIHCL_RDSYNERR exception. The argument expect is the character the caller expected, and the argument was is the character actually read.

EXCEPTIONS RAISED

NIHCL_RDBADSIG, NIHCL_RDEOF, NIHCL_RDFAIL, NIHCL_RDSYNERR, NIHCL_RDUNKCLASS,
NIHCL_RDWRONGCLASS, NIHCL_STROV

Go to the previous, next section.