Discussion:
Serialization (Load/Save from file)
(too old to reply)
Ori Lahav
2009-04-17 13:51:38 UTC
Permalink
Hello wxUsers,
I'm pretty sure this question was asked a few times, but I can't find any
useful answer. I'm working on an option to save and load the project. I have
two problems with it:
1. (De)Serializing basic types (int, ...): How do I serialize them, and how
do I make it portable? I know there is a problem with byte order
(Big-Endian, Little-Endian).
2. wxObjects (wxString, wxSize, ...): How do I serialize wxString? Do I have
to create a function for each wxWidgets object (e.g. serialize the
wxSize.Width and Height separately)? And what about the other classes?

Thanks!
Ori.
Iulian-Nicu Șerbănoiu
2009-04-17 14:23:38 UTC
Permalink
Using a text based format spares you of all the Big/Little endian issues.
Lately files are saved usually in an XML format ... but it depends on what
you want to do.

If you want to go binary I suggest:

1. using the network byte order for portability of code (use nthos, nthol
that are available on every platform).
2. using one byte order you like (big/little endian) and use these macros -
http://docs.wxwidgets.org/trunk/group__group__funcmacro__byteorder.html

You can also have a look at XDR:
http://en.wikipedia.org/wiki/External_Data_Representation

In case of wxObjects ... you should have to serialize them yourself (I don't
think there are such functions inside wx like they are in Java).

My suggestion would be to go with the XML option, especially because there
are a lot of parsers out there which are already tested are ready for use.
Reinventing the wheel is not an option right now, but then again it depends
on what you're trying to do.

HTH,

Iulian
Post by Ori Lahav
Hello wxUsers,
I'm pretty sure this question was asked a few times, but I can't find any
useful answer. I'm working on an option to save and load the project. I have
1. (De)Serializing basic types (int, ...): How do I serialize them, and how
do I make it portable? I know there is a problem with byte order
(Big-Endian, Little-Endian).
2. wxObjects (wxString, wxSize, ...): How do I serialize wxString? Do I
have to create a function for each wxWidgets object (e.g. serialize the
wxSize.Width and Height separately)? And what about the other classes?
Thanks!
Ori.
_______________________________________________
wx-users mailing list
http://lists.wxwidgets.org/mailman/listinfo/wx-users
Krishna
2009-04-17 15:29:15 UTC
Permalink
On Fri, Apr 17, 2009 at 7:53 PM, Iulian-Nicu Șerbănoiu
Post by Iulian-Nicu Șerbănoiu
...
http://en.wikipedia.org/wiki/External_Data_Representation
Many years ago I stumbled across UBF. It's a lightweight and legible
format and comes from the Erlang world. Full specs are available at
http://www.sics.se/~joe/ubf/site/home.html .

Cheers,
--Krishna
--
I love deadlines. I like the whooshing sound
they make as they fly by.
-- Douglas Adams
Jonathan Liu
2009-04-18 06:35:09 UTC
Permalink
Post by Ori Lahav
1. (De)Serializing basic types (int, ...): How do I serialize them, and
how do I make it portable? I know there is a problem with byte order
(Big-Endian, Little-Endian).
Using a text-based format like XML is usually the way to go with this.
Post by Ori Lahav
2. wxObjects (wxString, wxSize, ...): How do I serialize wxString? Do I
have to create a function for each wxWidgets object (e.g. serialize the
wxSize.Width and Height separately)? And what about the other classes?
I use the Boost serialisation libraries for this -
http://www.boost.org/doc/libs/release/libs/serialization/.

I have created wrappers classes to allow using wxWidgets streams with
any library that supports standard streams -
http://trac.wxwidgets.org/ticket/10637.

wxString can be serialised by converting to UTF-8 bytes stored in a
std::string. Boost can then serialise this as it supports std::string
natively. You need to create a serialiser for each class you want to
serialise/deserialise as per serialisation library documentation.

Regards,
Jonathan
M Nealon
2009-04-18 14:06:40 UTC
Permalink
Post by Ori Lahav
Hello wxUsers,
I'm pretty sure this question was asked a few times, but I can't find any
useful answer. I'm working on an option to save and load the project. I have
1. (De)Serializing basic types (int, ...): How do I serialize them, and how
do I make it portable? I know there is a problem with byte order
(Big-Endian, Little-Endian).
2. wxObjects (wxString, wxSize, ...): How do I serialize wxString? Do I
have to create a function for each wxWidgets object (e.g. serialize the
wxSize.Width and Height separately)? And what about the other classes?
Thanks!
Ori.
Perhaps you might be satisfied with one of these ready made options

wxSerializer http://www.xs4all.nl/~jorgb/wb/MyProjects/wxSerialize.html
wxXmlSerializer http://wxcode.sourceforge.net/components/wxxs/

Either one might be sufficient for your use.

Best regards
Mal
--
Follow the development of my screenplay authoring program at
http://wxscreenplaywriter.blogspot.com/
Mark Gollahon
2009-04-21 18:19:24 UTC
Permalink
wxSerializer is actually found at:

http://www.xs4all.nl/~jorgb/wb/wxwidgets/wxserialize/index.html
Post by Ori Lahav
Hello wxUsers,
I'm pretty sure this question was asked a few times, but I
can't find any useful answer. I'm working on an option to save
1. (De)Serializing basic types (int, ...): How do I serialize
them, and how do I make it portable? I know there is a problem
with byte order (Big-Endian, Little-Endian).
2. wxObjects (wxString, wxSize, ...): How do I serialize
wxString? Do I have to create a function for each wxWidgets
object (e.g. serialize the wxSize.Width and Height
separately)? And what about the other classes?
Thanks!
Ori.
Perhaps you might be satisfied with one of these ready made options
wxSerializer
http://www.xs4all.nl/~jorgb/wb/MyProjects/wxSerialize.html
wxXmlSerializer http://wxcode.sourceforge.net/components/wxxs/
Either one might be sufficient for your use.
Best regards
Mal
--
Follow the development of my screenplay authoring program at
http://wxscreenplaywriter.blogspot.com/
_______________________________________________
wx-users mailing list
http://lists.wxwidgets.org/mailman/listinfo/wx-users
M Nealon
2009-04-21 19:31:44 UTC
Permalink
Post by Mark Gollahon
http://www.xs4all.nl/~jorgb/wb/wxwidgets/wxserialize/index.html
Yep, my bad. Old link I think?

Best regards
Mal
--
Follow the development of my screenplay authoring program at
http://wxscreenplaywriter.blogspot.com/
Iulian-Nicu Șerbănoiu
2009-04-21 19:45:11 UTC
Permalink
Why isn't this in the wxWidgets official package?
I find it extremely useful.

Regards,

Iulian
http://www.xs4all.nl/~jorgb/wb/wxwidgets/wxserialize/index.html<http://www.xs4all.nl/%7Ejorgb/wb/wxwidgets/wxserialize/index.html>
Post by Ori Lahav
Hello wxUsers,
I'm pretty sure this question was asked a few times, but I
can't find any useful answer. I'm working on an option to save
1. (De)Serializing basic types (int, ...): How do I serialize
them, and how do I make it portable? I know there is a problem
with byte order (Big-Endian, Little-Endian).
2. wxObjects (wxString, wxSize, ...): How do I serialize
wxString? Do I have to create a function for each wxWidgets
object (e.g. serialize the wxSize.Width and Height
separately)? And what about the other classes?
Thanks!
Ori.
Perhaps you might be satisfied with one of these ready made options
wxSerializer
http://www.xs4all.nl/~jorgb/wb/MyProjects/wxSerialize.html<http://www.xs4all.nl/%7Ejorgb/wb/MyProjects/wxSerialize.html>
wxXmlSerializer http://wxcode.sourceforge.net/components/wxxs/
Either one might be sufficient for your use.
Best regards
Mal
--
Follow the development of my screenplay authoring program at
http://wxscreenplaywriter.blogspot.com/
_______________________________________________
wx-users mailing list
http://lists.wxwidgets.org/mailman/listinfo/wx-users
_______________________________________________
wx-users mailing list
http://lists.wxwidgets.org/mailman/listinfo/wx-users
Mark Gollahon
2009-04-21 20:25:30 UTC
Permalink
Naw, he has that link on his wxwidgets/index.html page. I had to go
searching his website's virtual directories to find a page with the
correct link on it.

