Boost logo

Geometry :

Subject: [ggl] serialization and hash
From: Richard Ulrich (richi)
Date: 2010-08-15 09:09:42


To fully use point_ll_deg with boost::serialize, std::find and
boost::unordered_set, I have a header file with the following:

Is serialization planned to be included in boost::geometry itself?

Rgds
Richard

// ggl (boost sandbox)
#include <boost/geometry/extensions/gis/latlong/latlong.hpp>
// boost
#include <boost/serialization/split_free.hpp>
#include <boost/unordered_set.hpp>

namespace boost
{
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
namespace serialization
{
    template <class Archive>
    void save(Archive &ar, const geometry::point_ll_deg &pos, const
unsigned int version)
    {
                double lat(pos.lat()), lon(pos.lon());
                ar & BOOST_SERIALIZATION_NVP(lat);
                ar & BOOST_SERIALIZATION_NVP(lon);
    }

    template <class Archive>
    void load(Archive &ar, geometry::point_ll_deg &pos, const unsigned
int version)
    {
                double lat, lon;
                ar & BOOST_SERIALIZATION_NVP(lat);
                ar & BOOST_SERIALIZATION_NVP(lon);
                pos = geometry::point_ll_deg(geometry::latitude<>(lat),
geometry::longitude<>(lon));
    }

} // namespace serialization
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
namespace geometry
{
    size_t hash_value(const point_ll_deg &pnt)
    {
        return boost::hash_value(pnt.lat()) +
boost::hash_value(pnt.lon());
    }

    bool operator==(const point_ll_deg &lhs, const point_ll_deg &rhs)
    {
        return lhs.lon() == rhs.lon() && lhs.lat() == rhs.lat();
    }
} // namespace geometry

} // namespace boost
BOOST_SERIALIZATION_SPLIT_FREE(geometry::point_ll_deg)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://lists.osgeo.org/pipermail/ggl/attachments/20100815/b8106db3/attachment.bin


Geometry list run by mateusz at loskot.net