RE: [Algorithms] class parser
Brought to you by:
vexxed72
From: Ko, M. <MAN...@ca...> - 2000-08-10 16:22:55
|
That is a bad way to go about it: your problem was you didn't design the persistent interface ahead of time. I use a "schema driven" method - sort of like database systems. 1) You need to think of the on-disk persistent structure as separate data-structures from the runtime/in-memory rep. Remember, C/C++ structures have compiler imposed alignments that are not obvious. NEVER writes a structure or class directly to disk. VERY BAD!!! Besides, there are always fields in a class that are meant for runtime only. Don't want to persist those. 2) The on disk record structures are defined explicitily using a schema. 3) with schemas you never need to write another line of IO code. The byte swapping code can be writing once. It uses the schema to do the swapping. 4) More important when you change compilers or compiler options - your alignment never changes! Otherwise when you go from 32bit to 64 bit. You will go nuts. Next the question is how to map runtime/in memory objects that need to be persistented to their schema. 1) Use some macros around each member variable that u need to be persistented in the class - complicated and fragile. But if u get it to work, less maintainence. 2) Define a static method for each class that u need to persist and register itself with the schema manager. Simple and robust. Problem is only when u extend the class u need to update the registration method. I use 2) - it works well. Next - you have to deal with pointers. If you are currently reading and writing in memory structures that are graphs or lists. Then you might have to deal with pointers. I don't persistent those structures. I use arrays. But if you do, use a persistent ID scheme. For every ptr. define a unique ID that will be saved on disk. -----Original Message----- From: Blade S.N [mailto:he...@ci...] Sent: Tuesday, August 01, 2000 6:55 AM To: gda...@li... Subject: [Algorithms] class parser Hi all, We are going to port our game to Mac and begin to experience problem of small_big endian conversion.It is concerned with too many class and structure .It's impossible to write all the conversion code for every data file type. So I am going to implement a head file parser to parse the definition of each class and generate the conversion code automatically .It's surely not the most convenient way to make that.But I haven't any good idea. Can anyone here enlighten me.Is there any simple way? Thanks in advance. S.N |