Boost logo

Boost Users :

From: Chris Coleman (cqc_at_[hidden])
Date: 2005-08-11 09:17:46


Hello,

We have the same problem in our project. The solution we have arrived
at is:

change "boost/serialization/hash_map.hpp" as below:
//#ifdef __GLIBCPP__
#include <ext/hash_map>
//#else
//#include <hash_map>
//#endif

and add the following lines to: "boost/config/stdlib/libstdcpp3.hpp"
#define BOOST_HAS_HASH
#define BOOST_STD_EXTENSION_NAMESPACE __gnu_cxx

This has been discussed before I think, although seems still to be an
issue in 1.33 I believe. I think its due to the fact that there is no
standardised hash_map map implementation.

Hope that helps,
Cheers
Chirs

Peter Lindman wrote:

>Hello,
>
>I cannot really get the serializations to work for hash_maps. Using
>maps, lists and vectors
>everything works just fine.
>
>Using the sample code pasted below (using a hash_map) gives the
>following compilation-errors:
>
>/usr/include/boost/serialization/access.hpp: In static member function `static
> void boost::serialization::access::serialize(Archive&, T&, unsigned int)
> [with Archive = boost::archive::text_oarchive, T = __gnu_cxx::hash_map<long
> int, long int, __gnu_cxx::hash<long int>, std::equal_to<long int>,
> std::allocator<long int> >]':
>/usr/include/boost/serialization/serialization.hpp:78: instantiated
>from `void boost::serialization::serialize(Archive&, T&, unsigned int)
>[with Archive = boost::archive::text_oarchive, T =
>__gnu_cxx::hash_map<long int, long int, __gnu_cxx::hash<long int>,
>std::equal_to<long int>, std::allocator<long int> >]'
>/usr/include/boost/serialization/serialization.hpp:121: instantiated
>from `void boost::serialization::serialize_adl(Archive&, T&, unsigned
>int) [with Archive = boost::archive::text_oarchive, T =
>__gnu_cxx::hash_map<long int, long int, __gnu_cxx::hash<long int>,
>std::equal_to<long int>, std::allocator<long int> >]'
>/usr/include/boost/archive/detail/oserializer.hpp:148: instantiated
>from `void boost::archive::detail::oserializer<Archive,
>T>::save_object_data(boost::archive::detail::basic_oarchive&, const
>void*) const [with Archive = boost::archive::text_oarchive, T =
>__gnu_cxx::hash_map<long int, long int, __gnu_cxx::hash<long int>,
>std::equal_to<long int>, std::allocator<long int> >]'
>/usr/include/boost/archive/detail/oserializer.hpp:243: instantiated from here
>/usr/include/boost/serialization/access.hpp:106: error: `serialize' undeclared
> (first use this function)
>/usr/include/boost/serialization/access.hpp:106: error: (Each undeclared
> identifier is reported only once for each function it appears in.)
>
>
>Changing the created class to "busmap" (based on std::map) everything
>works just fine!
>(The ONLY difference between the classes is the container-definition)
>
>System specs:
>
>Linux kernel version 2.4.26
>g++ (GCC) 3.3.2 20031218
>boost-1.32
>
>Sample code
>compiled with: g++ -o test test.cpp -lboost_serialization-gcc-mt
>==================================================
>
>#include <fstream>
>#include <boost/archive/text_oarchive.hpp>
>#include <boost/archive/text_iarchive.hpp>
>#include <boost/serialization/hash_map.hpp>
>#include <boost/serialization/map.hpp>
>#include <ext/hash_map>
>#include <map>
>
>class busmap
>{
> friend class boost::serialization::access;
> std::map<long,long> bus_serial_map; // Imaginary bus-serial-number
>to bus number lookup-table;
> template<class Archive>
> void serialize(Archive & ar, const unsigned int version)
> {
> ar & bus_serial_map;
> }
>public:
> busmap(){}
>};
>
>
>class bushashmap
>{
> friend class boost::serialization::access;
> __gnu_cxx::hash_map<long,long> bus_serial_map; // Imaginary
>bus-serial-number to bus number lookup-table;
> template<class Archive>
> void serialize(Archive & ar, const unsigned int version)
> {
> ar & bus_serial_map;
> }
>public:
> bushashmap(){}
>};
>
>
>int main() {
> // create and open a character archive for output
> std::ofstream ofs("filename");
> boost::archive::text_oarchive oa(ofs);
>
> // create class instance
> const bushashmap myBusMap;
>
> // write class instance to archive
> oa << myBusMap;
> // close archive
> ofs.close();
>
> // ... some time later restore the class instance to its orginal state
> // create and open an archive for input
>
> std::ifstream ifs("filename", std::ios::binary);
> boost::archive::text_iarchive ia(ifs);
> // read class state from archive
> busmap myNewBusMap;
> ia >> myNewBusMap;
> // close archive
> ifs.close();
> return 0;
>}
>
>=======================================
>
>Bug or my fault?? Can anyone help?
>
>Best regards
>Peter
>
>_______________________________________________
>Boost-users mailing list
>Boost-users_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.


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