bidir_node_iterator.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Copyright 2003-2018 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/multi_index for library home page.
  7. */
  8. #ifndef BOOST_MULTI_INDEX_DETAIL_BIDIR_NODE_ITERATOR_HPP
  9. #define BOOST_MULTI_INDEX_DETAIL_BIDIR_NODE_ITERATOR_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  14. #include <boost/operators.hpp>
  15. #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
  16. #include <boost/serialization/nvp.hpp>
  17. #include <boost/serialization/split_member.hpp>
  18. #endif
  19. namespace boost{
  20. namespace multi_index{
  21. namespace detail{
  22. /* Iterator class for node-based indices with bidirectional
  23. * iterators (ordered and sequenced indices.)
  24. */
  25. template<typename Node>
  26. class bidir_node_iterator:
  27. public bidirectional_iterator_helper<
  28. bidir_node_iterator<Node>,
  29. typename Node::value_type,
  30. typename Node::difference_type,
  31. const typename Node::value_type*,
  32. const typename Node::value_type&>
  33. {
  34. public:
  35. /* coverity[uninit_ctor]: suppress warning */
  36. bidir_node_iterator(){}
  37. explicit bidir_node_iterator(Node* node_):node(node_){}
  38. const typename Node::value_type& operator*()const
  39. {
  40. return node->value();
  41. }
  42. bidir_node_iterator& operator++()
  43. {
  44. Node::increment(node);
  45. return *this;
  46. }
  47. bidir_node_iterator& operator--()
  48. {
  49. Node::decrement(node);
  50. return *this;
  51. }
  52. #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
  53. /* Serialization. As for why the following is public,
  54. * see explanation in safe_mode_iterator notes in safe_mode.hpp.
  55. */
  56. BOOST_SERIALIZATION_SPLIT_MEMBER()
  57. typedef typename Node::base_type node_base_type;
  58. template<class Archive>
  59. void save(Archive& ar,const unsigned int)const
  60. {
  61. node_base_type* bnode=node;
  62. ar<<serialization::make_nvp("pointer",bnode);
  63. }
  64. template<class Archive>
  65. void load(Archive& ar,const unsigned int)
  66. {
  67. node_base_type* bnode;
  68. ar>>serialization::make_nvp("pointer",bnode);
  69. node=static_cast<Node*>(bnode);
  70. }
  71. #endif
  72. /* get_node is not to be used by the user */
  73. typedef Node node_type;
  74. Node* get_node()const{return node;}
  75. private:
  76. Node* node;
  77. };
  78. template<typename Node>
  79. bool operator==(
  80. const bidir_node_iterator<Node>& x,
  81. const bidir_node_iterator<Node>& y)
  82. {
  83. return x.get_node()==y.get_node();
  84. }
  85. } /* namespace multi_index::detail */
  86. } /* namespace multi_index */
  87. } /* namespace boost */
  88. #endif