| Overview | Screenshots | Downloads | News | Documentation | Thanks | Simugraph Home Page |
H-World will be able to save games at any stage of the game. It uses a persistent object storage layer to save all objects involved in a running game.

What's the meaning of the colors in the diagram? The yellow classes are part of the application independant persistence layer and can be resued for other projects. White classes are application dependant and just added as examples. Grey boxes are comments.
The heart of the persistence layer is the storage_t class which is responsible for storing and restoring object networks. It ensures that multiple referenced objects are stored only once and that during loading all pointers are restored correctly (to point to the correct object instances).
The storage_t class is application independant. To restore application objects each application has to subclass it and implement the create() method to instantiate application dependant objects. I've chosen this approach beacuse I think I'll need persistent object storage in other projects, too, and I can resuse the storage_t class for other projects this way.
Each object that shall be stored persistently must be derived from the persistent_t base class. It has to implement the method read_write() to store and restore it's contents and its aggregated and associated objects, and get_cid() which is needed to get a unique id for the objects class. This id is needed to instantiate a object of the correct class in the restore() operation of storage_t.
The iofile_t class is a base class for reading/writing basic data types to persistent storage. It brings a implementation to store data in disk files, but it can be subclassed to store data in databases or other storage media.
All in all this is a fairly simple persistence layer. It can't handle pointers to pointers, but H-World does not need such constructs. Only associated and aggregated objects (object networks) are supported.
Was this article interesting to you?
Did you find mistakes or want to make suggestions?
Feedback (good or bad) is always welcome!
You can reach me by
e-mail:
Send feedback.