You are not logged in.

#1 2005-03-09 23:21:27

mercy
Member
Registered: 2004-04-24
Posts: 62

gnu c++ and object serialization

im googlin now since hours but didnt find anything useable...

what i want..

typedef struct vertex {
  GLfloat x;
  GLfloat y;
  GLfloat z;
}

class SimpleClass {
public:
  SimpleClass();
  ~SimpleClass();
private:
  vector<vertex> v;
  string n;
};
SimpleClass::SimpleClass() {
  n="something";
  voxel x;
  x.x=0.0f; x.y=0.0f; x.z=0.0f;
  v.push_back(x);
} test;
-snip-
test >> file
-snip-
test << file
-snip-
or something like that..
so i dont have to care about what i write or how to read it back... and all those other nasty shit a file is causing ;-)

i found some lib's implementing stuff like that... like boost .. but i'd like to know more about...
and also i don't want to use something else than the realy base-libs
(I also bet that there MUST be something i didn't find yet)

Offline

#2 2005-03-10 00:30:10

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: gnu c++ and object serialization

this no innate way to do that without writing your own methods.  I'd suggest using the archive stuff from boost

Offline

#3 2005-03-10 08:27:26

mercy
Member
Registered: 2004-04-24
Posts: 62

Re: gnu c++ and object serialization

bad news  :cry:

Offline

#4 2005-03-10 09:31:13

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: gnu c++ and object serialization

personally, I hate boost

but you can always do this the C way, if you want...

the C way is as follows:

SomeClass c();

char buffer[sizeof(SomeClass)];
memcpy( (void*)buffer, (void*)&c, sizeof(SomeClass));
...
file << buffer;
...
file >> buffer;
memcpy( (void*)&c, (void*)buffer, sizeof(SomeClass));

c.SomeMethod();

keep in mind this isn't really the best way to do it, but it works

Offline

#5 2005-03-10 12:26:26

mercy
Member
Registered: 2004-04-24
Posts: 62

Re: gnu c++ and object serialization

hmmm ic  :?

i'll really have to spend more time on this than i actually thougt i would have to ...

well im already using SDL... but .. it got just some very very basic stuff (writing bitmaps to files) as far as i know at the moment (but supports zip and bz2 if i got it right - in a way you dont have to care about that it is compressed)

anyway not really what i wanted to have...

i guess my next step will be to have a look at some applications for 3D-model-creation (GPL/LGPL'ed ones of course  wink )

so i implement support for there model-file-format and build the rest so it fits

this way i dont run in the need of writing my own tools for import/export/filearchitecture or even a tool to create 3D-model's  wink

Offline

#6 2005-03-11 07:25:06

STiAT
Member
From: Vienna, Austria
Registered: 2004-12-23
Posts: 606

Re: gnu c++ and object serialization

Hmm.. we've built own functions in our company, to store our data. We're more or less serializing the objects by our own methods, deserializing it again as well.

But .. a typedef with a type definition and without a type name interesting.

We've overloaded our operators to filestreams, and wrote the serialize / deserialize ourselves, exactly what you don't want. But - you've been googling for hours? In an hour you'd have written this.

// STi


Ability is nothing without opportunity.

Offline

#7 2005-03-11 09:05:43

mercy
Member
Registered: 2004-04-24
Posts: 62

Re: gnu c++ and object serialization

#include <iostream>
#include "SDL.h"
#include "SDL_opengl.h"

using namespace std;

typedef struct vertex {
  GLfloat x;
  GLfloat y;
  GLfloat z;
};

// Main
int main(int argc, char **argv) {

  vertex test;
 
  test.x=1.0f;
  test.y=2.0f;
  test.z=3.0f;

  cout << test.x << " " << test.y << " " << test.z << " " << endl;
 
  exit (0);
}


as far as every book told me...

struct [typename] {
  [typedefinition]
} {variablelist};

so the typename is there -> vertex
typedefinition -> my 3 GLfloat variables

and the keyword typedef (i think) takes care of that the compiler knows later on that it should be treated like every *basic* datatype (like int)

eg.:

vector<vertex> vertexvector;

----------------------------------------

about serialization...

well... im working on a "hobby-project" ... not on a business one

im a system-admin / network-operator .. no programmer - i just have some very basic knowladge of programming techniques and languages (cobol, pl/1,borland-c (ansii-c), borland-c++(ansii-c++), Visual C++ with mfc (just to mention that i did something with it - but just cuz we had to at school - bless god and beer that i forgot everything about it ),  java)

i just started programming again cuz of interest .. basically i wanted to know what im able to do with OpenGL  wink

therefore my intend isnt to finish everything as fast as possible but fiddeling arround and learning roll

Offline

#8 2005-03-11 15:12:18

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: gnu c++ and object serialization

mercy wrote:

as far as every book told me...

struct [typename] {
  [typedefinition]
} {variablelist};

so the typename is there -> vertex
typedefinition -> my 3 GLfloat variables

and the keyword typedef (i think) takes care of that the compiler knows later on that it should be treated like every *basic* datatype (like int)

no, the proper typedef usage is:
typedef [original type] [new type];
and a proper struct definition is:
struct [name] { [data members] };

so, combining the two, you get:
typedef [struct definition] [new name];
or
typedef [name] { [data members] } [new name];

it's a C trick to do this:
typedef struct _vertex { int x,y,z; } vertex;
because under C, to declare a struct variable you must use "struct _vertex"... the typedef just makes it simpler...

under C++ you can do: struct vertex {int x,y,z; }
and use "vertex v;" just fine....

Offline

#9 2005-03-11 16:36:10

mercy
Member
Registered: 2004-04-24
Posts: 62

Re: gnu c++ and object serialization

ah

thx  wink

Offline

#10 2005-03-11 16:56:36

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: gnu c++ and object serialization

mercy wrote:

i guess my next step will be to have a look at some applications for 3D-model-creation (GPL/LGPL'ed ones of course  wink )

Wings3D, ArtOfIllusion, Blender, Equinox3D I find Wings3D to be the most useable, but texturing in it is a pain, I do my models in Wings3D and texturing in AoI.

Blender is the gimp of 3D, it does everything. Equinox3D looks interesting, I haven't tried it yet.

I don't know what your application is, but you might be interested in using Python instead of C++; it has pickling for easy serialization, and the Soya3D API is about as easy to use a 3D API as you can get. Another option I might slip in is Java, which also has serialization and Java3D, a SceneGraphAPI and JOGL, a direct OpenGL layer. Python programs seem to have a lower framerate, but is easier to use. Java with JOGL is said to be about equivalent in speed to OpenGL. Java with Java3D is somewhere in between.

Dusty

Offline

#11 2005-03-11 23:27:50

mercy
Member
Registered: 2004-04-24
Posts: 62

Re: gnu c++ and object serialization

Thx a lot for those hints! ... i'll google em asap!  wink

I already had a look at blender... it seems to be a REALY powerfull app but its *mainly* a renderer ... i saw that there are scripts to export .blender files to something else.. like OBJ or 3DS, MD3,4,5...

but couldnt figure out yet *how* or even if those scripts come with the arch pgk ... just read in posts that they exist .. (but i found a API-Docu for *Blender-scripting*...)

what id like to have would be a GPL'ed/OS/FREE 3D-Model-creator able to export to common 3D-Model-file formats
till now all i googeled about where win32 apps ... some free.. most commercial (starting at 1.000 Euro)

as you maybe already guessed ... "common file format" according to games  wink

my intend with this *Project* is to code a game ...

maybe you know Master of Orion 2, Birth of Federation, (guess) civilization,...

Offline

#12 2005-03-11 23:40:44

mercy
Member
Registered: 2004-04-24
Posts: 62

Re: gnu c++ and object serialization

about Phyton/Java ...

uhm.. well... i can't say anything about Phyton... never *saw* it.. just heard the name often...

and java.. well.. from the very first moment up to now i simply [personal opinion]DON'T LIKE IT[/personal opinion] ... not even one piece of it... i can't really point at something why i don't like it

but my main-reason why i don't wanna switch is: i started to "use/learn" SDL and OpenGL some time ago... i had a look at the tutorials(mostly NeHe)... but after some while it got boring to simply draw rotating/blitted thingies flying arround on the screen... also i liked to play Master of Orion 2... so why not combine those to and code a OpenGL/SDL game following the principle of MoO  wink

(no i dont think that i will ever finish it... i have too much ideas/too less knowledge and time  wink )

and as i already said ... i do it as a hobby and for further education  smile

Offline

#13 2005-03-11 23:45:12

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: gnu c++ and object serialization

Blender isn't really just for rendering. It can do everything... hard beast to tame though.

I'm pretty sure Blender has scripts to export to more formats than anything. I even found one that exported directly to Java3D. If that's supported, anything is. Soya3D uses Cal3D files, which include animations and such all in the same file and you can call them, might be a useful format for a game because you don't have to write animations either (Soya was designed for gaming -- slune for example).

Wings3D exports to a handful of modeling formats. You'll want to choose only one format in the end because you don't want to have to write a file-format loader for every single format out there. wink

Dusty

Offline

Board footer

Powered by FluxBB