At this point, the last compilation problem in applying the
boost.serialization library to my application has to do with pointers.
Specifically, its pointers to std::string and char member attributes.
I have other pointer member attributes that compile successfully, but
this point to objects that have serialize methods.
I have attempted use of register_type and am including
"serialization/string.hpp" in the modules that have pointer to string
attributes. These actions were not affective.
As an example of the type of compilation error, when I uncomment the
following attribute's archive attempt:
char *m_pByPointerPrefix;
I get:
/home/jholle/boost_1_32_0/boost/serialization/access.hpp: In static
member function `static void
boost::serialization::access::serialize(Archive&, T&, unsigned int)
[with Archive = boost::archive::binary_iarchive, T = char]':
/home/jholle/boost_1_32_0/boost/serialization/serialization.hpp:78:
instantiated from `void boost::serialization::serialize(Archive&, T&,
unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]'
/home/jholle/boost_1_32_0/boost/serialization/serialization.hpp:121:
instantiated from `void boost::serialization::serialize_adl(Archive&,
T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T =
char]'
/home/jholle/boost_1_32_0/boost/archive/detail/iserializer.hpp:155:
instantiated from `void boost::archive::detail::iserializer
"Jeffrey Holle"
At this point, the last compilation problem in applying the boost.serialization library to my application has to do with pointers.
Specifically, its pointers to std::string and char member attributes.
...
What is the solution to this?
From a reply by Robert on the development thread:
"Hmmm - let me consider this. My view is based on the test test_list_ptr which serializes a list of pointers. In this case each list element is tracked because its a pointer. when a pointer is de-serialized a second time, tracking assures that the pointer is reloaded. In your case - std::string is tracked on output. When it its serialized a second time, only the object ID is written out. So when it is read back in the second time, the serialization system recognizes that its a copy and just reloads it. This only gotcha is that most primitive types are not tracked by default. and std::string has been assigned a serialization trait of "primitive" that means don't track. So I believe that this would work for non-primitive types. If you need this to work for a primitive type (e.g. int, or...) use a serialization wrapper." So it sounds like you'll need to turn on Object Tracking for these types at a minimum, or creates appropriate wrappers. Jeff Flinn
pointers to primitive objects are not serializable by default. This is
explained in the document which describes serialization traits. The reason
for this is
a) suppose one place in the program I serialization a pointer to a float.
Then addresses of ALLL the floats in the program would end up being
seriailzed which is probably not what one wants.
The solution is to make a wrapper so the the type has its own class
BOOST_STRONG_TYPEDEF(float, tracked_float)
Then use a tracked_float instead of a normal float where you want to
serialize it through a pointer.
Note that strings and characters are both considered primitive types in this
context - I just used float as an example.
This is the second time this question has come up so I guess we need to
augment the manual and/or include another static assertion in the code.
Good Luck - hope this his helpful
Robert Ramey
"Jeffrey Holle"
At this point, the last compilation problem in applying the boost.serialization library to my application has to do with pointers.
Specifically, its pointers to std::string and char member attributes.
I have other pointer member attributes that compile successfully, but this point to objects that have serialize methods.
I have attempted use of register_type and am including "serialization/string.hpp" in the modules that have pointer to string attributes. These actions were not affective.
As an example of the type of compilation error, when I uncomment the following attribute's archive attempt: char *m_pByPointerPrefix; I get:
/home/jholle/boost_1_32_0/boost/serialization/access.hpp: In static member function `static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]': /home/jholle/boost_1_32_0/boost/serialization/serialization.hpp:78: instantiated from `void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]' /home/jholle/boost_1_32_0/boost/serialization/serialization.hpp:121: instantiated from `void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]' /home/jholle/boost_1_32_0/boost/archive/detail/iserializer.hpp:155: instantiated from `void boost::archive::detail::iserializer
::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::binary_iarchive, T = char]' VariableName.cpp:102: instantiated from here /home/jholle/boost_1_32_0/boost/serialization/access.hpp:106: error: request for member `serialize' in `t', which is of non-class type `char' What is the solution to this?
Just how am I supposed to use a BOOST_STRONG_TYPEDEF produced type? If I make it the type of the class attribute, I get an error everywhere that I use it. Usage examples would be helpful. For instance, what does: m_pByPointerPrefix = new char[strlen(src.m_pByPointerPrefix)+1]; need to be turned into when m_pByPointerPrefix goes from a "char" to tracked_char"? If I only need to introduce tracked_char in the serialize methods, I need examples of doing this too... Robert Ramey wrote:
pointers to primitive objects are not serializable by default. This is explained in the document which describes serialization traits. The reason for this is
a) suppose one place in the program I serialization a pointer to a float. Then addresses of ALLL the floats in the program would end up being seriailzed which is probably not what one wants.
The solution is to make a wrapper so the the type has its own class
BOOST_STRONG_TYPEDEF(float, tracked_float)
Then use a tracked_float instead of a normal float where you want to serialize it through a pointer.
Note that strings and characters are both considered primitive types in this context - I just used float as an example.
This is the second time this question has come up so I guess we need to augment the manual and/or include another static assertion in the code.
Good Luck - hope this his helpful
Robert Ramey
"Jeffrey Holle"
wrote in message news:coqcn7$uhv$1@sea.gmane.org... At this point, the last compilation problem in applying the boost.serialization library to my application has to do with pointers.
Specifically, its pointers to std::string and char member attributes.
I have other pointer member attributes that compile successfully, but this point to objects that have serialize methods.
I have attempted use of register_type and am including "serialization/string.hpp" in the modules that have pointer to string attributes. These actions were not affective.
As an example of the type of compilation error, when I uncomment the following attribute's archive attempt: char *m_pByPointerPrefix; I get:
/home/jholle/boost_1_32_0/boost/serialization/access.hpp: In static member function `static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]': /home/jholle/boost_1_32_0/boost/serialization/serialization.hpp:78: instantiated from `void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]' /home/jholle/boost_1_32_0/boost/serialization/serialization.hpp:121: instantiated from `void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]' /home/jholle/boost_1_32_0/boost/archive/detail/iserializer.hpp:155: instantiated from `void boost::archive::detail::iserializer
::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::binary_iarchive, T = char]' VariableName.cpp:102: instantiated from here /home/jholle/boost_1_32_0/boost/serialization/access.hpp:106: error: request for member `serialize' in `t', which is of non-class type `char' What is the solution to this?
Just how am I supposed to use a BOOST_STRONG_TYPEDEF produced type? If I make it the type of the class attribute, I get an error everywhere that I use it. Usage examples would be helpful. For instance, what does: m_pByPointerPrefix = new char[strlen(src.m_pByPointerPrefix)+1]; need to be turned into when m_pByPointerPrefix goes from a "char" to tracked_char"?
If I only need to introduce tracked_char in the serialize methods, I need examples of doing this too...
Robert Ramey wrote:
pointers to primitive objects are not serializable by default. This is explained in the document which describes serialization traits. The reason for this is
a) suppose one place in the program I serialization a pointer to a float. Then addresses of ALLL the floats in the program would end up being seriailzed which is probably not what one wants.
The solution is to make a wrapper so the the type has its own class
BOOST_STRONG_TYPEDEF(float, tracked_float)
Then use a tracked_float instead of a normal float where you want to serialize it through a pointer.
Note that strings and characters are both considered primitive types in
OK, I'll add some examples to the manual.
Robert Ramey
"Jeffrey Holle"
context - I just used float as an example.
This is the second time this question has come up so I guess we need to augment the manual and/or include another static assertion in the code.
Good Luck - hope this his helpful
Robert Ramey
"Jeffrey Holle"
wrote in message news:coqcn7$uhv$1@sea.gmane.org... At this point, the last compilation problem in applying the boost.serialization library to my application has to do with pointers.
Specifically, its pointers to std::string and char member attributes.
I have other pointer member attributes that compile successfully, but this point to objects that have serialize methods.
I have attempted use of register_type and am including "serialization/string.hpp" in the modules that have pointer to string attributes. These actions were not affective.
As an example of the type of compilation error, when I uncomment the following attribute's archive attempt: char *m_pByPointerPrefix; I get:
/home/jholle/boost_1_32_0/boost/serialization/access.hpp: In static member function `static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]': /home/jholle/boost_1_32_0/boost/serialization/serialization.hpp:78: instantiated from `void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]' /home/jholle/boost_1_32_0/boost/serialization/serialization.hpp:121: instantiated from `void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]' /home/jholle/boost_1_32_0/boost/archive/detail/iserializer.hpp:155: instantiated from `void boost::archive::detail::iserializer
::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::binary_iarchive, T = char]' VariableName.cpp:102: instantiated from here /home/jholle/boost_1_32_0/boost/serialization/access.hpp:106: error: request for member `serialize' in `t', which is of non-class type `char' What is the solution to this?
Just how am I supposed to use a BOOST_STRONG_TYPEDEF produced type? If I make it the type of the class attribute, I get an error everywhere that I use it. Usage examples would be helpful. For instance, what does: m_pByPointerPrefix = new char[strlen(src.m_pByPointerPrefix)+1]; need to be turned into when m_pByPointerPrefix goes from a "char" to tracked_char"?
If I only need to introduce tracked_char in the serialize methods, I need examples of doing this too...
Robert Ramey wrote:
pointers to primitive objects are not serializable by default. This is explained in the document which describes serialization traits. The reason for this is
a) suppose one place in the program I serialization a pointer to a float. Then addresses of ALLL the floats in the program would end up being seriailzed which is probably not what one wants.
The solution is to make a wrapper so the the type has its own class
BOOST_STRONG_TYPEDEF(float, tracked_float)
Then use a tracked_float instead of a normal float where you want to serialize it through a pointer.
Note that strings and characters are both considered primitive types in
OK
Heres the short explanation using float as an example:
Its not a great idea to set the tracking trait for float to tracking because
you'll end up tracking ALL the floats int the archive.
So you make a very small class that just contains a float. That as wrapper
class. This is to function just like a float except that it has a different
class. So it will have the default serialization trace assigned since its
not a primitive. This means it will be tracked by default.
struct tracked_float {
float m_float; // the real data
template<class Archive>
void serialize(Archive &ar, unsigned int version){
ar & m_float;
}
// casting operators - not compiled
float operator float () const {
return m_float;
}
float & operator float() {
return m_float;
}
};
Now just use tracked_float for those floats you want to serialize through a
pointer and just float for other float variables.
This is more or less equivalent to using
BOOST_STRONG_TYPEDEF(tracked_float, float)
template<class Archive>
void serialize(Archive &ar, tracked_float & tf){
ar & tf.m_float;
}
I don't know if that helps - but there it is.
Robert Ramey
"Jeffrey Holle"
context - I just used float as an example.
This is the second time this question has come up so I guess we need to augment the manual and/or include another static assertion in the code.
Good Luck - hope this his helpful
Robert Ramey
"Jeffrey Holle"
wrote in message news:coqcn7$uhv$1@sea.gmane.org... At this point, the last compilation problem in applying the boost.serialization library to my application has to do with pointers.
Specifically, its pointers to std::string and char member attributes.
I have other pointer member attributes that compile successfully, but this point to objects that have serialize methods.
I have attempted use of register_type and am including "serialization/string.hpp" in the modules that have pointer to string attributes. These actions were not affective.
As an example of the type of compilation error, when I uncomment the following attribute's archive attempt: char *m_pByPointerPrefix; I get:
/home/jholle/boost_1_32_0/boost/serialization/access.hpp: In static member function `static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]': /home/jholle/boost_1_32_0/boost/serialization/serialization.hpp:78: instantiated from `void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]' /home/jholle/boost_1_32_0/boost/serialization/serialization.hpp:121: instantiated from `void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]' /home/jholle/boost_1_32_0/boost/archive/detail/iserializer.hpp:155: instantiated from `void boost::archive::detail::iserializer
::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::binary_iarchive, T = char]' VariableName.cpp:102: instantiated from here /home/jholle/boost_1_32_0/boost/serialization/access.hpp:106: error: request for member `serialize' in `t', which is of non-class type `char' What is the solution to this?
"Robert Ramey"
OK
Heres the short explanation using float as an example:
Its not a great idea to set the tracking trait for float to tracking because you'll end up tracking ALL the floats int the archive.
So you make a very small class that just contains a float. That as wrapper class. This is to function just like a float except that it has a different class. So it will have the default serialization trace assigned since its not a primitive. This means it will be tracked by default.
struct tracked_float { float m_float; // the real data template<class Archive> void serialize(Archive &ar, unsigned int version){ ar & m_float; } // casting operators - not compiled float operator float () const { return m_float; } float & operator float() { return m_float; } };
Now just use tracked_float for those floats you want to serialize through a
Does 'just use' mean that one would now need to replace all occurrences of float* data members with tracked_float*'s? As in: class with_float_ptr { tracked_float* m_tracked_float_ptr; ... template<class Archive> void serialize(Archive &ar, const unsigned int version ) { ar & m_tracked_float_ptr; } }; Or is there a less intrusive manner? I'm just curious, as there are no raw pointers in anything that I've yet needed to serialize.
pointer and just float for other float variables.
This is more or less equivalent to using
BOOST_STRONG_TYPEDEF(tracked_float, float)
template<class Archive> void serialize(Archive &ar, tracked_float & tf){ ar & tf.m_float; }
I don't know if that helps - but there it is.
Jeff
Does 'just use' mean that one would now need to replace all occurrences of float* data members with tracked_float*'s? As in:
All the ones you want to serialize as a pointer.
I expect there is another method which is less intrusive, but I would have
to think about it.
Robert Ramey
"Jeff Flinn"
"Robert Ramey"
wrote in message news:coqoda$2t4$1@sea.gmane.org... OK
Heres the short explanation using float as an example:
Its not a great idea to set the tracking trait for float to tracking because you'll end up tracking ALL the floats int the archive.
So you make a very small class that just contains a float. That as wrapper class. This is to function just like a float except that it has a different class. So it will have the default serialization trace assigned since
not a primitive. This means it will be tracked by default.
struct tracked_float { float m_float; // the real data template<class Archive> void serialize(Archive &ar, unsigned int version){ ar & m_float; } // casting operators - not compiled float operator float () const { return m_float; } float & operator float() { return m_float; } };
Now just use tracked_float for those floats you want to serialize
its through
a
Does 'just use' mean that one would now need to replace all occurrences of float* data members with tracked_float*'s? As in:
class with_float_ptr { tracked_float* m_tracked_float_ptr;
...
template<class Archive> void serialize(Archive &ar, const unsigned int version ) { ar & m_tracked_float_ptr; }
};
Or is there a less intrusive manner? I'm just curious, as there are no raw pointers in anything that I've yet needed to serialize.
pointer and just float for other float variables.
This is more or less equivalent to using
BOOST_STRONG_TYPEDEF(tracked_float, float)
template<class Archive> void serialize(Archive &ar, tracked_float & tf){ ar & tf.m_float; }
I don't know if that helps - but there it is.
Jeff
Following your instructions, I did get success dealing with pointers to std::string. The attached file is what works for me. The main additions involved making it a good C++ citizen. Robert Ramey wrote:
OK
Heres the short explanation using float as an example:
Its not a great idea to set the tracking trait for float to tracking because you'll end up tracking ALL the floats int the archive.
So you make a very small class that just contains a float. That as wrapper class. This is to function just like a float except that it has a different class. So it will have the default serialization trace assigned since its not a primitive. This means it will be tracked by default.
struct tracked_float { float m_float; // the real data template<class Archive> void serialize(Archive &ar, unsigned int version){ ar & m_float; } // casting operators - not compiled float operator float () const { return m_float; } float & operator float() { return m_float; } };
Now just use tracked_float for those floats you want to serialize through a pointer and just float for other float variables.
This is more or less equivalent to using
BOOST_STRONG_TYPEDEF(tracked_float, float)
template<class Archive> void serialize(Archive &ar, tracked_float & tf){ ar & tf.m_float; }
I don't know if that helps - but there it is.
Robert Ramey
"Jeffrey Holle"
wrote in message news:coqlem$mvg$1@sea.gmane.org... Just how am I supposed to use a BOOST_STRONG_TYPEDEF produced type? If I make it the type of the class attribute, I get an error everywhere that I use it. Usage examples would be helpful. For instance, what does: m_pByPointerPrefix = new char[strlen(src.m_pByPointerPrefix)+1]; need to be turned into when m_pByPointerPrefix goes from a "char" to tracked_char"?
If I only need to introduce tracked_char in the serialize methods, I need examples of doing this too...
Robert Ramey wrote:
pointers to primitive objects are not serializable by default. This is explained in the document which describes serialization traits. The
reason
for this is
a) suppose one place in the program I serialization a pointer to a
float.
Then addresses of ALLL the floats in the program would end up being seriailzed which is probably not what one wants.
The solution is to make a wrapper so the the type has its own class
BOOST_STRONG_TYPEDEF(float, tracked_float)
Then use a tracked_float instead of a normal float where you want to serialize it through a pointer.
Note that strings and characters are both considered primitive types in
this
context - I just used float as an example.
This is the second time this question has come up so I guess we need to augment the manual and/or include another static assertion in the code.
Good Luck - hope this his helpful
Robert Ramey
"Jeffrey Holle"
wrote in message news:coqcn7$uhv$1@sea.gmane.org... At this point, the last compilation problem in applying the boost.serialization library to my application has to do with pointers.
Specifically, its pointers to std::string and char member attributes.
I have other pointer member attributes that compile successfully, but this point to objects that have serialize methods.
I have attempted use of register_type and am including "serialization/string.hpp" in the modules that have pointer to string attributes. These actions were not affective.
As an example of the type of compilation error, when I uncomment the following attribute's archive attempt: char *m_pByPointerPrefix; I get:
/home/jholle/boost_1_32_0/boost/serialization/access.hpp: In static member function `static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]': /home/jholle/boost_1_32_0/boost/serialization/serialization.hpp:78: instantiated from `void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T =
char]'
/home/jholle/boost_1_32_0/boost/serialization/serialization.hpp:121: instantiated from `void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = char]' /home/jholle/boost_1_32_0/boost/archive/detail/iserializer.hpp:155: instantiated from `void boost::archive::detail::iserializer
::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::binary_iarchive, T = char]' VariableName.cpp:102: instantiated from here /home/jholle/boost_1_32_0/boost/serialization/access.hpp:106: error: request for member `serialize' in `t', which is of non-class type `char' What is the solution to this?
participants (3)
-
Jeff Flinn
-
Jeffrey Holle
-
Robert Ramey