|
Boost Users : |
Subject: Re: [Boost-users] Problems using boost serializing andcustomconstructors
From: Robert Ramey (ramey_at_[hidden])
Date: 2012-03-12 17:05:16
Allan Nielsen wrote:
> Hi
>
>> This whole thing looks a little suspicious to me.
> Well, it is most likely because I;m doing it completely wrong ;)
> Please correct me.
>
>> I'd have to spend considerable time looking into it. But I'm curious
>> why you don't just do the following:
>>
>> template<class Archive>
>> void save(Archive &ar, const unsigned int version) const {
>> ar << data;
>> }
>>
>> template<class Archive>
>> void load(Archive &ar, const unsigned int version){
>> ar >> data;
>> }
>>
>
> Because I have a shared pointer, and ( for other reasons ) I do not
> want to use "shared_ptr"
hmmm- I assume you are aware that you can serialize a shared_ptr.
>
> So, a simplified version of my problem could look like this:
>
> struct A {
> std::vector<unsigned> data;
> };
>
> struct B {
> const std::vector<unsigned> * data_ptr;
> };
>
> struct C {
> A a;
> std::vector<B> elements;
> };
>
> What would a serializing function for A, B and C look like.
// external version
template<class Archive>
void serialize(Archive &ar, A & a, const unsigned int version){
ar & data;;
}
template<class Archive>
void serialize(Archive &ar, B & b, const unsigned int version){
ar & data_ptr;;
}
template<class Archive>
void serialize(Archive &ar, C & c, const unsigned int version){
ar & a;
ar & elements;
}
Robert Ramey
>
> Best regards
> Allan W. Nielsen
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net