address_v6_range.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // ip/address_v6_range.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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() 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) noexcept
  43. : begin_(first),
  44. end_(last)
  45. {
  46. }
  47. /// Copy constructor.
  48. basic_address_range(const basic_address_range& other) noexcept
  49. : begin_(other.begin_),
  50. end_(other.end_)
  51. {
  52. }
  53. /// Move constructor.
  54. basic_address_range(basic_address_range&& other) noexcept
  55. : begin_(static_cast<iterator&&>(other.begin_)),
  56. end_(static_cast<iterator&&>(other.end_))
  57. {
  58. }
  59. /// Assignment operator.
  60. basic_address_range& operator=(
  61. const basic_address_range& other) noexcept
  62. {
  63. begin_ = other.begin_;
  64. end_ = other.end_;
  65. return *this;
  66. }
  67. /// Move assignment operator.
  68. basic_address_range& operator=(basic_address_range&& other) noexcept
  69. {
  70. begin_ = static_cast<iterator&&>(other.begin_);
  71. end_ = static_cast<iterator&&>(other.end_);
  72. return *this;
  73. }
  74. /// Obtain an iterator that points to the start of the range.
  75. iterator begin() const noexcept
  76. {
  77. return begin_;
  78. }
  79. /// Obtain an iterator that points to the end of the range.
  80. iterator end() const noexcept
  81. {
  82. return end_;
  83. }
  84. /// Determine whether the range is empty.
  85. bool empty() const noexcept
  86. {
  87. return begin_ == end_;
  88. }
  89. /// Find an address in the range.
  90. iterator find(const address_v6& addr) const noexcept
  91. {
  92. return addr >= *begin_ && addr < *end_ ? iterator(addr) : end_;
  93. }
  94. private:
  95. iterator begin_;
  96. iterator end_;
  97. };
  98. /// Represents a range of IPv6 addresses.
  99. typedef basic_address_range<address_v6> address_v6_range;
  100. } // namespace ip
  101. } // namespace asio
  102. } // namespace boost
  103. #include <boost/asio/detail/pop_options.hpp>
  104. #endif // BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP