File indexing completed on 2025-01-18 09:29:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_IP_BASIC_RESOLVER_ITERATOR_HPP
0012 #define BOOST_ASIO_IP_BASIC_RESOLVER_ITERATOR_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <cstddef>
0020 #include <cstring>
0021 #include <iterator>
0022 #include <string>
0023 #include <vector>
0024 #include <boost/asio/detail/memory.hpp>
0025 #include <boost/asio/detail/socket_ops.hpp>
0026 #include <boost/asio/detail/socket_types.hpp>
0027 #include <boost/asio/ip/basic_resolver_entry.hpp>
0028
0029 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
0030 # include <boost/asio/detail/winrt_utils.hpp>
0031 #endif
0032
0033 #include <boost/asio/detail/push_options.hpp>
0034
0035 namespace boost {
0036 namespace asio {
0037 namespace ip {
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 template <typename InternetProtocol>
0052 class basic_resolver_iterator
0053 {
0054 public:
0055
0056 typedef std::ptrdiff_t difference_type;
0057
0058
0059 typedef basic_resolver_entry<InternetProtocol> value_type;
0060
0061
0062 typedef const basic_resolver_entry<InternetProtocol>* pointer;
0063
0064
0065 typedef const basic_resolver_entry<InternetProtocol>& reference;
0066
0067
0068 typedef std::forward_iterator_tag iterator_category;
0069
0070
0071 basic_resolver_iterator()
0072 : index_(0)
0073 {
0074 }
0075
0076
0077 basic_resolver_iterator(const basic_resolver_iterator& other)
0078 : values_(other.values_),
0079 index_(other.index_)
0080 {
0081 }
0082
0083
0084 basic_resolver_iterator(basic_resolver_iterator&& other)
0085 : values_(static_cast<values_ptr_type&&>(other.values_)),
0086 index_(other.index_)
0087 {
0088 other.index_ = 0;
0089 }
0090
0091
0092 basic_resolver_iterator& operator=(const basic_resolver_iterator& other)
0093 {
0094 values_ = other.values_;
0095 index_ = other.index_;
0096 return *this;
0097 }
0098
0099
0100 basic_resolver_iterator& operator=(basic_resolver_iterator&& other)
0101 {
0102 if (this != &other)
0103 {
0104 values_ = static_cast<values_ptr_type&&>(other.values_);
0105 index_ = other.index_;
0106 other.index_ = 0;
0107 }
0108
0109 return *this;
0110 }
0111
0112
0113 const basic_resolver_entry<InternetProtocol>& operator*() const
0114 {
0115 return dereference();
0116 }
0117
0118
0119 const basic_resolver_entry<InternetProtocol>* operator->() const
0120 {
0121 return &dereference();
0122 }
0123
0124
0125 basic_resolver_iterator& operator++()
0126 {
0127 increment();
0128 return *this;
0129 }
0130
0131
0132 basic_resolver_iterator operator++(int)
0133 {
0134 basic_resolver_iterator tmp(*this);
0135 ++*this;
0136 return tmp;
0137 }
0138
0139
0140 friend bool operator==(const basic_resolver_iterator& a,
0141 const basic_resolver_iterator& b)
0142 {
0143 return a.equal(b);
0144 }
0145
0146
0147 friend bool operator!=(const basic_resolver_iterator& a,
0148 const basic_resolver_iterator& b)
0149 {
0150 return !a.equal(b);
0151 }
0152
0153 protected:
0154 void increment()
0155 {
0156 if (++index_ == values_->size())
0157 {
0158
0159 values_.reset();
0160 index_ = 0;
0161 }
0162 }
0163
0164 bool equal(const basic_resolver_iterator& other) const
0165 {
0166 if (!values_ && !other.values_)
0167 return true;
0168 if (values_ != other.values_)
0169 return false;
0170 return index_ == other.index_;
0171 }
0172
0173 const basic_resolver_entry<InternetProtocol>& dereference() const
0174 {
0175 return (*values_)[index_];
0176 }
0177
0178 typedef std::vector<basic_resolver_entry<InternetProtocol>> values_type;
0179 typedef boost::asio::detail::shared_ptr<values_type> values_ptr_type;
0180 values_ptr_type values_;
0181 std::size_t index_;
0182 };
0183
0184 }
0185 }
0186 }
0187
0188 #include <boost/asio/detail/pop_options.hpp>
0189
0190 #endif