123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- #ifndef ASIO_IP_BASIC_ENDPOINT_HPP
- #define ASIO_IP_BASIC_ENDPOINT_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include "asio/detail/config.hpp"
- #include <functional>
- #include "asio/detail/cstdint.hpp"
- #include "asio/ip/address.hpp"
- #include "asio/ip/detail/endpoint.hpp"
- #if !defined(ASIO_NO_IOSTREAM)
- # include <iosfwd>
- #endif
- #include "asio/detail/push_options.hpp"
- namespace asio {
- namespace ip {
- typedef uint_least16_t port_type;
- template <typename InternetProtocol>
- class basic_endpoint
- {
- public:
-
- typedef InternetProtocol protocol_type;
-
-
- #if defined(GENERATING_DOCUMENTATION)
- typedef implementation_defined data_type;
- #else
- typedef asio::detail::socket_addr_type data_type;
- #endif
-
- basic_endpoint() noexcept
- : impl_()
- {
- }
-
-
-
-
-
- basic_endpoint(const InternetProtocol& internet_protocol,
- port_type port_num) noexcept
- : impl_(internet_protocol.family(), port_num)
- {
- }
-
-
-
- basic_endpoint(const asio::ip::address& addr,
- port_type port_num) noexcept
- : impl_(addr, port_num)
- {
- }
-
- basic_endpoint(const basic_endpoint& other) noexcept
- : impl_(other.impl_)
- {
- }
-
- basic_endpoint(basic_endpoint&& other) noexcept
- : impl_(other.impl_)
- {
- }
-
- basic_endpoint& operator=(const basic_endpoint& other) noexcept
- {
- impl_ = other.impl_;
- return *this;
- }
-
- basic_endpoint& operator=(basic_endpoint&& other) noexcept
- {
- impl_ = other.impl_;
- return *this;
- }
-
- protocol_type protocol() const noexcept
- {
- if (impl_.is_v4())
- return InternetProtocol::v4();
- return InternetProtocol::v6();
- }
-
- data_type* data() noexcept
- {
- return impl_.data();
- }
-
- const data_type* data() const noexcept
- {
- return impl_.data();
- }
-
- std::size_t size() const noexcept
- {
- return impl_.size();
- }
-
- void resize(std::size_t new_size)
- {
- impl_.resize(new_size);
- }
-
- std::size_t capacity() const noexcept
- {
- return impl_.capacity();
- }
-
-
- port_type port() const noexcept
- {
- return impl_.port();
- }
-
-
- void port(port_type port_num) noexcept
- {
- impl_.port(port_num);
- }
-
- asio::ip::address address() const noexcept
- {
- return impl_.address();
- }
-
- void address(const asio::ip::address& addr) noexcept
- {
- impl_.address(addr);
- }
-
- friend bool operator==(const basic_endpoint<InternetProtocol>& e1,
- const basic_endpoint<InternetProtocol>& e2) noexcept
- {
- return e1.impl_ == e2.impl_;
- }
-
- friend bool operator!=(const basic_endpoint<InternetProtocol>& e1,
- const basic_endpoint<InternetProtocol>& e2) noexcept
- {
- return !(e1 == e2);
- }
-
- friend bool operator<(const basic_endpoint<InternetProtocol>& e1,
- const basic_endpoint<InternetProtocol>& e2) noexcept
- {
- return e1.impl_ < e2.impl_;
- }
-
- friend bool operator>(const basic_endpoint<InternetProtocol>& e1,
- const basic_endpoint<InternetProtocol>& e2) noexcept
- {
- return e2.impl_ < e1.impl_;
- }
-
- friend bool operator<=(const basic_endpoint<InternetProtocol>& e1,
- const basic_endpoint<InternetProtocol>& e2) noexcept
- {
- return !(e2 < e1);
- }
-
- friend bool operator>=(const basic_endpoint<InternetProtocol>& e1,
- const basic_endpoint<InternetProtocol>& e2) noexcept
- {
- return !(e1 < e2);
- }
- private:
-
- asio::ip::detail::endpoint impl_;
- };
- #if !defined(ASIO_NO_IOSTREAM)
- template <typename Elem, typename Traits, typename InternetProtocol>
- std::basic_ostream<Elem, Traits>& operator<<(
- std::basic_ostream<Elem, Traits>& os,
- const basic_endpoint<InternetProtocol>& endpoint);
- #endif
- }
- }
- namespace std {
- template <typename InternetProtocol>
- struct hash<asio::ip::basic_endpoint<InternetProtocol>>
- {
- std::size_t operator()(
- const asio::ip::basic_endpoint<InternetProtocol>& ep)
- const noexcept
- {
- std::size_t hash1 = std::hash<asio::ip::address>()(ep.address());
- std::size_t hash2 = std::hash<unsigned short>()(ep.port());
- return hash1 ^ (hash2 + 0x9e3779b9 + (hash1 << 6) + (hash1 >> 2));
- }
- };
- }
- #include "asio/detail/pop_options.hpp"
- #include "asio/ip/impl/basic_endpoint.hpp"
- #endif
|