1 // 2 // ip/address_v6_range.hpp 3 // ~~~~~~~~~~~~~~~~~~~~~~~ 4 // 5 // Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 // Oliver Kowalke (oliver dot kowalke at gmail dot com) 7 // 8 // Distributed under the Boost Software License, Version 1.0. (See accompanying 9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 10 // 11 12 #ifndef BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP 13 #define BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP 14 15 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 # pragma once 17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 19 #include <boost/asio/detail/config.hpp> 20 #include <boost/asio/ip/address_v6_iterator.hpp> 21 22 #include <boost/asio/detail/push_options.hpp> 23 24 namespace boost { 25 namespace asio { 26 namespace ip { 27 28 template <typename> class basic_address_range; 29 30 /// Represents a range of IPv6 addresses. 31 /** 32 * @par Thread Safety 33 * @e Distinct @e objects: Safe.@n 34 * @e Shared @e objects: Unsafe. 35 */ 36 template <> class basic_address_range<address_v6> 37 { 38 public: 39 /// The type of an iterator that points into the range. 40 typedef basic_address_iterator<address_v6> iterator; 41 42 /// Construct an empty range. basic_address_range()43 basic_address_range() BOOST_ASIO_NOEXCEPT 44 : begin_(address_v6()), 45 end_(address_v6()) 46 { 47 } 48 49 /// Construct an range that represents the given range of addresses. basic_address_range(const iterator & first,const iterator & last)50 explicit basic_address_range(const iterator& first, 51 const iterator& last) BOOST_ASIO_NOEXCEPT 52 : begin_(first), 53 end_(last) 54 { 55 } 56 57 /// Copy constructor. basic_address_range(const basic_address_range & other)58 basic_address_range(const basic_address_range& other) BOOST_ASIO_NOEXCEPT 59 : begin_(other.begin_), 60 end_(other.end_) 61 { 62 } 63 64 #if defined(BOOST_ASIO_HAS_MOVE) 65 /// Move constructor. basic_address_range(basic_address_range && other)66 basic_address_range(basic_address_range&& other) BOOST_ASIO_NOEXCEPT 67 : begin_(BOOST_ASIO_MOVE_CAST(iterator)(other.begin_)), 68 end_(BOOST_ASIO_MOVE_CAST(iterator)(other.end_)) 69 { 70 } 71 #endif // defined(BOOST_ASIO_HAS_MOVE) 72 73 /// Assignment operator. operator =(const basic_address_range & other)74 basic_address_range& operator=( 75 const basic_address_range& other) BOOST_ASIO_NOEXCEPT 76 { 77 begin_ = other.begin_; 78 end_ = other.end_; 79 return *this; 80 } 81 82 #if defined(BOOST_ASIO_HAS_MOVE) 83 /// Move assignment operator. operator =(basic_address_range && other)84 basic_address_range& operator=( 85 basic_address_range&& other) BOOST_ASIO_NOEXCEPT 86 { 87 begin_ = BOOST_ASIO_MOVE_CAST(iterator)(other.begin_); 88 end_ = BOOST_ASIO_MOVE_CAST(iterator)(other.end_); 89 return *this; 90 } 91 #endif // defined(BOOST_ASIO_HAS_MOVE) 92 93 /// Obtain an iterator that points to the start of the range. begin() const94 iterator begin() const BOOST_ASIO_NOEXCEPT 95 { 96 return begin_; 97 } 98 99 /// Obtain an iterator that points to the end of the range. end() const100 iterator end() const BOOST_ASIO_NOEXCEPT 101 { 102 return end_; 103 } 104 105 /// Determine whether the range is empty. empty() const106 bool empty() const BOOST_ASIO_NOEXCEPT 107 { 108 return begin_ == end_; 109 } 110 111 /// Find an address in the range. find(const address_v6 & addr) const112 iterator find(const address_v6& addr) const BOOST_ASIO_NOEXCEPT 113 { 114 return addr >= *begin_ && addr < *end_ ? iterator(addr) : end_; 115 } 116 117 private: 118 iterator begin_; 119 iterator end_; 120 }; 121 122 /// Represents a range of IPv6 addresses. 123 typedef basic_address_range<address_v6> address_v6_range; 124 125 } // namespace ip 126 } // namespace asio 127 } // namespace boost 128 129 #include <boost/asio/detail/pop_options.hpp> 130 131 #endif // BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP 132