beautypg.com

A note on the rwfactory, See below – HP Integrity NonStop J-Series User Manual

Page 227

background image

function:

RWspace RWCollectable::nilStoreSize();

For other objects, use member function binaryStoreSize().

Here's a sample definition of a binaryStoreSize() function for class Bus:

RWspace Bus::binaryStoreSize() const{
RWspace count = RWCollectable::binaryStoreSize() +
customers_.recursiveStoreSize() +
sizeof(busNumber_) +
driver_.binaryStoreSize();

if (passengers_)
count += passengers_->recursiveStoreSize();
else
count += RWCollectable::nilStoreSize();

return count;
}

Polymorphically Persisting Custom Collections

The versions of saveGuts() and restoreGuts() that Tools.h++ built into class

RWCollection

are

sufficient for most collection classes. The function RWCollection::saveGuts() works by repeatedly
calling:

RWvostream& operator<<(RWvostream&, const RWCollectable&);

for each item in the collection. Similarly, RWCollection::restoreGuts() works by repeatedly calling:

RWvistream& operator>>(RWvistream&, RWCollectable*&);

This operator allocates a new object of the proper type off the heap, then calls insert(). Because all
of the Rogue Wave Smalltalk-like collection classes inherit from

RWCollection

, they all use this

mechanism.

If you decide to write your own collection classes that inherit from class

RWCollection

, you will

rarely have to define your own saveGuts() or restoreGuts().

There are exceptions. For example, class

RWBinaryTree

has its own version of saveGuts(). This is

necessary because the default version of saveGuts() stores items in order. For a binary tree, this
would result in a severely unbalanced tree when the tree was read back in_essentially, the
degenerate case of a linked list. Hence, RWBinaryTree's version of saveGuts() stores the tree
level-by-level.

When you design your class, you must determine whether it has similar special requirements which
may need a custom version of saveGuts() and restoreGuts().

This manual is related to the following products: