save: reflection?



 DEVELOP > c-Plus-Plus > save: reflection?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "danny van elsen"
Date: 11 Dec 2004 02:43:11 PM
Object: save: reflection?
hello all,
in my application, I want to save the state of a number of classes to disk: what would be the best way to do this?
right now, I'm hard coding the fields of the classes, but of course after
every change to the classes, I also have to adapt the 'save' method. Is there a better way, perhaps using some kind of reflection?
I've searched boost.org for reflection, but there don't seem to be ready made classes?
thanks for any answer,
Danny.
.

User: "Tom Widmer"

Title: Re: save: reflection? 13 Dec 2004 11:11:34 AM
On Sat, 11 Dec 2004 21:43:11 +0100, danny van elsen
<danny_van_elsen@hotmail.com> wrote:

hello all,

in my application, I want to save the state of a number of classes to disk: what would be the best way to do this?

right now, I'm hard coding the fields of the classes, but of course after
every change to the classes, I also have to adapt the 'save' method. Is there a better way, perhaps using some kind of reflection?

I've searched boost.org for reflection, but there don't seem to be ready made classes?

One approach is to only ever have one data member, a boost::tuple.
That's not nice though, since you have to add a load of private
accessor methods really to avoid nasty syntax (and you may need
const/non-const overloads). Alternatively, accept the small
maintenance overhead (which does give you backwards compatibility and
versioning, unlike if you use reflection directly as is often done in
Java), and use the boost serialization library.
Tom
.

User: "msalters"

Title: Re: save: reflection? 14 Dec 2004 06:12:07 AM
danny van elsen wrote:

hello all,

in my application, I want to save the state of a number of classes to
disk: what would be the best way to do this?

Are they PODs?

right now, I'm hard coding the fields of the classes, but of course

after

every change to the classes, I also have to adapt the 'save' method.
Is there a better way, perhaps using some kind of reflection?

How do you deal with load(), especially with loading older files?
There is a common notion that classes related to file structures
should not change, period. If you need another field, create
a new C++ type and a new file format.
Another solution is to use an XSD to C++ compiler. If you want a new
field, change the XSD and recompile it. They usually will generate
the "save to disk" funcions for you as well.
In the same vein you could use an O/R mapper to save objects to a DB.
Regards,
Michiel Salters
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER