persistence framework

Started by
2 comments, last by PantherBoy 20 years, 1 month ago
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]
Advertisement
something like this is really good as well
http://www.codefarms.com/ppf.htm
I got the idea to a function in the class that recieve a void/byte buffer of raw data.
And then extracts the data to each member/variable within the class.


class CMonster <

short x;
short y;

void *load_from_data_buffer(void *buffer)<
x = *buffer;
buffer += sizeof(short);
y = *buffer;
buffer += sizeof(short);
return buffer;
>

>


if you have an array of classes you want to load data into from file buffer, the function returns the pointer to the raw data counted forwards to the raw data that belongs to the next class.

Anton Karlsson
Klingis Entertainment
Games with silly humor
Not quite what I had in mind, not generic enough and still will break down for more complicated classes- pointers, stl containers, etc. We want a solution thats easy to use for the end user thats lightweight and syntactily nice.

I have made a lot of progress with this though now

This topic is closed to new replies.

Advertisement