Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:59

0001 //
0002 // ip/address_v4_range.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_IP_ADDRESS_V4_RANGE_HPP
0012 #define BOOST_ASIO_IP_ADDRESS_V4_RANGE_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/ip/address_v4_iterator.hpp>
0020 
0021 #include <boost/asio/detail/push_options.hpp>
0022 
0023 namespace boost {
0024 namespace asio {
0025 namespace ip {
0026 
0027 template <typename> class basic_address_range;
0028 
0029 /// Represents a range of IPv4 addresses.
0030 /**
0031  * @par Thread Safety
0032  * @e Distinct @e objects: Safe.@n
0033  * @e Shared @e objects: Unsafe.
0034  */
0035 template <> class basic_address_range<address_v4>
0036 {
0037 public:
0038   /// The type of an iterator that points into the range.
0039   typedef basic_address_iterator<address_v4> iterator;
0040 
0041   /// Construct an empty range.
0042   basic_address_range() noexcept
0043     : begin_(address_v4()),
0044       end_(address_v4())
0045   {
0046   }
0047 
0048   /// Construct an range that represents the given range of addresses.
0049   explicit basic_address_range(const iterator& first,
0050       const iterator& last) noexcept
0051     : begin_(first),
0052       end_(last)
0053   {
0054   }
0055 
0056   /// Copy constructor.
0057   basic_address_range(const basic_address_range& other) noexcept
0058     : begin_(other.begin_),
0059       end_(other.end_)
0060   {
0061   }
0062 
0063   /// Move constructor.
0064   basic_address_range(basic_address_range&& other) noexcept
0065     : begin_(static_cast<iterator&&>(other.begin_)),
0066       end_(static_cast<iterator&&>(other.end_))
0067   {
0068   }
0069 
0070   /// Assignment operator.
0071   basic_address_range& operator=(const basic_address_range& other) noexcept
0072   {
0073     begin_ = other.begin_;
0074     end_ = other.end_;
0075     return *this;
0076   }
0077 
0078   /// Move assignment operator.
0079   basic_address_range& operator=(basic_address_range&& other) noexcept
0080   {
0081     begin_ = static_cast<iterator&&>(other.begin_);
0082     end_ = static_cast<iterator&&>(other.end_);
0083     return *this;
0084   }
0085 
0086   /// Obtain an iterator that points to the start of the range.
0087   iterator begin() const noexcept
0088   {
0089     return begin_;
0090   }
0091 
0092   /// Obtain an iterator that points to the end of the range.
0093   iterator end() const noexcept
0094   {
0095     return end_;
0096   }
0097 
0098   /// Determine whether the range is empty.
0099   bool empty() const noexcept
0100   {
0101     return size() == 0;
0102   }
0103 
0104   /// Return the size of the range.
0105   std::size_t size() const noexcept
0106   {
0107     return end_->to_uint() - begin_->to_uint();
0108   }
0109 
0110   /// Find an address in the range.
0111   iterator find(const address_v4& addr) const noexcept
0112   {
0113     return addr >= *begin_ && addr < *end_ ? iterator(addr) : end_;
0114   }
0115 
0116 private:
0117   iterator begin_;
0118   iterator end_;
0119 };
0120 
0121 /// Represents a range of IPv4 addresses.
0122 typedef basic_address_range<address_v4> address_v4_range;
0123 
0124 } // namespace ip
0125 } // namespace asio
0126 } // namespace boost
0127 
0128 #include <boost/asio/detail/pop_options.hpp>
0129 
0130 #endif // BOOST_ASIO_IP_ADDRESS_V4_RANGE_HPP