473,804 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1347
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
2170
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 what the image looks like, and how big it is. the quality is selected using a trackBar1. the MouseUp event of trackBar1 triggers this method public void updatePanel() string file =...
1
5879
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 multiple Instances of 1 form. I have a Form frmSource from which I have multiple Instances, each with a unique Identifier. So when I Load or Close a specific instance, I want to load or save the Settings (Top, Height, Width, etc) in an XML-file....
10
7375
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 Windows.Forms.UserControl in a COM environment, i.e. I want to host that control in a COM host. So far, so good, I can host it, but I can not reach the parent COM object from the control (Parent property is null :( ). I have stopped the control in the...
1
10383
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: fileName.SaveAs("testfile.txt"); it's going to document settings -- my documents and saving it there. I need to save it in the bin folder of the project so my printing process can pick
7
1272
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 ending. event : Application_End in Global.asax. But the object are not accesible from there so I can't save them. Any idea ???
6
8005
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 file is not the real text needed to login? I am loking to create simple ftp client to perform one function, and that is to dl one file, and rename it. Everything works fine, except I am a bit uncomfortable leaving the password of the ftp location...
0
1552
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 execute button2's click event. This works great when i know the name of the method that i want to invoke. I do so by doing this: Dim AssemblyPointer As Reflection.Assembly
3
13223
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 the 'AssemblyBuilder.Save' method, however, it takes a file name as a parameter and I dont see any documentaion on how to define the path/target location to write the file to. Here's a snippet of my code: Dim TCA As New TestCreateAssembly Dim...
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9177
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6870
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.