Clementine
address_v4_range.hpp
1 //
2 // ip/address_v4_range.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
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)
9 //
10 
11 #ifndef ASIO_IP_ADDRESS_V4_RANGE_HPP
12 #define ASIO_IP_ADDRESS_V4_RANGE_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 #include "asio/ip/address_v4_iterator.hpp"
20 
21 #include "asio/detail/push_options.hpp"
22 
23 namespace asio {
24 namespace ip {
25 
26 template <typename> class basic_address_range;
27 
29 
34 template <> class basic_address_range<address_v4>
35 {
36 public:
39 
41  basic_address_range() ASIO_NOEXCEPT
42  : begin_(address_v4()),
43  end_(address_v4())
44  {
45  }
46 
48  explicit basic_address_range(const iterator& first,
49  const iterator& last) ASIO_NOEXCEPT
50  : begin_(first),
51  end_(last)
52  {
53  }
54 
56  basic_address_range(const basic_address_range& other) ASIO_NOEXCEPT
57  : begin_(other.begin_),
58  end_(other.end_)
59  {
60  }
61 
62 #if defined(ASIO_HAS_MOVE)
63  basic_address_range(basic_address_range&& other) ASIO_NOEXCEPT
65  : begin_(ASIO_MOVE_CAST(iterator)(other.begin_)),
66  end_(ASIO_MOVE_CAST(iterator)(other.end_))
67  {
68  }
69 #endif // defined(ASIO_HAS_MOVE)
70 
73  const basic_address_range& other) ASIO_NOEXCEPT
74  {
75  begin_ = other.begin_;
76  end_ = other.end_;
77  return *this;
78  }
79 
80 #if defined(ASIO_HAS_MOVE)
81  basic_address_range& operator=(
83  basic_address_range&& other) ASIO_NOEXCEPT
84  {
85  begin_ = ASIO_MOVE_CAST(iterator)(other.begin_);
86  end_ = ASIO_MOVE_CAST(iterator)(other.end_);
87  return *this;
88  }
89 #endif // defined(ASIO_HAS_MOVE)
90 
92  iterator begin() const ASIO_NOEXCEPT
93  {
94  return begin_;
95  }
96 
98  iterator end() const ASIO_NOEXCEPT
99  {
100  return end_;
101  }
102 
104  bool empty() const ASIO_NOEXCEPT
105  {
106  return size() == 0;
107  }
108 
110  std::size_t size() const ASIO_NOEXCEPT
111  {
112  return end_->to_uint() - begin_->to_uint();
113  }
114 
116  iterator find(const address_v4& addr) const ASIO_NOEXCEPT
117  {
118  return addr >= *begin_ && addr < *end_ ? iterator(addr) : end_;
119  }
120 
121 private:
122  iterator begin_;
123  iterator end_;
124 };
125 
128 
129 } // namespace ip
130 } // namespace asio
131 
132 #include "asio/detail/pop_options.hpp"
133 
134 #endif // ASIO_IP_ADDRESS_V4_RANGE_HPP
basic_address_range() ASIO_NOEXCEPT
Construct an empty range.
Definition: address_v4_range.hpp:41
iterator begin() const ASIO_NOEXCEPT
Obtain an iterator that points to the start of the range.
Definition: address_v4_range.hpp:92
Implements IP version 4 style addresses.
Definition: address_v4.hpp:45
basic_address_range & operator=(const basic_address_range &other) ASIO_NOEXCEPT
Assignment operator.
Definition: address_v4_range.hpp:72
An input iterator that can be used for traversing IPv4 addresses.
Definition: address_v4_iterator.hpp:37
Represents a range of IPv4 addresses.
Definition: address_v4_range.hpp:34
iterator end() const ASIO_NOEXCEPT
Obtain an iterator that points to the end of the range.
Definition: address_v4_range.hpp:98
basic_address_range(const basic_address_range &other) ASIO_NOEXCEPT
Copy constructor.
Definition: address_v4_range.hpp:56
bool empty() const ASIO_NOEXCEPT
Determine whether the range is empty.
Definition: address_v4_range.hpp:104
basic_address_range(const iterator &first, const iterator &last) ASIO_NOEXCEPT
Construct an range that represents the given range of addresses.
Definition: address_v4_range.hpp:48
basic_address_iterator< address_v4 > iterator
The type of an iterator that points into the range.
Definition: address_v4_range.hpp:38
std::size_t size() const ASIO_NOEXCEPT
Return the size of the range.
Definition: address_v4_range.hpp:110
Definition: address_v4_range.hpp:26
iterator find(const address_v4 &addr) const ASIO_NOEXCEPT
Find an address in the range.
Definition: address_v4_range.hpp:116
Definition: any_io_executor.hpp:28