Chapter 11. Archiving, Dearchiving and Networking Objects and Simulations

breve allows simulations and individual objects within simulations to be archived into human-readable XML files, and then later extracted. The XML archive/dearchive process applies both to saving simulation objects to files and to sending objects over a network. Both techniques require object encoding and decoding, and the discussion in this chapter applies to both.

This chapter first describes how individual objects can be archived and dearchived (the section called “Saving and Loading Individual Objects”) and then how entire simulations can be archived and dearchived (the section called “Saving and Loading the Entire State of a Simulation”). Though this simulation discusses archiving to and from files, the same techniques discussed in this section are used for networking.

Important note: archiving and dearchiving is currently only supported in the steve language frontend, not the Python language frontend. Support for Python archiving and dearchiving is forthcoming in a future breve release.

Methods Called for Objects During Archiving and Dearchiving

During dearchiving, the following steve language types are automatically saved and restored: int, float, string, list, hash, data. The pointer type is not automatically restored. The object type is restored only if the other object was dearchived from the same archive. If an object to be archived contains only the types which are automatically saved and restored, no further action is required to prepare the objects for saving and loading.

For objects which do contain either pointer or object types, data will need to be carefully encoded and decoded. The special methods archive and dearchive are called automatically during archiving and dearchiving respectively. The "archive" method should be implemented, if necessary, to prepare a user object for archiving. The "dearchive" method should be implemented, if necessary, after an object has been archived to prepare it for being loaded into a simulation.

For many users, these methods are not required and should not be implemented. If they are implemented, however, they must return 1 to indicate success and unless the methods are specifically intended to override superclass behaviors, they must call the superclass implementation. In most cases, it is desirable to return the same value as the superclass implementation so that errors are handled correctly. Example archive and dearchive methods are shown below. These methods do no special preparation for archiving and dearchiving, but instead fulfill the requirements listed above and print a message.

+ to archive:
        print "Archiving $self...".

        return (super archive).

+ to dearchive:
        print "Dearchiving $self...".

        return (super archive).