Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] Sending user data to serialize()?
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2009-02-04 16:17:37


Robert Dailey wrote:
> Hi,
>
> I have a complex case I'm trying to work with. I may be doing this
> completely wrong so if there is a better design for this I'm always
> open for that. However for now I'm going to assume my particular
> problem can be solved.
>
> There exists two classes: A and B. Class A is defined as such:
>
> class A
> {
> public:
> template< typename Archive >
> void load( Archive& archive, unsigned int )
> {
> archive & m_listOfB;
> }
>
> private:
> std::vector<int> m_listOfInt;
> boost::ptr_vector<B> m_listOfB;
> };
>
> And class B is defined roughly as:
>
> class B
> {
> public:
> template< typename Archive >
> void load( Archive& archive, unsigned int )
> {
> // Code isn't important here
> }
> };
>
> Here's the problem:
>
> For each B that is deserialized by A::load(), I need to pass in a
> reference to m_listOfInt. So, essentially the load() function in B
> would look something like this:
>
> void load( Archive& archive, unsigned int, std::vector<int>& listOfInt )
> {
> }
>
> I was hoping boost.bind could be used somewhere, but I just don't
> see how. One way to solve the problem is to call B::load()
> explicitly with the extra parameter, but I don't think that's an
> appropriate solution. Any ideas on how to solve this? Or perhaps I'm
> trying to solve the wrong problem.

What's wrong with:

> class A
> {
> public:
> template< typename Archive >
> void load( Archive& archive, unsigned int )
> {
> archive & m_listOfInt;
> archive & m_listOfB;
> }
>
> private:
> std::vector<int> m_listOfInt;
> boost::ptr_vector<B> m_listOfB;
> };

I'm guessing that the missing B::load code IS important.

Jeff


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