Skip to content

Commit

Permalink
+ kdtree serialization codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lei Xu committed Aug 8, 2010
1 parent e115842 commit 46fe09c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
40 changes: 40 additions & 0 deletions kdtree++/kdtree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
# include <stack>
#endif

#ifdef KDTREE_SERIALIZATION
# include <boost/serialization/split_member.hpp>
# include <boost/serialization/string.hpp>
#endif

#include <cmath>
#include <cstddef>
#include <cassert>
Expand Down Expand Up @@ -1198,6 +1203,41 @@ namespace KDTree
_Cmp _M_cmp;
_Dist _M_dist;

#ifdef KDTREE_SERIALIZATION
friend class boost::serialization::access;
template<class Archive>
void save(Archive & ar, const unsigned int version) const
{
ar.register_type(static_cast< _Link_type>(NULL));
_Link_type root = static_cast<_Link_type>(_M_root);
ar & root;
ar & _M_count;
}

template<class Archive>
void load(Archive & ar, const unsigned int version)
{
ar.register_type(static_cast<_Link_type>(NULL));
_Link_type root;
ar & root;
ar & _M_count;
_M_set_root(root);

if ( _M_get_root() ) {
_M_set_leftmost( node_type::_S_minimum(_M_get_root()));
_M_set_rightmost( node_type::_S_maximum(_M_get_root()));
_M_root->_M_parent = &_M_header;
} else {
_M_set_leftmost( &_M_header );
_M_set_rightmost( &_M_header );
}

_M_header._M_parent = NULL;
}

BOOST_SERIALIZATION_SPLIT_MEMBER()
#endif

#ifdef KDTREE_DEFINE_OSTREAM_OPERATORS
friend std::ostream&
operator<<(std::ostream& o,
Expand Down
37 changes: 37 additions & 0 deletions kdtree++/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#include <cstddef>
#include <cmath>

#ifdef KDTREE_SERIALIZATION
# include <boost/serialization/base_object.hpp>
# include <boost/serialization/split_member.hpp>
#endif

namespace KDTree
{
struct _Node_base
Expand Down Expand Up @@ -59,6 +64,38 @@ namespace KDTree
_Base_ptr const __RIGHT = NULL)
: _Node_base(__PARENT, __LEFT, __RIGHT), _M_value(__VALUE) {}

#ifdef KDTREE_SERIALIZATION
friend class boost::serialization::access;
template<class Archive>
void save(Archive & ar, const unsigned int version) const
{
ar.register_type(static_cast< _Link_type>(NULL));
_Link_type left = static_cast<_Link_type>(_M_left);
_Link_type right = static_cast<_Link_type>(_M_right);
ar & left & right;
ar & _M_value;
}

template<class Archive>
void load(Archive & ar, const unsigned int version)
{
ar.register_type(static_cast< _Link_type>(NULL));
_Link_type left, right;
ar & left & right;
ar & _M_value;
if (left) {
left->_M_parent = this;
}
if (right) {
right->_M_parent = this;
}
_M_left = left;
_M_right = right;
}

BOOST_SERIALIZATION_SPLIT_MEMBER()
#endif

#ifdef KDTREE_DEFINE_OSTREAM_OPERATORS

template <typename Char, typename Traits>
Expand Down

0 comments on commit 46fe09c

Please sign in to comment.