472,986 Members | 2,825 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Saving/Loading a class instance to file

Trying to save/load a class instance to a file is tough. The reason is
because there is no way to preserve its type other than by conventon. For
eample, one can save all the states of the members of a class instance to a
file. But when loading it up the program can only read in the values stored.
It has no idea what kind of class they came from, and there is no way to
save info (that I'm aware of) that let can allow the application to figure
this out at runtime. The programmer must therefore figure out a saving
convention and then load the approriate type according to his convention.

This is especially a problem with templated classes. This is because an
instance of a templated class requires it be made concrete at compile time.
It is therefore impossible to write a Save_To_File() member method for a
templated class, since one can't override it for different types, and there
is no way of constructing an arbitray template class (i.e., one where the
template arguments are variables).

Anybody have clever ways of saving a class instance in such a way it can be
restored without knowing ahead of time what class it came from in the first
place? For example, can I save something to a file that when loaded can let
me build at runtime, say, an arbitrary class or data type?

Nov 23 '05 #1
3 1375
Sounds to me you are trying to reinvent what is already prescribed and
available. Take a look at the IPersist* family of interfaces.

Nov 24 '05 #2
Thanks Brian!

Indeed, I'll look this up. So far the MSDN2 does list IPersist, but doesn't
really describe it, it just --- IS. I also see I should study IMoniker. If
you know of any sources of sample code, preferably in /clr managed VS
C++.NET (Express), that would be great too... : )


"Brian Muth" <bm***@mvps.org> wrote in message
Sounds to me you are trying to reinvent what is already prescribed and
available. Take a look at the IPersist* family of interfaces.


Nov 28 '05 #3
The best reference for IMoniker is "Inside OLE" by Kraig Brockshmidt. The
entire text of this book is available on one of the older MSDN Library
CD's... I forget which one.

Nov 28 '05 #4

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

Similar topics

by: Jacob H | last post by:
Hello list... I'm developing an adventure game in Python (which of course is lots of fun). One of the features is the ability to save games and restore the saves later. I'm using the pickle...
by: G-Factor | last post by:
Hi all I've just started learning about saving files. I got bit of a problem. The following code gives me an error about incompatible types. (Cannot covert from class character to char *). I...
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
by: Aguilar, James | last post by:
My previous example used the concept of a Shape class heirarchy, so I will continue with that. Suppose I have something like fifty different shapes, and I am trying to instantiate one of them. ...
by: Tom | last post by:
I have a large application; lots of forms, multiple dynamic DLLs, etc. I also have, in the appliation, a general 'Preferences' class object (which is in itself a separate DLL, and I just include a...
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a...
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data)...
by: shuisheng | last post by:
Dear All, Assume I have two classes: material and shape, as follows class Material { double density; // material attribute, may have more vector<Shape*pShape; // shape objects assocaited...
by: ulaskaraoz | last post by:
Hi, I have a std::map instance that I want to save into harddisk so that I donot have to recompute it each time. The map itself is keyed by a string and the values are pointers to other objects....
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.