Boost logo

Boost Users :

From: christophe loustaunau (christophe.loustaunau_at_[hidden])
Date: 2008-02-14 02:40:07


Hello,

Recently I have used Boost for serialization. Unfortunatly it doesn't work
with
hash_map. I work with Visual 8, and Visual 8 used the dinkumware version of
std lib.

In order to make things working I have modified three files of boost :

in the folder config/stdlib :
dinkumware.hpp : BOOST_HAS_HASH is not defined.(why ?).

in the folder serialization :
hash_collections_load_imp.hpp : In this file I have made these changes :

template<class Archive, class Container, class InputFunction>
inline void load_hash_collection(Archive & ar, Container &s)
{
    s.clear();
    // retrieve number of elements
    unsigned int count;
    unsigned int item_version(0);
// unsigned int bucket_count;;
    ar >> BOOST_SERIALIZATION_NVP(count);
// if(3 < ar.get_library_version()){
// ar >> BOOST_SERIALIZATION_NVP(bucket_count);
// ar >> BOOST_SERIALIZATION_NVP(item_version);
// }
// #if ! defined(__MWERKS__)
// s.resize(bucket_count);
// #endif
    InputFunction ifunc;
    while(count-- > 0){
        ifunc(ar, s, item_version);
    }
}

} // namespace stl
} // namespace serialization
} // namespace boost

hash_collections_save_imp.hpp : In this file I have made these changes :

template<class Archive, class Container>
inline void save_hash_collection(Archive & ar, const Container &s)
{
    // record number of elements
    unsigned int count = s.size();
    ar << BOOST_SERIALIZATION_NVP(count);
    // make sure the target type is registered so we can retrieve
    // the version when we load
// if(3 < ar.get_library_version()){
// const unsigned int bucket_count = s.bucket_count();
// ar << BOOST_SERIALIZATION_NVP(bucket_count);
// const unsigned int item_version = version<BOOST_DEDUCED_TYPENAME
Container::value_type>::value;
// ar << BOOST_SERIALIZATION_NVP(item_version);
// }
    BOOST_DEDUCED_TYPENAME Container::const_iterator it = s.begin();
    while(count-- > 0){
        // note borland emits a no-op without the explicit namespace
        boost::serialization::save_construct_data_adl(
            ar,
            &(*it),
            boost::serialization::version<
                BOOST_DEDUCED_TYPENAME Container::value_type
>::value
        );
        ar << boost::serialization::make_nvp("item", *it++);
    }
}

} // namespace stl
} // namespace serialization
} // namespace boost

With this changes Serialization of hash_map works well.
Maybe you could make a :

#if (!defined dinkumware )
.....
# endif
In theses two files in order to make the serialization of hash_map with
dinkumware working.

Thanks for your time and your so good library !

-- 
Christophe Loustaunau.


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