address_v6_range.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #ifndef BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP
  12. #define BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  16. #include <boost/asio/detail/config.hpp>
  17. #include <boost/asio/ip/address_v6_iterator.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace ip {
  22. template <typename> class basic_address_range;
  23. /// Represents a range of IPv6 addresses.
  24. /**
  25. * @par Thread Safety
  26. * @e Distinct @e objects: Safe.@n
  27. * @e Shared @e objects: Unsafe.
  28. */
  29. template <> class basic_address_range<address_v6>
  30. {
  31. public:
  32. /// The type of an iterator that points into the range.
  33. typedef basic_address_iterator<address_v6> iterator;
  34. /// Construct an empty range.
  35. basic_address_range() BOOST_ASIO_NOEXCEPT
  36. : begin_(address_v6()),
  37. end_(address_v6())
  38. {
  39. }
  40. /// Construct an range that represents the given range of addresses.
  41. explicit basic_address_range(const iterator& first,
  42. const iterator& last) BOOST_ASIO_NOEXCEPT
  43. : begin_(first),
  44. end_(last)
  45. {
  46. }
  47. /// Copy constructor.
  48. basic_address_range(const basic_address_range& other) BOOST_ASIO_NOEXCEPT
  49. : begin_(other.begin_),
  50. end_(other.end_)
  51. {
  52. }
  53. #if defined(BOOST_ASIO_HAS_MOVE)
  54. /// Move constructor.
  55. basic_address_range(basic_address_range&& other) BOOST_ASIO_NOEXCEPT
  56. : begin_(BOOST_ASIO_MOVE_CAST(iterator)(other.begin_)),
  57. end_(BOOST_ASIO_MOVE_CAST(iterator)(other.end_))
  58. {
  59. }
  60. #endif // defined(BOOST_ASIO_HAS_MOVE)
  61. /// Assignment operator.
  62. basic_address_range& operator=(
  63. const basic_address_range& other) BOOST_ASIO_NOEXCEPT
  64. {
  65. begin_ = other.begin_;
  66. end_ = other.end_;
  67. return *this;
  68. }
  69. #if defined(BOOST_ASIO_HAS_MOVE)
  70. /// Move assignment operator.
  71. basic_address_range& operator=(
  72. basic_address_range&& other) BOOST_ASIO_NOEXCEPT
  73. {
  74. begin_ = BOOST_ASIO_MOVE_CAST(iterator)(other.begin_);
  75. end_ = BOOST_ASIO_MOVE_CAST(iterator)(other.end_);
  76. return *this;
  77. }
  78. #endif // defined(BOOST_ASIO_HAS_MOVE)
  79. /// Obtain an iterator that points to the start of the range.
  80. iterator begin() const BOOST_ASIO_NOEXCEPT
  81. {
  82. return begin_;
  83. }
  84. /// Obtain an iterator that points to the end of the range.
  85. iterator end() const BOOST_ASIO_NOEXCEPT
  86. {
  87. return end_;
  88. }
  89. /// Determine whether the range is empty.
  90. bool empty() const BOOST_ASIO_NOEXCEPT
  91. {
  92. return begin_ == end_;
  93. }
  94. /// Find an address in the range.
  95. iterator find(const address_v6& addr) const BOOST_ASIO_NOEXCEPT
  96. {
  97. return addr >= *begin_ && addr < *end_ ? iterator(addr) : end_;
  98. }
  99. private:
  100. iterator begin_;
  101. iterator end_;
  102. };
  103. /// Represents a range of IPv6 addresses.
  104. typedef basic_address_range<address_v6> address_v6_range;
  105. } // namespace ip
  106. } // namespace asio
  107. } // namespace boost
  108. #include <boost/asio/detail/pop_options.hpp>
  109. #endif // BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP