SFML community forums
Help => General => Topic started by: kaB00M on November 25, 2011, 08:06:52 am
-
So I can serialize classes compose of simple type, but can sfml classes be serialized?
-
If you mean "directly" (with memcpy of whatever), then no. But even simple types can't be serialized directly anyway, you always have to do it manually in order to avoid problems with type sizes of endianness. So it doesn't really matter if it's a complex or simple type, you have to write the serialization rules anyway.
hint: use boost.serialize
-
I'm using ofstream and ifstream.
As always, thank you.
-
I'm using ofstream and ifstream
It's not a serialization interface, it just provides raw read/write. It doesn't help for types sizes and endianness. You should really use something dedicated to this task.
-
Maybe this will help:
http://www.boost.org/doc/libs/1_48_0/libs/serialization/doc/index.html
-
Maybe this will help:
http://www.boost.org/doc/libs/1_48_0/libs/serialization/doc/index.html
I tried to use serialization with boost, but the simplest way to implement it in your program is to modify sfml code itself. I think there's a complex way to do serialization without modify sfml code, but IMO it doesn't worth it.
I suggest to use xml instead.
I use tinyxml lib to save/load my sfml objects. :)
-
I tried to use serialization with boost, but the simplest way to implement it in your program is to modify sfml code itself. I think there's a complex way to do serialization without modify sfml code
Everything that is relevant to serialize is public, so why would you need to modify SFML itself?
-
I think there's a complex way to do serialization without modify sfml code, but IMO it doesn't worth it.
I don't see why this should be complex, either. Just provide the global function overloads required by Boost.Serialization.
On the opposite, the intrusive solution brings you trouble because your SFML version is incompatible to others, revision updates become complicated etc. I would avoid changing the library itself unless it's really necessary, and in this case it isn't.
-
Everything that is relevant to serialize is public, so why would you need to modify SFML itself?
Probabily it's possible, but I dont know how. :)
So I used xml documents.
I don't see why this should be complex, either. Just provide the global function overloads required by Boost.Serialization.
How can I access a sfml function and override it? With a derived class?
Or maybe I don't understand what you want to mean...
-
Why do you need to override SFML functions? Most of SFML's classes are not designed as base classes. Contrary to languages like Java, C++ doesn't intend inheritance to be the main and only mechanism to extend existing functionality. Alternative approaches are often far more flexible, the STL is a very good example.
Boost.Serialization doesn't enforce class modifications. For a non-intrusive serialization function, look at the documentation (http://www.boost.org/doc/libs/1_48_0/libs/serialization/doc/tutorial.html#nonintrusiveversion). Absolutely no need to modify SFML.
-
Boost.Serialization doesn't enforce class modifications. For a non-intrusive serialization function, look at the documentation (http://www.boost.org/doc/libs/1_48_0/libs/serialization/doc/tutorial.html#nonintrusiveversion). Absolutely no need to modify SFML.
I knew that there was this non-intrusive method, but I preferred xml for simplicity (I've been using it for a while).
Anyway serialization could be my next choice. :)
-
XML is serialization. It's just an output format -- other formats could be binary data, JSON, INI, ...
With a well designed library (such as boost.serialization) the serialization functions and the output format are completely separated. You only have to write your serialization functions once, in a generic way, and then you can output the result to many different formats.
-
XML is serialization. It's just an output format -- other formats could be binary data, JSON, INI, ...
With a well designed library (such as boost.serialization) the serialization functions and the output format are completely separated. You only have to write your serialization functions once, in a generic way, and then you can output the result to many different formats.
Your remark is fully correct!
In my previous post with "serialization" I mean binary serialization, and with "using xml" I mean "using xml serialization without boost" :)