Tools.h++ Manual
104011 Tandem Computers Incorporated 8-7
8
Unfortunately, at the time of this writing, most implementations of
seekg()
have not proven to be reliable. Hence, this approach was not chosen for this
example.
8.3 Recap
We have seen how an object can be stored and recovered from streams without
regard to the final destination of the bytes of that stream. They could reside in
memory, or on disk. We have also seen how we need not be concerned with
the final formatting of the stream. It could be in ASCII or binary.
It is also quite possible to write your own specializing "virtual stream" class,
much like
RWpostream
and
RWpistream
. The great advantage of the virtual
streams facility is that if you do write your own specialized virtual stream,
there is no need to modify any of the code of the client classes—you just use
your stream class as an argument to
RWvostream& operator<<(RWvostream&, const ClassName&);
RWvistream& operator<<(RWvistream&, ClassName&);
In addition to storing and retrieving an object to and from virtual streams, all
of the classes can store and retrieve themselves in binary to and from an
RWFile
. This file encapsulates ANSI-C style file I/O. Although more limited
in its abilities than stream I/O, this form of storage and retrieval is faster to
and from disk because the virtual dispatching machinery is not needed.