1 | //
|
---|
2 | // Boost.Pointer Container
|
---|
3 | //
|
---|
4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and
|
---|
5 | // distribution is subject to the Boost Software License, Version
|
---|
6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
7 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
8 | //
|
---|
9 | // For more information, see http://www.boost.org/libs/ptr_container/
|
---|
10 | //
|
---|
11 |
|
---|
12 | #ifndef BOOST_PTR_CONTAINER_MAP_ITERATOR_HPP
|
---|
13 | #define BOOST_PTR_CONTAINER_MAP_ITERATOR_HPP
|
---|
14 |
|
---|
15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
---|
16 | # pragma once
|
---|
17 | #endif
|
---|
18 |
|
---|
19 | #include <boost/config.hpp>
|
---|
20 | #include <cassert>
|
---|
21 | #include <utility>
|
---|
22 |
|
---|
23 | namespace boost
|
---|
24 | {
|
---|
25 | //namespace ptr_container_detail
|
---|
26 | //{
|
---|
27 | template
|
---|
28 | <
|
---|
29 | typename I, // original iterator
|
---|
30 | typename K, // key type
|
---|
31 | typename V // return value type of operator*()
|
---|
32 | >
|
---|
33 | class ptr_map_iterator
|
---|
34 | {
|
---|
35 | I iter_;
|
---|
36 | typedef K key_type;
|
---|
37 |
|
---|
38 | public:
|
---|
39 | typedef std::ptrdiff_t difference_type;
|
---|
40 | typedef V value_type;
|
---|
41 | typedef V* pointer;
|
---|
42 | typedef V& reference;
|
---|
43 | typedef std::bidirectional_iterator_tag iterator_category;
|
---|
44 |
|
---|
45 | public:
|
---|
46 | ptr_map_iterator() {}
|
---|
47 | ptr_map_iterator( const I& i ) : iter_( i ) {}
|
---|
48 |
|
---|
49 | template< class MutableIterator, class K2, class V2 >
|
---|
50 | ptr_map_iterator( const ptr_map_iterator<MutableIterator,K2,V2>& r )
|
---|
51 | : iter_(r.base())
|
---|
52 | { }
|
---|
53 |
|
---|
54 | V& operator*() const
|
---|
55 | {
|
---|
56 | return *static_cast<V*>( iter_->second );
|
---|
57 | }
|
---|
58 |
|
---|
59 | V* operator->() const
|
---|
60 | {
|
---|
61 | return static_cast<V*>( iter_->second );
|
---|
62 | }
|
---|
63 |
|
---|
64 | ptr_map_iterator& operator++()
|
---|
65 | {
|
---|
66 | ++iter_;
|
---|
67 | return *this;
|
---|
68 | }
|
---|
69 |
|
---|
70 | ptr_map_iterator operator++(int)
|
---|
71 | {
|
---|
72 | ptr_map_iterator res = *this;
|
---|
73 | ++iter_;
|
---|
74 | return res;
|
---|
75 | }
|
---|
76 |
|
---|
77 | ptr_map_iterator& operator--()
|
---|
78 | {
|
---|
79 | --iter_;
|
---|
80 | return *this;
|
---|
81 | }
|
---|
82 |
|
---|
83 | ptr_map_iterator operator--(int)
|
---|
84 | {
|
---|
85 | ptr_map_iterator res = *this;
|
---|
86 | --iter_;
|
---|
87 | return res;
|
---|
88 |
|
---|
89 | }
|
---|
90 |
|
---|
91 | I base() const
|
---|
92 | {
|
---|
93 | return iter_;
|
---|
94 | }
|
---|
95 |
|
---|
96 | key_type key() const
|
---|
97 | {
|
---|
98 | return iter_->first;
|
---|
99 | }
|
---|
100 |
|
---|
101 | }; // class 'ptr_map_iterator'
|
---|
102 |
|
---|
103 |
|
---|
104 |
|
---|
105 | template< class I, class K, class V, class I2, class K2, class V2 >
|
---|
106 | inline bool operator==( const ptr_map_iterator<I,K,V>& l,
|
---|
107 | const ptr_map_iterator<I2,K2,V2>& r )
|
---|
108 | {
|
---|
109 | return l.base() == r.base();
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 |
|
---|
114 | template< class I, class K, class V, class I2, class K2, class V2 >
|
---|
115 | inline bool operator!=( const ptr_map_iterator<I,K,V>& l,
|
---|
116 | const ptr_map_iterator<I2,K2,V2>& r )
|
---|
117 | {
|
---|
118 | return l.base() != r.base();
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | #endif
|
---|