bidir_node_iterator.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Copyright 2003-2023 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/core/serialization.hpp>
  17. #endif
  18. namespace boost{
  19. namespace multi_index{
  20. namespace detail{
  21. /* Iterator class for node-based indices with bidirectional
  22. * iterators (ordered and sequenced indices.)
  23. */
  24. template<typename Node>
  25. class bidir_node_iterator:
  26. public bidirectional_iterator_helper<
  27. bidir_node_iterator<Node>,
  28. typename Node::value_type,
  29. typename Node::difference_type,
  30. const typename Node::value_type*,
  31. const typename Node::value_type&>
  32. {
  33. public:
  34. /* coverity[uninit_ctor]: suppress warning */
  35. bidir_node_iterator(){}
  36. explicit bidir_node_iterator(Node* node_):node(node_){}
  37. const typename Node::value_type& operator*()const
  38. {
  39. return node->value();
  40. }
  41. bidir_node_iterator& operator++()
  42. {
  43. Node::increment(node);
  44. return *this;
  45. }
  46. bidir_node_iterator& operator--()
  47. {
  48. Node::decrement(node);
  49. return *this;
  50. }
  51. #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
  52. /* Serialization. As for why the following is public,
  53. * see explanation in safe_mode_iterator notes in safe_mode.hpp.
  54. */
  55. template<class Archive>
  56. void serialize(Archive& ar,const unsigned int version)
  57. {
  58. core::split_member(ar,*this,version);
  59. }
  60. typedef typename Node::base_type node_base_type;
  61. template<class Archive>
  62. void save(Archive& ar,const unsigned int)const
  63. {
  64. node_base_type* bnode=node;
  65. ar<<core::make_nvp("pointer",bnode);
  66. }
  67. template<class Archive>
  68. void load(Archive& ar,const unsigned int)
  69. {
  70. node_base_type* bnode;
  71. ar>>core::make_nvp("pointer",bnode);
  72. node=static_cast<Node*>(bnode);
  73. }
  74. #endif
  75. /* get_node is not to be used by the user */
  76. typedef Node node_type;
  77. Node* get_node()const{return node;}
  78. private:
  79. Node* node;
  80. };
  81. template<typename Node>
  82. bool operator==(
  83. const bidir_node_iterator<Node>& x,
  84. const bidir_node_iterator<Node>& y)
  85. {
  86. return x.get_node()==y.get_node();
  87. }
  88. } /* namespace multi_index::detail */
  89. } /* namespace multi_index */
  90. } /* namespace boost */
  91. #endif