/* Copyright (c) 1999, Gary Yihsiang Hsiao. All Rights Reserved. bugs report to: ghsiao@rbcds.com or ghsiao@netzero.net Permission to use, copy, modify, and distribute this software for NON-COMMERCIAL purposes and without fee is hereby granted provided that this copyright notice appears in all copies. This software is distributed on an 'as is' basis without warranty. */ This software was downloaded originally from www.cuj.com for the August 2000 c++ users journal. Persistence seems fast and fairly easy to do. 1- Create a class inheriting from the POBObj class. example.h In this example, only two routines need to be overwritten. "const string &" conversion routine Assignment operator Follow the pattern as shown. This enables the object to be streamed to and from disk properly without any more code. The implementation of these two methods is shown in "example.C". Also, be sure and add the static create method as shown. All objects need to be instantiated at some point by a GFactory class. Essentially, POBObj is an interface class which enforces these methods to be created. 2- Create an application which can write to disk. example1.C - writes and modifies objects on disk. example2.C - removes objects from disk by Object Idenfier, OID. Every application will need to declare the filename. This is done via a POBroker class. This template class is the window for all persistent object activity. The initial constructor will require the name of the file as shown below: POBroker<POBObj> pob("TEST.DAT"); Next, register the appropriate create functions so that those objects may be created, modified and/or deleted. pob.register_create_function(typeid(ABC).name(), ABC::create); Check out the POBroker class to understand all the various database functions. Remember always to delete the reference returned by a database operation: pob.deleteRef(pabc); 3- Read back in persisted objects. It is just that easy ...
Hosted by www.Geocities.ws

1