Clementine
basic_resolver_entry.hpp
1 //
2 // ip/basic_resolver_entry.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_BASIC_RESOLVER_ENTRY_HPP
12 #define ASIO_IP_BASIC_RESOLVER_ENTRY_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 <string>
20 #include "asio/detail/string_view.hpp"
21 
22 #include "asio/detail/push_options.hpp"
23 
24 namespace asio {
25 namespace ip {
26 
28 
36 template <typename InternetProtocol>
38 {
39 public:
41  typedef InternetProtocol protocol_type;
42 
44  typedef typename InternetProtocol::endpoint endpoint_type;
45 
48  {
49  }
50 
52  basic_resolver_entry(const endpoint_type& ep,
53  ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service)
54  : endpoint_(ep),
55  host_name_(static_cast<std::string>(host)),
56  service_name_(static_cast<std::string>(service))
57  {
58  }
59 
61  endpoint_type endpoint() const
62  {
63  return endpoint_;
64  }
65 
67  operator endpoint_type() const
68  {
69  return endpoint_;
70  }
71 
73  std::string host_name() const
74  {
75  return host_name_;
76  }
77 
79  template <class Allocator>
80  std::basic_string<char, std::char_traits<char>, Allocator> host_name(
81  const Allocator& alloc = Allocator()) const
82  {
83  return std::basic_string<char, std::char_traits<char>, Allocator>(
84  host_name_.c_str(), alloc);
85  }
86 
88  std::string service_name() const
89  {
90  return service_name_;
91  }
92 
94  template <class Allocator>
95  std::basic_string<char, std::char_traits<char>, Allocator> service_name(
96  const Allocator& alloc = Allocator()) const
97  {
98  return std::basic_string<char, std::char_traits<char>, Allocator>(
99  service_name_.c_str(), alloc);
100  }
101 
102 private:
103  endpoint_type endpoint_;
104  std::string host_name_;
105  std::string service_name_;
106 };
107 
108 } // namespace ip
109 } // namespace asio
110 
111 #include "asio/detail/pop_options.hpp"
112 
113 #endif // ASIO_IP_BASIC_RESOLVER_ENTRY_HPP
basic_resolver_entry(const endpoint_type &ep, ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service)
Construct with specified endpoint, host name and service name.
Definition: basic_resolver_entry.hpp:52
Definition: awaitable.hpp:421
endpoint_type endpoint() const
Get the endpoint associated with the entry.
Definition: basic_resolver_entry.hpp:61
std::string service_name() const
Get the service name associated with the entry.
Definition: basic_resolver_entry.hpp:88
InternetProtocol::endpoint endpoint_type
The endpoint type associated with the endpoint entry.
Definition: basic_resolver_entry.hpp:44
std::basic_string< char, std::char_traits< char >, Allocator > host_name(const Allocator &alloc=Allocator()) const
Get the host name associated with the entry.
Definition: basic_resolver_entry.hpp:80
std::basic_string< char, std::char_traits< char >, Allocator > service_name(const Allocator &alloc=Allocator()) const
Get the service name associated with the entry.
Definition: basic_resolver_entry.hpp:95
std::string host_name() const
Get the host name associated with the entry.
Definition: basic_resolver_entry.hpp:73
An entry produced by a resolver.
Definition: basic_resolver_entry.hpp:37
basic_resolver_entry()
Default constructor.
Definition: basic_resolver_entry.hpp:47
Definition: any_io_executor.hpp:28
InternetProtocol protocol_type
The protocol type associated with the endpoint entry.
Definition: basic_resolver_entry.hpp:41