[Boost.Serialization] shared_ptr compile-time error.
Hi,
I receive a compile time error when I try to serialize
shared_ptr<string> in my class. Here are the relevant parts of this class:
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
#include
string is considered a primitive type and therefore not serializable through a pointer. (shared_ptr<string> contains a pointer to a string. Look in the documentation for serialization of pointers. You can address this by wrapping string in another class just for serialization. Robert Ramey Vjekoslav Brajkovic wrote:
Hi,
I receive a compile time error when I try to serialize shared_ptr<string> in my class. Here are the relevant parts of this class:
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
#include
#include #include class chunk_data : public chunk_metadata {
public:
chunk_data(std::string s);
chunk_data( chunk_metadata metadata, boost::shared_ptrstd::string data_ptr);
chunk_data( boost::filesystem::path path, chunk_metadata::cuid_type chunk_id);
chunk_data( boost::filesystem::path path, chunk_metadata::cuid_type chunk_id, boost::shared_ptrstd::string data_ptr);
virtual ~chunk_data();
template <typename Archive> void serialize(Archive& ar, const unsigned int version) { boost::serialization::base_object
(*this); ar & data_ptr_; } boost::shared_ptrstd::string data_ptr_; };
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
And here are the relevant parts from compilation error.
invalid application of â?~sizeofâ?T to incomplete type â?~boost::STATIC_ASSERTION_FAILURE<false>â?T error: â?~struct std::basic_string
â?T has no member named â?~serializeâ?T I haven't found any relevant hints about this error neither in the documentation or on the boost mailing list. Also I've attached the compilation log. I would really appreciate any help.
-Vjeko
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Sat, 2 Aug 2008, Robert Ramey wrote:
string is considered a primitive type and therefore not serializable through a pointer. (shared_ptr<string> contains a pointer to a string. Look in the documentation for serialization of pointers.
You can address this by wrapping string in another class just for serialization.
Thanks Robert. It works now. Also, I've manged to find one of your previous discussions which made things much more clear: http://groups.google.com/group/boost-list/browse_thread/thread/8ebe5d1e00346... -Vjeko
On Sat, Aug 2, 2008 at 9:43 PM, Robert Ramey
string is considered a primitive type and therefore not serializable through a pointer. (shared_ptr<string> contains a pointer to a string. Look in the documentation for serialization of pointers.
You can address this by wrapping string in another class just for serialization.
Forgive my bluntness but is it a good idea for the shared_ptr serialization to be implemented in terms of the T * object contained in a boost::shared_ptr<T>? I mean, for example std::string isn't serialized in terms of the char * object it contains, right? Perhaps more to the point, what plans do we have for serializing std::shared_ptr using boost::serialization? Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
Emil Dotchevski wrote:
it a good idea for the shared_ptr serialization to be implemented in terms of the T * object contained in a boost::shared_ptr<T>?
The whole serialization library is built on that concept. It's the best idea I could come up with.
I mean, for example std::string isn't serialized in terms of the char * object it contains, right?
whether std::string contains a char * is an internal implemention detail. Serialization of std::string does use (If I remember correctly) the function which returns a char * - but maybe not. std::string is not a good example though as it is a special case for a couple of reasons.
Perhaps more to the point, what plans do we have for serializing std::shared_ptr using boost::serialization?
The current implementation of serialization of boost::shared_ptr depends only upon the published public interface of boost::shared_ptr. (personally I have some complaints about that public interface though). Assuming that std::shared_ptr has the same published interface as boost::shared_ptr - I would expect the serialization implemenation would be the same. Robert Ramey
Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
On Tue, Aug 5, 2008 at 5:05 PM, Robert Ramey
Emil Dotchevski wrote:
it a good idea for the shared_ptr serialization to be implemented in terms of the T * object contained in a boost::shared_ptr<T>?
The current implementation of serialization of boost::shared_ptr depends only upon the published public interface of boost::shared_ptr. (personally I have some complaints about that public interface though). Assuming that std::shared_ptr has the same published interface as boost::shared_ptr - I would expect the serialization implemenation would be the same.
Then maybe I misunderstood your earlier reply, that boost::shared_ptrstd::string can't be serialized directly because it contains a std::string pointer. That's why I brought up the pointer stored in std::string, which is an implementation detail indeed, as is the T pointer in boost::shared_ptr<T>. So, why wouldn't shared_ptrstd::string "just work" when serialized, even if serializing std::string raw pointers doesn't? Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
Emil Dotchevski wrote:
On Tue, Aug 5, 2008 at 5:05 PM, Robert Ramey
wrote: Emil Dotchevski wrote:
it a good idea for the shared_ptr serialization to be implemented in terms of the T * object contained in a boost::shared_ptr<T>?
The current implementation of serialization of boost::shared_ptr depends only upon the published public interface of boost::shared_ptr. (personally I have some complaints about that public interface though). Assuming that std::shared_ptr has the same published interface as boost::shared_ptr - I would expect the serialization implemenation would be the same.
Then maybe I misunderstood your earlier reply, that boost::shared_ptrstd::string can't be serialized directly because it contains a std::string pointer. That's why I brought up the pointer stored in std::string, which is an implementation detail indeed, as is the T pointer in boost::shared_ptr<T>.
So, why wouldn't shared_ptrstd::string "just work" when serialized, even if serializing std::string raw pointers doesn't?
well, I suppose it could be "made to work" by internally wrapping it in a special type so it doesn't get treated as a serialization primitive. I would never occur to me to do such a thing though. The strength of the current approach is it's "conceptual integrity". That is shared_ptr<T> is pointer is serializable if and only if T * is serializable. This is much simpler than trying to out smart the programmer by silently fixing things up for him when it can. Robert Ramey
Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
participants (3)
-
Emil Dotchevski
-
Robert Ramey
-
Vjekoslav Brajkovic