Operators
The storage and retrieval of polymorphic objects that inherit from RWCollectable is a powerful and adaptable feature of the The Essential Tools Module. Like other persistence mechanisms, polymorphic persistence uses the overloaded extraction and insertion operators (operator<< and operator>>). When these operators are used in polymorphic persistence, not only are objects isomorphically saved and restored, but objects of unknown type can be restored.
Polymorphic persistence uses the operators listed below.
*Operators that save references to RWCollectable objects:
 
RWvostream& operator<<(RWvostream&, const RWCollectable&);
RWFile& operator<<(RWFile&, const RWCollectable&);
Each RWCollectable-derived object is saved isomorphically with a class ID that uniquely identifies the object's class.
*Operators that save RWCollectable pointers:
 
RWvostream& operator<<(RWvostream&, const RWCollectable*);
RWFile& operator<<(RWFile&, const RWCollectable*);
Each pointer to an object is saved isomorphically with a class ID that uniquely identifies the object's class. Even nil pointers can be saved.
*Operators that restore already-existing RWCollectable objects:
 
RWvistream& operator>>(RWvistream&, RWCollectable&);
RWFile& operator>>(RWFile&, RWCollectable&);
Each RWCollectable-derived object is restored isomorphically. The persistence mechanism determines the object type at run time by examining the class ID that was stored with the object.
*Operators that restore pointers to RWCollectable objects:
 
RWvistream& operator>>(RWvistream&, RWCollectable*&);
RWFile& operator>>(RWFile&, RWCollectable*&);
Each object derived from RWCollectable is restored isomorphically and the pointer reference is updated to point to the restored object. The persistence mechanism determines the object type at run time by examining the class ID that was stored with the object. Since the restored objects are allocated from the heap, you are responsible for deleting them when you are done with them.