StreamingSnippets

These snippets illustrate how to create streams on various kinds of memory objects, and flatten and resurrect objects using those streams. TStreamExample is a sample class that illustrates how to implement the standard streaming operators, operator>>= and operator<<=, and how to maintain compatibility with earlier versions.

To run the snippets, use either the SnippetBrowser or RunSnippet utilities. RunSnippet can be invoked like this:

Files and classes

TStreamingSnippets, defined in StreamingSnippets.h and StreamingSnippets.C, defines snippets that illustrate streaming with standard memory stream objects. It uses classes such as TMemorySurrogate, TContiguousMemoryStream, TContiguousGrowingStream, TGrowingChunkyStream, TStreamContextWrapper, and TStreamException.

TStreamExample, defined in StreamExample.h and StreamExample.C, is used by the StreamingVersion snippet in TStreamingSnippets. The source code for two versions of this class is available, controlled by the variable SAMPLE_NEWVERSION. This variable is set in the .PinkMake file. When SAMPLE_NEWVERSION is undefined, the "original" version code is used. This original code only writes and reads the original version of the flattened information. When SAMPLE_NEWVERSION is defined, the "new" version code is used. This code writes the new version of the flattened information, but reads both the old and new versions.

Notes

As a general rule of thumb, all classes belong in a library, rather than a binary. TStreamExample is built into StreamingAndPersistenceLib. If you write a test program and encounter streaming failures, it might be because you tried to put all the code into a binary, rather than keeping only the main() in a binary and putting other classes into a library.

The StreamingVersion snippet relies on data files in $TaligentRoot/RuntimeEnv/Data/Samples that contain flattened representations of old and new versions of TStreamExample. This data is created by two versions of StreamExampleDataGeneratorApp: one built with SAMPLE_NEWVERSION undefined, and one with it defined.

You cannot install two versions of a library at the same time. If you want to run these snippets using a different version of the library, you need to:

1) Define (or undefine) the SAMPLE_NEWVERSION variable by editing the compileoptions line in the .PinkMake file.

2) Execute 'Makeit Clean Complete' to delete the old code and rebuild the project. The new library will be installed.

When you next execute the snippet, the changed version of the library will be used.

If you want to generate new data files, you will have to follow this same procedure so that you can generate one file using one library, and the other file using the other. After each build, execute StreamExampleGeneratorApp to generate the data file.


Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.