Re: [Dev-C++] Loading variables from files [C++]
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Derek C. <de...@ci...> - 2008-04-29 08:18:13
|
Absolutely.
I just communicated the essence of the concept and left making it
bombproof as an exercise for the reader :-)
On Mon, Apr 28, 2008 at 5:31 PM, Per Westermark <pw...@ia...> wrote:
> But remember that you may quite often want to make the serialize a lot
> more advanced, with versioning information.
>
> Serialize is best when the same version of an application on the same
> architecture will load a saved state.
>
> Life may quickly get complicated if moving between different
> architectures. If you write a 32-bit int and the other program expects
> an int to be 64 bits large, the serialize will fail.
>
> Another thing is when a new version have added more state information in
> the class. It is quite probable that the end user expects a new version of
> an application to be able to continue using the existing state
> information.
>
> I often make the serialize methods use text format (together with a bit of
> glue helper functions) to make the serialize a bit more forgiving. It is
> also possible to use binary formats. It's just a question about how to
> handle potential overflows, and to make sure that missing/invalid fields
> gets reasonable defaults.
>
> /pwm
>
>
>
> On Mon, 28 Apr 2008, Derek Clarke wrote:
>
> > A good way is to add serialise operators to the class:
> >
> > ostream& hero::operator>>(ostream& stream)
> > {
> > mapid >> stream;
> > posx >> stream;
> > posy >> stream;
> > return stream;
> > }
> >
> > istream& hero::operator <<(istream& stream)
> > {
> > mapid << stream:
> > posx << stream;
> > posy << stream;
> > return stream;
> > }
> >
> > On Mon, Apr 28, 2008 at 6:40 AM, Samuel Hulley <tal...@gm...> wrote:
> > > Hi,
> > > I am attempting to load variables from files but im not sure what
> > > todo because the variables are different types and sizes.
> > > Here is the source:
> > >
> > > #pragma once
> > > #include <fstream>
> > > using namespace std;
> > >
> > > class hero
> > > {
> > > public:
> > > void setname(string first, string last)
> > > {
> > > fname = first;
> > > lname = last;
> > > return;
> > > }
> > >
> > > void setmap(int mp)
> > > {
> > > mapid = mp;
> > > return;
> > > }
> > >
> > > void setpos(int x, int y)
> > > {
> > > posx = x;
> > > posy = y;
> > > return;
> > > }
> > >
> > > void setmapx(int x)
> > > {
> > > posx = x;
> > > return;
> > > }
> > >
> > > void setmapy(int y)
> > > {
> > > posy = y;
> > > return;
> > > }
> > >
> > > int getmap()
> > > {
> > > return mapid;
> > > }
> > >
> > > int getmapx()
> > > {
> > > return posx;
> > > }
> > >
> > > int getmapy()
> > > {
> > > return posy;
> > > }
> > >
> > > void loadinfo()
> > > {
> > > // This is where I will load the config.
> > > }
> > >
> > > private:
> > > // Map variables.
> > > int mapid;
> > > int posx;
> > > int posy;
> > > };
> > >
> > > Yours Truly
> > > Samuel Hulley.
> > >
> > > -------------------------------------------------------------------------
> > > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> > > Don't miss this year's exciting event. There's still time to save $100.
> > > Use priority code J8TL2D2.
> > > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
> >
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> > Don't miss this year's exciting event. There's still time to save $100.
> > Use priority code J8TL2D2.
> > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
>
|