However, what it boils down to is that wxSerialize is better for binary
serialization and wxXS is better for XML serialization. (Too bad we
don't have a pluggable serialization with different "back ends" for
binary and XML. That'd be pretty cool....)
Post by Mark Gollahon
http://www.xs4all.nl/~jorgb/wb/wxwidgets/wxserialize/index.html
Yep, my bad. Old link I think?
Best regards
Mal
--
Follow the development of my screenplay authoring program at
http://wxscreenplaywriter.blogspot.com/
_______________________________________________
wx-users mailing list
http://lists.wxwidgets.org/mailman/listinfo/wx-users
Brian Ravnsgaard Riis
2009-04-22 06:04:44 UTC
Permalink
Post by Mark Gollahon
Naw, he has that link on his wxwidgets/index.html page. I had to go
searching his website's virtual directories to find a page with the
correct link on it.
However, what it boils down to is that wxSerialize is better for binary
serialization and wxXS is better for XML serialization. (Too bad we
don't have a pluggable serialization with different "back ends" for
binary and XML. That'd be pretty cool....)
Boost.Serialization. :-) Serialization of the object is orthogonal to
the "package" (called "archive") the serialized data gets put into.
Boost.Serialization has builtin support for both plain text and XML.

/Brian
Mark Gollahon
2009-04-22 13:25:48 UTC
Permalink
OOooooo, ask and it shall be answered.... :) Cool.... Thanks!!!
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Mark Gollahon
Naw, he has that link on his wxwidgets/index.html page. I had to go
searching his website's virtual directories to find a page with the
correct link on it.
However, what it boils down to is that wxSerialize is better for binary
serialization and wxXS is better for XML serialization. (Too bad we
don't have a pluggable serialization with different "back ends" for
binary and XML. That'd be pretty cool....)
Boost.Serialization. :-) Serialization of the object is orthogonal to
the "package" (called "archive") the serialized data gets put into.
Boost.Serialization has builtin support for both plain text and XML.
/Brian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFJ7rN8k1tAOprY6QERAufsAKCAwdJaMmxIZHJGxOHFuVAYzrZ/FQCgpJTo
DHXZh6MqD4kgcOVZ9+8qK6k=
=3Ns/
-----END PGP SIGNATURE-----
_______________________________________________
wx-users mailing list
http://lists.wxwidgets.org/mailman/listinfo/wx-users
Ori Lahav
2009-05-03 13:29:54 UTC
Permalink
Thanks a lot for the suggestions! I'll begin experimenting with these
libraries.

Ori.
Post by Mark Gollahon
OOooooo, ask and it shall be answered.... :) Cool.... Thanks!!!
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Mark Gollahon
Naw, he has that link on his wxwidgets/index.html page. I had to go
searching his website's virtual directories to find a page with the
correct link on it.
However, what it boils down to is that wxSerialize is better for binary
serialization and wxXS is better for XML serialization. (Too bad we
don't have a pluggable serialization with different "back ends" for
binary and XML. That'd be pretty cool....)
Boost.Serialization. :-) Serialization of the object is orthogonal to
the "package" (called "archive") the serialized data gets put into.
Boost.Serialization has builtin support for both plain text and XML.
/Brian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFJ7rN8k1tAOprY6QERAufsAKCAwdJaMmxIZHJGxOHFuVAYzrZ/FQCgpJTo
DHXZh6MqD4kgcOVZ9+8qK6k=
=3Ns/
-----END PGP SIGNATURE-----
_______________________________________________
wx-users mailing list
http://lists.wxwidgets.org/mailman/listinfo/wx-users
_______________________________________________
wx-users mailing list
http://lists.wxwidgets.org/mailman/listinfo/wx-users
Continue reading on narkive:
Loading...