Maybe it’s the wrong name given in the subject but I’ll try and explain what I am trying to achieve.
I am in the midst of designing a persistence framework that will allow a user in an intuitive way to serialize data to file that’s more easy to use past the trivial way of making objects inherit a 'serialize' function and let it deal with itself the writing of information.
Its very cumbersome and error prone to keep implementing these serialise functions for each different type of class you want to serialise even if you do lots of helper macros that deal with the atomic types its not really solving the inelegant way the client programmer uses it.
There have been a few approaches that I have seen that seem to work and I was hoping for suggestions\ideas.
Concerning what’s better for the end user what do you think about this?
An approach I've seen is to declare special structures that contain metadata of the types you want to be persistent.
Eg
T_PersisClass myPersistentStructure
{
CAT n; // category would be a user defined enum that
// would specify file groupings with default as 0
PERSIS_MEMBER a;
PERSIS_ARRAY arr nElements;
PERSIS_DYN_ARRAY dynArr;
PERSIS_STR string;
//......
}
the macros PERSIS_MEMBER etc are the only types to be allowed in the class but the types can be extended if necessary.
The category (CAT member) decides what file the structure would be saved into.
T_PersisClass.RegisterCatogory( CAT catNumber, const char * fileName);
if no category registered then somesort of default category used.
When your ready you can save all your defined structures to file in you make the call
PersistantFramwork::Save(savedFile);
by some magic behind the scenes all the the structures will be save to the correct files.
I would probably have an xml file also that points to the different files on save as well with the different categories as nodes containing the filepath.
When the user wants to load the structure back in they will need a definition of the structure and they would load it in via the xml file
myPersistentStructureLoad = T_PersisClass ::load(savedFile.xml);
This will search the savedFile.xml file and restore the object to myPeristentStructure.
A couple of drawbacks include the multiple definition of the structures on save and load unless they share common headers but cant see how that would be avoided.
Also need some magic for name decoration or something with id tags to deal with identicle structures.
I would plan to use this as dumping ground for information like an intermediate file format. My maya or max exporter can then use this to output all scene data with catorgaries such shaders, vertices, scene settings etc.
A platfrom specific converter can then read the ouputed file that the exporters created using the persistent lib created and get the information it needs leaving unnecessary types and create a platform specific game wad.
[edited by - PantherBoy on July 26, 2003 3:05:18 PM]