]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) | |
5 | * | |
6 | * See http://www.boost.org/libs/multi_index for library home page. | |
7 | */ | |
8 | ||
9 | #ifndef BOOST_MULTI_INDEX_DETAIL_RND_NODE_ITERATOR_HPP | |
10 | #define BOOST_MULTI_INDEX_DETAIL_RND_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/serialization/nvp.hpp> | |
21 | #include <boost/serialization/split_member.hpp> | |
22 | #endif | |
23 | ||
24 | namespace boost{ | |
25 | ||
26 | namespace multi_index{ | |
27 | ||
28 | namespace detail{ | |
29 | ||
30 | /* Iterator class for node-based indices with random access iterators. */ | |
31 | ||
32 | template<typename Node> | |
33 | class rnd_node_iterator: | |
34 | public random_access_iterator_helper< | |
35 | rnd_node_iterator<Node>, | |
36 | typename Node::value_type, | |
37 | std::ptrdiff_t, | |
38 | const typename Node::value_type*, | |
39 | const typename Node::value_type&> | |
40 | { | |
41 | public: | |
42 | /* coverity[uninit_ctor]: suppress warning */ | |
43 | rnd_node_iterator(){} | |
44 | explicit rnd_node_iterator(Node* node_):node(node_){} | |
45 | ||
46 | const typename Node::value_type& operator*()const | |
47 | { | |
48 | return node->value(); | |
49 | } | |
50 | ||
51 | rnd_node_iterator& operator++() | |
52 | { | |
53 | Node::increment(node); | |
54 | return *this; | |
55 | } | |
56 | ||
57 | rnd_node_iterator& operator--() | |
58 | { | |
59 | Node::decrement(node); | |
60 | return *this; | |
61 | } | |
62 | ||
63 | rnd_node_iterator& operator+=(std::ptrdiff_t n) | |
64 | { | |
65 | Node::advance(node,n); | |
66 | return *this; | |
67 | } | |
68 | ||
69 | rnd_node_iterator& operator-=(std::ptrdiff_t n) | |
70 | { | |
71 | Node::advance(node,-n); | |
72 | return *this; | |
73 | } | |
74 | ||
75 | #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) | |
76 | /* Serialization. As for why the following is public, | |
77 | * see explanation in safe_mode_iterator notes in safe_mode.hpp. | |
78 | */ | |
79 | ||
80 | BOOST_SERIALIZATION_SPLIT_MEMBER() | |
81 | ||
82 | typedef typename Node::base_type node_base_type; | |
83 | ||
84 | template<class Archive> | |
85 | void save(Archive& ar,const unsigned int)const | |
86 | { | |
87 | node_base_type* bnode=node; | |
88 | ar<<serialization::make_nvp("pointer",bnode); | |
89 | } | |
90 | ||
91 | template<class Archive> | |
92 | void load(Archive& ar,const unsigned int) | |
93 | { | |
94 | node_base_type* bnode; | |
95 | ar>>serialization::make_nvp("pointer",bnode); | |
96 | node=static_cast<Node*>(bnode); | |
97 | } | |
98 | #endif | |
99 | ||
100 | /* get_node is not to be used by the user */ | |
101 | ||
102 | typedef Node node_type; | |
103 | ||
104 | Node* get_node()const{return node;} | |
105 | ||
106 | private: | |
107 | Node* node; | |
108 | }; | |
109 | ||
110 | template<typename Node> | |
111 | bool operator==( | |
112 | const rnd_node_iterator<Node>& x, | |
113 | const rnd_node_iterator<Node>& y) | |
114 | { | |
115 | return x.get_node()==y.get_node(); | |
116 | } | |
117 | ||
118 | template<typename Node> | |
119 | bool operator<( | |
120 | const rnd_node_iterator<Node>& x, | |
121 | const rnd_node_iterator<Node>& y) | |
122 | { | |
123 | return Node::distance(x.get_node(),y.get_node())>0; | |
124 | } | |
125 | ||
126 | template<typename Node> | |
127 | std::ptrdiff_t operator-( | |
128 | const rnd_node_iterator<Node>& x, | |
129 | const rnd_node_iterator<Node>& y) | |
130 | { | |
131 | return Node::distance(y.get_node(),x.get_node()); | |
132 | } | |
133 | ||
134 | } /* namespace multi_index::detail */ | |
135 | ||
136 | } /* namespace multi_index */ | |
137 | ||
138 | } /* namespace boost */ | |
139 | ||
140 | #endif |