473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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.
Jul 22 '05 #1
2 1329
On Sat, 11 Dec 2004 21:43:11 +0100, danny van elsen
<da*************@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
Jul 22 '05 #2

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

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sean | last post by:
i am writing a class that visual demonstrates the result of changing the quality of a jpeg. the intention is to do this by saving the file and a selected quality, then reloading it to get an idea of...
1
by: DraguVaso | last post by:
Hi, I found some examples for storing the FormSettings of a Form in an XML-file, but none of these could match my criteria: What I am looking for is the possibility to save the FormSettings of...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
1
by: microsoft.news.com | last post by:
I have a console app that creates a file and I want to save it to the bin directory of the project. How can I have the file save there as default? My code looks like this: ...
7
by: Shanli RICHEZ | last post by:
I'm using ASP.NET and quite a lot of object in memory instead of a database. The question is that I tried to save the data, serialize them in a XML file to save them when the application is...
6
by: Luis | last post by:
Hello All! I know this may be beginner stuff but... I was wondering if there is a way to save text from a text box to an Application Configuration file and maybe hash it so that the text in the...
0
by: Shawn Hogan | last post by:
Hi everyone, I've been trying to execute a control's private event code via reflection from another class with the goal of potentially doing some unit testing. The examples below are trying to...
3
by: moondaddy | last post by:
I'm using some sample code from the msdn sample project: http://download.microsoft.com/download/4/7/B/47B2164C-E780-4B10-8DE4-2CB5B886E0A6/Technologies/Reflection/ReflectionEmit.zip.exe I'm using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.