1 /* Copyright 2003-2014 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)
6 * See http://www.boost.org/libs/multi_index for library home page.
9 #ifndef BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_ITERATOR_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_ITERATOR_HPP
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17 #include <boost/operators.hpp>
19 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
20 #include <boost/serialization/nvp.hpp>
21 #include <boost/serialization/split_member.hpp>
22 #include <boost/serialization/version.hpp>
27 namespace multi_index{
31 /* Iterator class for hashed indices.
34 struct hashed_index_global_iterator_tag{};
35 struct hashed_index_local_iterator_tag{};
37 template<typename Node,typename BucketArray,typename Category>
38 class hashed_index_iterator:
39 public forward_iterator_helper<
40 hashed_index_iterator<Node,BucketArray,Category>,
41 typename Node::value_type,
43 const typename Node::value_type*,
44 const typename Node::value_type&>
47 /* coverity[uninit_ctor]: suppress warning */
48 hashed_index_iterator(){}
49 hashed_index_iterator(Node* node_):node(node_){}
51 const typename Node::value_type& operator*()const
56 hashed_index_iterator& operator++()
58 this->increment(Category());
62 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
63 /* Serialization. As for why the following is public,
64 * see explanation in safe_mode_iterator notes in safe_mode.hpp.
67 BOOST_SERIALIZATION_SPLIT_MEMBER()
69 typedef typename Node::base_type node_base_type;
71 template<class Archive>
72 void save(Archive& ar,const unsigned int)const
74 node_base_type* bnode=node;
75 ar<<serialization::make_nvp("pointer",bnode);
78 template<class Archive>
79 void load(Archive& ar,const unsigned int version)
81 load(ar,version,Category());
84 template<class Archive>
86 Archive& ar,const unsigned int version,hashed_index_global_iterator_tag)
88 node_base_type* bnode;
89 ar>>serialization::make_nvp("pointer",bnode);
90 node=static_cast<Node*>(bnode);
92 BucketArray* throw_away; /* consume unused ptr */
93 ar>>serialization::make_nvp("pointer",throw_away);
97 template<class Archive>
99 Archive& ar,const unsigned int version,hashed_index_local_iterator_tag)
101 node_base_type* bnode;
102 ar>>serialization::make_nvp("pointer",bnode);
103 node=static_cast<Node*>(bnode);
105 BucketArray* buckets;
106 ar>>serialization::make_nvp("pointer",buckets);
107 if(buckets&&node&&node->impl()==buckets->end()->prior()){
108 /* end local_iterators used to point to end node, now they are null */
115 /* get_node is not to be used by the user */
117 typedef Node node_type;
119 Node* get_node()const{return node;}
123 void increment(hashed_index_global_iterator_tag)
125 Node::increment(node);
128 void increment(hashed_index_local_iterator_tag)
130 Node::increment_local(node);
136 template<typename Node,typename BucketArray,typename Category>
138 const hashed_index_iterator<Node,BucketArray,Category>& x,
139 const hashed_index_iterator<Node,BucketArray,Category>& y)
141 return x.get_node()==y.get_node();
144 } /* namespace multi_index::detail */
146 } /* namespace multi_index */
148 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
149 /* class version = 1 : hashed_index_iterator does no longer serialize a bucket
153 namespace serialization {
154 template<typename Node,typename BucketArray,typename Category>
156 boost::multi_index::detail::hashed_index_iterator<Node,BucketArray,Category>
159 BOOST_STATIC_CONSTANT(int,value=1);
161 } /* namespace serialization */
164 } /* namespace boost */