links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Last updated at 5:29 am UTC on 19 October 2017

Class comment:

Ordinary ReferenceStreams assume that the names and order of instance variables is exactly the same when an object file is written and read.
SmartRefStream allows object files to be read even after instance variables have changed or the entire class has been renamed.

When an object file is written, no one knows how the classes will change in the future. Therefore, all conversion must be done when the file is read. The key is to store enough information in the file about the names of the instance variables of all outgoing classes.

SmartRefStream works best with only one tree of objects per file. You can nextPut: more than once, but each object tree gets its own class structure description, which is big.

Conversion of old objects is done by a method

A method in each class called
 convertToCurrentVersion: varDict refStream: smartRefStrm
converts objects stored with SmartRefStream in an old class version to the objects of a new class version.

At fileOut time, ChangeSet>>checkForConversionMethods creates a prototype of this method. This happens only if
 Preference #conversionMethodsAtFileOut 
is true.
The programmer must edit this method to
1. test if the incoming object needs conversion,
2. put non-nil values into any new inst vars that need them, and
3. save the data of any inst vars that are being deleted.

Determining which old version is represented by the incoming object can be done in several ways: noticing that a current inst var is nil when it should have data, noticing that there is an older inst var name in the variable dictionary (varDict), checking kinds of objects in one or more inst vars, or retrieving the classVersion of the incoming object from the ref stream.

If a class is renamed, a method goes into SmartRefStream telling the new name. The conversion method of the new class must be prepared to accept instances of the old class also. If no inst var names have changed, the conversion method does nothing.

This is illustrated by a SmartRefStream renaming example.

SmartRefStream is used when exporting an ImageSegment

Mariano Martinez Peck 1, Noury Bouraqadi, Stéphane Ducasse, Luc Fabresse
Object Swapping Challenges - an Evaluation of ImageSegment

See also