Persistence
Overview
The Essential Math Module comes with an extensive and powerful persistence facility which can faithfully store and restore your vectors and matrices. In the Essential Math Module, store and restore are accomplished by the following member functions:
 
void restoreFrom(RWFile&);
void restoreFrom(RWvistream&);
void saveOn(RWFile&) const;
void saveOn(RWvostream&) const;
These functions can move objects to and from RWFile objects, and to and from the Rogue Wave virtual streams facility.
Class RWFile encapsulates ANSI-C file I/O. Objects saved through RWFile are saved in binary format, resulting in efficient storage and retrieval.
Classes RWvistream and RWvostream are abstract base classes of the Rogue Wave virtual streams facility. The specializing classes that derive from these abstract base classes determine their final output formats. For example, the classes RWpistream and RWpostream, which derive from RWvistream and RWvostream, respectively, store and retrieve objects using portable ASCII format. The results can even be transferred between different operating systems.
It is up to the user to decide whether to store to RWFiles or to virtual streams. RWFiles offer the advantage of speed, but limit portability of the results to the host machine. Virtual streams are not as fast, but the specializing classes RWpistream and RWpostream allow the results to be moved to any machine.
For more information on RWFile or the streaming classes, see the SourcePro API Reference Guide.
There is one final way to store and retrieve objects. The overloaded left shift operator << prints the contents of an object in a human-readable form. Conversely, the overloaded right shift operator >> reads and parses an object from an istream in a human-understandable format. Here are their prototypes:
 
ostream& operator<<(ostream& ostr, const ClassName& x);
istream& operator>>(istream& istr, const ClassName& x);
For most objects, the output of operator<<() can be fed into operator>>(). Note that this approach contrasts with restoreFrom() and saveOn(), which may store and restore to an ASCII stream, but not necessarily in a form that could be called human-readable.