/* Copyright 2003-2005 Joaquín M López Muñoz. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * See http://www.boost.org/libs/multi_index for library home page. */ #ifndef BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_ITERATOR_HPP #define BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_ITERATOR_HPP #if defined(_MSC_VER)&&(_MSC_VER>=1200) #pragma once #endif #include /* keep it first to prevent nasty warns in MSVC */ #include #include #include #include #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) #include #include #endif namespace boost{ namespace multi_index{ namespace detail{ /* An iterator template for nodes of multi_index::detail::hashed_index. * Built with the aid boost::forward_iterator_helper from * boost/operators.hpp. */ #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) #if BOOST_WORKAROUND(BOOST_MSVC,<1300) template class hashed_index_iterator: public boost::forward_iterator_helper< hashed_index_iterator, typename Node::value_type, std::ptrdiff_t, const typename Node::value_type*, const typename Node::value_type&>, public safe_iterator > #else template class hashed_index_iterator: public boost::forward_iterator_helper< hashed_index_iterator, typename Node::value_type, std::ptrdiff_t, const typename Node::value_type*, const typename Node::value_type&>, public safe_iterator #endif #else template class hashed_index_iterator: public boost::forward_iterator_helper< hashed_index_iterator, typename Node::value_type, std::ptrdiff_t, const typename Node::value_type*, const typename Node::value_type&> #endif { #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) public: #if BOOST_WORKAROUND(BOOST_MSVC,<1300) typedef hashed_index_proxy container_type; #else typedef Container container_type; #endif private: typedef safe_iterator safe_super; public: hashed_index_iterator():node(0),buckets(0){} hashed_index_iterator( Node* node_,BucketArray& buckets_,container_type* cont_): safe_super(cont_),node(node_),buckets(&buckets_){} hashed_index_iterator& operator=(const hashed_index_iterator& x) { BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(x); safe_super::operator=(x); node=x.node; buckets=x.buckets; return *this; } #else public: hashed_index_iterator(){} hashed_index_iterator(Node* node_,BucketArray& buckets_): node(node_),buckets(&buckets_){} #endif const typename Node::value_type& operator*()const { BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(*this); BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(*this); return node->value; } hashed_index_iterator& operator++() { BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(*this); BOOST_MULTI_INDEX_CHECK_INCREMENTABLE_ITERATOR(*this); Node::increment(node,buckets->begin(),buckets->end()); return *this; } friend bool operator==(const hashed_index_iterator& x,const hashed_index_iterator& y) { BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(x); BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(y); BOOST_MULTI_INDEX_CHECK_SAME_OWNER(x,y); return x.node==y.node; } /* get_node is not to be used by the user */ Node* get_node()const{return node;} private: Node* node; BucketArray* buckets; #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) /* serialization */ friend class boost::serialization::access; BOOST_SERIALIZATION_SPLIT_MEMBER() typedef typename Node::base_type node_base_type; template void save(Archive& ar,const unsigned int version)const { BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(*this); node_base_type* bnode=node; ar< void load(Archive& ar,const unsigned int version) { node_base_type* bnode; ar>>serialization::make_nvp("pointer",bnode); node=static_cast(bnode); ar>>serialization::make_nvp("pointer",buckets); #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) safe_super::uncheck(); #endif } #endif }; } /* namespace multi_index::detail */ } /* namespace multi_index */ } /* namespace boost */ #endif