Go to the previous, next section.
#include <nihcl/OIOstream.h>
Class
OIOistream
is the abstract base class for classes implementing various formats of object input from
istream
s 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.
OIOistream(istream&
s, unsigned
capacity
=1024)
OIOistream
for the
istream
s
with an initial object capacity of
capacity
objects (see class
ReadFromTbl
).
virtual OIOin& operator>>(char*)
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&)
istream
associated with this
OIOistream
via
istream::operator>>()
and returns a reference to this
OIOistream
.
virtual int get()
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)
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)
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)
istream
associated with this
OIOistream
via
istream::operator>>()
and returns a reference to this
OIOistream
.
virtual OIOin& get(streambuf&
sb, char
delim
='\n')
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)
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)
virtual int precision()
virtual int width(int
n)
virtual int width()
operator istream&()
istream
associated with this
OIOistream
.
istream* strm; // input stream
virtual Object* readObject(const Class&
expected) = 0
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.
void checkRead() const
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)
istream
associated with this
OIOistream
and returns a reference to this
OIOistream
.
void syntaxErr(const char*
expect, char
was) const
NIHCL_RDSYNERR
exception. The argument
expect
is the character the caller expected, and the argument
was
is the character actually read.
NIHCL_RDBADSIG
,
NIHCL_RDEOF
,
NIHCL_RDFAIL
,
NIHCL_RDSYNERR
,
NIHCL_RDUNKCLASS
,
NIHCL_RDWRONGCLASS
,
NIHCL_STROV
Go to the previous, next section.