tree_node.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2007-2013
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/intrusive for documentation.
  10. //
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_INTRUSIVE_TREE_NODE_HPP
  13. #define BOOST_INTRUSIVE_TREE_NODE_HPP
  14. #ifndef BOOST_CONFIG_HPP
  15. # include <boost/config.hpp>
  16. #endif
  17. #if defined(BOOST_HAS_PRAGMA_ONCE)
  18. # pragma once
  19. #endif
  20. #include <boost/intrusive/detail/config_begin.hpp>
  21. #include <boost/intrusive/detail/workaround.hpp>
  22. #include <boost/intrusive/pointer_rebind.hpp>
  23. namespace boost {
  24. namespace intrusive {
  25. template<class VoidPointer>
  26. struct tree_node
  27. {
  28. typedef typename pointer_rebind<VoidPointer, tree_node>::type node_ptr;
  29. node_ptr parent_, left_, right_;
  30. };
  31. template<class VoidPointer>
  32. struct tree_node_traits
  33. {
  34. typedef tree_node<VoidPointer> node;
  35. typedef typename node::node_ptr node_ptr;
  36. typedef typename pointer_rebind<VoidPointer, const node>::type const_node_ptr;
  37. BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_parent(const const_node_ptr & n)
  38. { return n->parent_; }
  39. BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_parent(const node_ptr & n)
  40. { return n->parent_; }
  41. BOOST_INTRUSIVE_FORCEINLINE static void set_parent(node_ptr n, node_ptr p)
  42. { n->parent_ = p; }
  43. BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_left(const const_node_ptr & n)
  44. { return n->left_; }
  45. BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_left(const node_ptr & n)
  46. { return n->left_; }
  47. BOOST_INTRUSIVE_FORCEINLINE static void set_left(node_ptr n, node_ptr l)
  48. { n->left_ = l; }
  49. BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_right(const const_node_ptr & n)
  50. { return n->right_; }
  51. BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_right(const node_ptr & n)
  52. { return n->right_; }
  53. BOOST_INTRUSIVE_FORCEINLINE static void set_right(node_ptr n, node_ptr r)
  54. { n->right_ = r; }
  55. };
  56. } //namespace intrusive
  57. } //namespace boost
  58. #include <boost/intrusive/detail/config_end.hpp>
  59. #endif //BOOST_INTRUSIVE_TREE_NODE_HPP