Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/asio/ip/address_v6_iterator.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ip/address_v6_iterator.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //                         Oliver Kowalke (oliver dot kowalke at gmail dot com)
0007 //
0008 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0009 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 
0012 #ifndef BOOST_ASIO_IP_ADDRESS_V6_ITERATOR_HPP
0013 #define BOOST_ASIO_IP_ADDRESS_V6_ITERATOR_HPP
0014 
0015 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0016 # pragma once
0017 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0018 
0019 #include <boost/asio/detail/config.hpp>
0020 #include <boost/asio/ip/address_v6.hpp>
0021 
0022 #include <boost/asio/detail/push_options.hpp>
0023 
0024 namespace boost {
0025 namespace asio {
0026 namespace ip {
0027 
0028 template <typename> class basic_address_iterator;
0029 
0030 /// An input iterator that can be used for traversing IPv6 addresses.
0031 /**
0032  * In addition to satisfying the input iterator requirements, this iterator
0033  * also supports decrement.
0034  *
0035  * @par Thread Safety
0036  * @e Distinct @e objects: Safe.@n
0037  * @e Shared @e objects: Unsafe.
0038  */
0039 template <> class basic_address_iterator<address_v6>
0040 {
0041 public:
0042   /// The type of the elements pointed to by the iterator.
0043   typedef address_v6 value_type;
0044 
0045   /// Distance between two iterators.
0046   typedef std::ptrdiff_t difference_type;
0047 
0048   /// The type of a pointer to an element pointed to by the iterator.
0049   typedef const address_v6* pointer;
0050 
0051   /// The type of a reference to an element pointed to by the iterator.
0052   typedef const address_v6& reference;
0053 
0054   /// Denotes that the iterator satisfies the input iterator requirements.
0055   typedef std::input_iterator_tag iterator_category;
0056 
0057   /// Construct an iterator that points to the specified address.
0058   basic_address_iterator(const address_v6& addr) noexcept
0059     : address_(addr)
0060   {
0061   }
0062 
0063   /// Copy constructor.
0064   basic_address_iterator(
0065       const basic_address_iterator& other) noexcept
0066     : address_(other.address_)
0067   {
0068   }
0069 
0070   /// Move constructor.
0071   basic_address_iterator(basic_address_iterator&& other) noexcept
0072     : address_(static_cast<address_v6&&>(other.address_))
0073   {
0074   }
0075 
0076   /// Assignment operator.
0077   basic_address_iterator& operator=(
0078       const basic_address_iterator& other) noexcept
0079   {
0080     address_ = other.address_;
0081     return *this;
0082   }
0083 
0084   /// Move assignment operator.
0085   basic_address_iterator& operator=(basic_address_iterator&& other) noexcept
0086   {
0087     address_ = static_cast<address_v6&&>(other.address_);
0088     return *this;
0089   }
0090 
0091   /// Dereference the iterator.
0092   const address_v6& operator*() const noexcept
0093   {
0094     return address_;
0095   }
0096 
0097   /// Dereference the iterator.
0098   const address_v6* operator->() const noexcept
0099   {
0100     return &address_;
0101   }
0102 
0103   /// Pre-increment operator.
0104   basic_address_iterator& operator++() noexcept
0105   {
0106     for (int i = 15; i >= 0; --i)
0107     {
0108       if (address_.addr_.s6_addr[i] < 0xFF)
0109       {
0110         ++address_.addr_.s6_addr[i];
0111         break;
0112       }
0113 
0114       address_.addr_.s6_addr[i] = 0;
0115     }
0116 
0117     return *this;
0118   }
0119 
0120   /// Post-increment operator.
0121   basic_address_iterator operator++(int) noexcept
0122   {
0123     basic_address_iterator tmp(*this);
0124     ++*this;
0125     return tmp;
0126   }
0127 
0128   /// Pre-decrement operator.
0129   basic_address_iterator& operator--() noexcept
0130   {
0131     for (int i = 15; i >= 0; --i)
0132     {
0133       if (address_.addr_.s6_addr[i] > 0)
0134       {
0135         --address_.addr_.s6_addr[i];
0136         break;
0137       }
0138 
0139       address_.addr_.s6_addr[i] = 0xFF;
0140     }
0141 
0142     return *this;
0143   }
0144 
0145   /// Post-decrement operator.
0146   basic_address_iterator operator--(int)
0147   {
0148     basic_address_iterator tmp(*this);
0149     --*this;
0150     return tmp;
0151   }
0152 
0153   /// Compare two addresses for equality.
0154   friend bool operator==(const basic_address_iterator& a,
0155       const basic_address_iterator& b)
0156   {
0157     return a.address_ == b.address_;
0158   }
0159 
0160   /// Compare two addresses for inequality.
0161   friend bool operator!=(const basic_address_iterator& a,
0162       const basic_address_iterator& b)
0163   {
0164     return a.address_ != b.address_;
0165   }
0166 
0167 private:
0168   address_v6 address_;
0169 };
0170 
0171 /// An input iterator that can be used for traversing IPv6 addresses.
0172 typedef basic_address_iterator<address_v6> address_v6_iterator;
0173 
0174 } // namespace ip
0175 } // namespace asio
0176 } // namespace boost
0177 
0178 #include <boost/asio/detail/pop_options.hpp>
0179 
0180 #endif // BOOST_ASIO_IP_ADDRESS_V6_ITERATOR_HPP