Boost logo

Boost Users :

Subject: Re: [Boost-users] Serialization on boost::dynamic bitset
From: Gokulakannan Somasundaram (gokul007_at_[hidden])
Date: 2009-07-15 14:05:30


Can someone verify whether my code is appropriate?

#include <vector>

#include <ace/Basic_Types.h>
#include <boost/dynamic_bitset.hpp>

class Bitmapset
{
private:
    friend class boost::serialization::access;

    template<class Archive>
    void load(Archive& ar, const unsigned int version);

    template<class Archive>
    void save(Archive& ar, const unsigned int version) const;

    BOOST_SERIALIZATION_SPLIT_MEMBER()

    friend std::ostream& operator<<(std::ostream& os, const Bitmapset&
node);

private:
    boost::dynamic_bitset<ACE_UINT32> m_bits;
}

template<class Archive>
void Bitmapset::save(Archive & ar, const unsigned int version) const
{
    std::vector<ACE_UINT32> blocks;
    boost::to_block_range<ACE_UINT32>(m_bits, blocks.begin());
    ar & blocks;
}

template<class Archive>
void Bitmapset::load(Archive & ar, const unsigned int version)
{
    std::vector<ACE_UINT32> blocks;
    ar & blocks;
    boost::from_block_range<ACE_UINT32>( blocks.begin(), blocks.end(),
m_bits);

}

Thanks,
Gokul.

On Sat, Jul 11, 2009 at 2:14 PM, Gokulakannan Somasundaram <
gokul007_at_[hidden]> wrote:

> Hi,
> I have to write code for serialization of dynamic bitset. I could well
> write the code by iterating through the bitset, but i was just wondering,
> why it is not provided as part of the library.
>
>
> Thanks,
> Gokul.
>



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