Line data Source code
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 : 9 : #ifndef BOOST_MULTI_INDEX_DETAIL_BIDIR_NODE_ITERATOR_HPP 10 : #define BOOST_MULTI_INDEX_DETAIL_BIDIR_NODE_ITERATOR_HPP 11 : 12 : #if defined(_MSC_VER) 13 : #pragma once 14 : #endif 15 : 16 : #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ 17 : #include <boost/operators.hpp> 18 : 19 : #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) 20 : #include <boost/core/serialization.hpp> 21 : #endif 22 : 23 : namespace boost{ 24 : 25 : namespace multi_index{ 26 : 27 : namespace detail{ 28 : 29 : /* Iterator class for node-based indices with bidirectional 30 : * iterators (ordered and sequenced indices.) 31 : */ 32 : 33 : template<typename Node> 34 : class bidir_node_iterator: 35 : public bidirectional_iterator_helper< 36 : bidir_node_iterator<Node>, 37 : typename Node::value_type, 38 : typename Node::difference_type, 39 : const typename Node::value_type*, 40 : const typename Node::value_type&> 41 : { 42 : public: 43 : /* coverity[uninit_ctor]: suppress warning */ 44 : bidir_node_iterator(){} 45 4234320 : explicit bidir_node_iterator(Node* node_):node(node_){} 46 : 47 121989 : const typename Node::value_type& operator*()const 48 : { 49 121989 : return node->value(); 50 : } 51 : 52 57597 : bidir_node_iterator& operator++() 53 : { 54 57597 : Node::increment(node); 55 57597 : return *this; 56 : } 57 : 58 88839 : bidir_node_iterator& operator--() 59 : { 60 88839 : Node::decrement(node); 61 88839 : return *this; 62 : } 63 : 64 : #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) 65 : /* Serialization. As for why the following is public, 66 : * see explanation in safe_mode_iterator notes in safe_mode.hpp. 67 : */ 68 : 69 : template<class Archive> 70 : void serialize(Archive& ar,const unsigned int version) 71 : { 72 : core::split_member(ar,*this,version); 73 : } 74 : 75 : typedef typename Node::base_type node_base_type; 76 : 77 : template<class Archive> 78 : void save(Archive& ar,const unsigned int)const 79 : { 80 : node_base_type* bnode=node; 81 : ar<<core::make_nvp("pointer",bnode); 82 : } 83 : 84 : template<class Archive> 85 : void load(Archive& ar,const unsigned int) 86 : { 87 : node_base_type* bnode; 88 : ar>>core::make_nvp("pointer",bnode); 89 : node=static_cast<Node*>(bnode); 90 : } 91 : #endif 92 : 93 : /* get_node is not to be used by the user */ 94 : 95 : typedef Node node_type; 96 : 97 3102105 : Node* get_node()const{return node;} 98 : 99 : private: 100 : Node* node; 101 : }; 102 : 103 : template<typename Node> 104 1135054 : bool operator==( 105 : const bidir_node_iterator<Node>& x, 106 : const bidir_node_iterator<Node>& y) 107 : { 108 1135054 : return x.get_node()==y.get_node(); 109 : } 110 : 111 : } /* namespace multi_index::detail */ 112 : 113 : } /* namespace multi_index */ 114 : 115 : } /* namespace boost */ 116 : 117 : #endif