basic_resolver_entry.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // ip/basic_resolver_entry.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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. #ifndef ASIO_IP_BASIC_RESOLVER_ENTRY_HPP
  11. #define ASIO_IP_BASIC_RESOLVER_ENTRY_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include <string>
  17. #include "asio/detail/push_options.hpp"
  18. namespace asio {
  19. namespace ip {
  20. /// An entry produced by a resolver.
  21. /**
  22. * The asio::ip::basic_resolver_entry class template describes an entry
  23. * as returned by a resolver.
  24. *
  25. * @par Thread Safety
  26. * @e Distinct @e objects: Safe.@n
  27. * @e Shared @e objects: Unsafe.
  28. */
  29. template <typename InternetProtocol>
  30. class basic_resolver_entry
  31. {
  32. public:
  33. /// The protocol type associated with the endpoint entry.
  34. typedef InternetProtocol protocol_type;
  35. /// The endpoint type associated with the endpoint entry.
  36. typedef typename InternetProtocol::endpoint endpoint_type;
  37. /// Default constructor.
  38. basic_resolver_entry()
  39. {
  40. }
  41. /// Construct with specified endpoint, host name and service name.
  42. basic_resolver_entry(const endpoint_type& ep,
  43. const std::string& host, const std::string& service)
  44. : endpoint_(ep),
  45. host_name_(host),
  46. service_name_(service)
  47. {
  48. }
  49. /// Get the endpoint associated with the entry.
  50. endpoint_type endpoint() const
  51. {
  52. return endpoint_;
  53. }
  54. /// Convert to the endpoint associated with the entry.
  55. operator endpoint_type() const
  56. {
  57. return endpoint_;
  58. }
  59. /// Get the host name associated with the entry.
  60. std::string host_name() const
  61. {
  62. return host_name_;
  63. }
  64. /// Get the service name associated with the entry.
  65. std::string service_name() const
  66. {
  67. return service_name_;
  68. }
  69. private:
  70. endpoint_type endpoint_;
  71. std::string host_name_;
  72. std::string service_name_;
  73. };
  74. } // namespace ip
  75. } // namespace asio
  76. #include "asio/detail/pop_options.hpp"
  77. #endif // ASIO_IP_BASIC_RESOLVER_ENTRY_HPP