2 // ip/basic_resolver_iterator.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_IP_BASIC_RESOLVER_ITERATOR_HPP
12 #define BOOST_ASIO_IP_BASIC_RESOLVER_ITERATOR_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
24 #include <boost/asio/detail/memory.hpp>
25 #include <boost/asio/detail/socket_ops.hpp>
26 #include <boost/asio/detail/socket_types.hpp>
27 #include <boost/asio/ip/basic_resolver_entry.hpp>
29 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
30 # include <boost/asio/detail/winrt_utils.hpp>
31 #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
33 #include <boost/asio/detail/push_options.hpp>
39 /// An iterator over the entries produced by a resolver.
41 * The boost::asio::ip::basic_resolver_iterator class template is used to define
42 * iterators over the results returned by a resolver.
44 * The iterator's value_type, obtained when the iterator is dereferenced, is:
45 * @code const basic_resolver_entry<InternetProtocol> @endcode
48 * @e Distinct @e objects: Safe.@n
49 * @e Shared @e objects: Unsafe.
51 template <typename InternetProtocol>
52 class basic_resolver_iterator
55 /// The type used for the distance between two iterators.
56 typedef std::ptrdiff_t difference_type;
58 /// The type of the value pointed to by the iterator.
59 typedef basic_resolver_entry<InternetProtocol> value_type;
61 /// The type of the result of applying operator->() to the iterator.
62 typedef const basic_resolver_entry<InternetProtocol>* pointer;
64 /// The type of the result of applying operator*() to the iterator.
65 typedef const basic_resolver_entry<InternetProtocol>& reference;
67 /// The iterator category.
68 typedef std::forward_iterator_tag iterator_category;
70 /// Default constructor creates an end iterator.
71 basic_resolver_iterator()
77 basic_resolver_iterator(const basic_resolver_iterator& other)
78 : values_(other.values_),
83 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
85 basic_resolver_iterator(basic_resolver_iterator&& other)
86 : values_(BOOST_ASIO_MOVE_CAST(values_ptr_type)(other.values_)),
91 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
93 /// Assignment operator.
94 basic_resolver_iterator& operator=(const basic_resolver_iterator& other)
96 values_ = other.values_;
97 index_ = other.index_;
101 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
102 /// Move-assignment operator.
103 basic_resolver_iterator& operator=(basic_resolver_iterator&& other)
107 values_ = BOOST_ASIO_MOVE_CAST(values_ptr_type)(other.values_);
108 index_ = other.index_;
114 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
116 /// Dereference an iterator.
117 const basic_resolver_entry<InternetProtocol>& operator*() const
119 return dereference();
122 /// Dereference an iterator.
123 const basic_resolver_entry<InternetProtocol>* operator->() const
125 return &dereference();
128 /// Increment operator (prefix).
129 basic_resolver_iterator& operator++()
135 /// Increment operator (postfix).
136 basic_resolver_iterator operator++(int)
138 basic_resolver_iterator tmp(*this);
143 /// Test two iterators for equality.
144 friend bool operator==(const basic_resolver_iterator& a,
145 const basic_resolver_iterator& b)
150 /// Test two iterators for inequality.
151 friend bool operator!=(const basic_resolver_iterator& a,
152 const basic_resolver_iterator& b)
160 if (++index_ == values_->size())
162 // Reset state to match a default constructed end iterator.
168 bool equal(const basic_resolver_iterator& other) const
170 if (!values_ && !other.values_)
172 if (values_ != other.values_)
174 return index_ == other.index_;
177 const basic_resolver_entry<InternetProtocol>& dereference() const
179 return (*values_)[index_];
182 typedef std::vector<basic_resolver_entry<InternetProtocol> > values_type;
183 typedef boost::asio::detail::shared_ptr<values_type> values_ptr_type;
184 values_ptr_type values_;
192 #include <boost/asio/detail/pop_options.hpp>
194 #endif // BOOST_ASIO_IP_BASIC_RESOLVER_ITERATOR_HPP