Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:09

0001 /* Copyright 2003-2023 Joaquin M Lopez Munoz.
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * See http://www.boost.org/libs/multi_index for library home page.
0007  */
0008 
0009 #ifndef BOOST_MULTI_INDEX_DETAIL_RND_NODE_ITERATOR_HPP
0010 #define BOOST_MULTI_INDEX_DETAIL_RND_NODE_ITERATOR_HPP
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
0017 #include <boost/operators.hpp>
0018 
0019 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
0020 #include <boost/core/serialization.hpp>
0021 #endif
0022 
0023 namespace boost{
0024 
0025 namespace multi_index{
0026 
0027 namespace detail{
0028 
0029 /* Iterator class for node-based indices with random access iterators. */
0030 
0031 template<typename Node>
0032 class rnd_node_iterator:
0033   public random_access_iterator_helper<
0034     rnd_node_iterator<Node>,
0035     typename Node::value_type,
0036     typename Node::difference_type,
0037     const typename Node::value_type*,
0038     const typename Node::value_type&>
0039 {
0040 public:
0041   /* coverity[uninit_ctor]: suppress warning */
0042   rnd_node_iterator(){}
0043   explicit rnd_node_iterator(Node* node_):node(node_){}
0044 
0045   const typename Node::value_type& operator*()const
0046   {
0047     return node->value();
0048   }
0049 
0050   rnd_node_iterator& operator++()
0051   {
0052     Node::increment(node);
0053     return *this;
0054   }
0055 
0056   rnd_node_iterator& operator--()
0057   {
0058     Node::decrement(node);
0059     return *this;
0060   }
0061 
0062   rnd_node_iterator& operator+=(typename Node::difference_type n)
0063   {
0064     Node::advance(node,n);
0065     return *this;
0066   }
0067 
0068   rnd_node_iterator& operator-=(typename Node::difference_type n)
0069   {
0070     Node::advance(node,-n);
0071     return *this;
0072   }
0073 
0074 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
0075   /* Serialization. As for why the following is public,
0076    * see explanation in safe_mode_iterator notes in safe_mode.hpp.
0077    */
0078 
0079   template<class Archive>
0080   void serialize(Archive& ar,const unsigned int version)
0081   {
0082     core::split_member(ar,*this,version);
0083   }
0084 
0085   typedef typename Node::base_type node_base_type;
0086 
0087   template<class Archive>
0088   void save(Archive& ar,const unsigned int)const
0089   {
0090     node_base_type* bnode=node;
0091     ar<<core::make_nvp("pointer",bnode);
0092   }
0093 
0094   template<class Archive>
0095   void load(Archive& ar,const unsigned int)
0096   {
0097     node_base_type* bnode;
0098     ar>>core::make_nvp("pointer",bnode);
0099     node=static_cast<Node*>(bnode);
0100   }
0101 #endif
0102 
0103   /* get_node is not to be used by the user */
0104 
0105   typedef Node node_type;
0106 
0107   Node* get_node()const{return node;}
0108 
0109 private:
0110   Node* node;
0111 };
0112 
0113 template<typename Node>
0114 bool operator==(
0115   const rnd_node_iterator<Node>& x,
0116   const rnd_node_iterator<Node>& y)
0117 {
0118   return x.get_node()==y.get_node();
0119 }
0120 
0121 template<typename Node>
0122 bool operator<(
0123   const rnd_node_iterator<Node>& x,
0124   const rnd_node_iterator<Node>& y)
0125 {
0126   return Node::distance(x.get_node(),y.get_node())>0;
0127 }
0128 
0129 template<typename Node>
0130 typename Node::difference_type operator-(
0131   const rnd_node_iterator<Node>& x,
0132   const rnd_node_iterator<Node>& y)
0133 {
0134   return Node::distance(y.get_node(),x.get_node());
0135 }
0136 
0137 } /* namespace multi_index::detail */
0138 
0139 } /* namespace multi_index */
0140 
0141 } /* namespace boost */
0142 
0143 #endif