From cba39c6af7d336ffd325c172088323e924b93b3b Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Tue, 28 Apr 2015 09:46:32 +1000 Subject: [PATCH] Add allocator-aware accessors to ip::basic_resolver_entry. --- asio/include/asio/ip/basic_resolver_entry.hpp | 18 ++++++ asio/src/tests/unit/ip/tcp.cpp | 57 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/asio/include/asio/ip/basic_resolver_entry.hpp b/asio/include/asio/ip/basic_resolver_entry.hpp index 8ad45a83..77da9e1e 100644 --- a/asio/include/asio/ip/basic_resolver_entry.hpp +++ b/asio/include/asio/ip/basic_resolver_entry.hpp @@ -74,12 +74,30 @@ public: return host_name_; } + /// Get the host name associated with the entry. + template + std::basic_string, Allocator> host_name( + const Allocator& alloc = Allocator()) const + { + return std::basic_string, Allocator>( + host_name_.c_str(), alloc); + } + /// Get the service name associated with the entry. std::string service_name() const { return service_name_; } + /// Get the service name associated with the entry. + template + std::basic_string, Allocator> service_name( + const Allocator& alloc = Allocator()) const + { + return std::basic_string, Allocator>( + service_name_.c_str(), alloc); + } + private: endpoint_type endpoint_; std::string host_name_; diff --git a/asio/src/tests/unit/ip/tcp.cpp b/asio/src/tests/unit/ip/tcp.cpp index de710e21..c7b7c0d1 100644 --- a/asio/src/tests/unit/ip/tcp.cpp +++ b/asio/src/tests/unit/ip/tcp.cpp @@ -1023,6 +1023,62 @@ void test() //------------------------------------------------------------------------------ +// ip_tcp_resolver_entry_compile test +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// The following test checks that all public member functions on the class +// ip::tcp::resolver::entry compile and link correctly. Runtime failures are +// ignored. + +namespace ip_tcp_resolver_entry_compile { + +void test() +{ + using namespace asio; + namespace ip = asio::ip; + const ip::tcp::endpoint endpoint; + const std::string host_name; + const std::string service_name; + const std::allocator alloc; + + try + { + // basic_resolver_entry constructors. + + const ip::basic_resolver_entry entry1; + ip::basic_resolver_entry entry2(endpoint, host_name, service_name); + ip::basic_resolver_entry entry3(entry1); +#if defined(ASIO_HAS_MOVE) + ip::basic_resolver_entry entry4(std::move(entry2)); +#endif // defined(ASIO_HAS_MOVE) + + // basic_resolver_entry functions. + + ip::tcp::endpoint e1 = entry1.endpoint(); + (void)e1; + + ip::tcp::endpoint e2 = entry1; + (void)e2; + + std::string s1 = entry1.host_name(); + (void)s1; + + std::string s2 = entry1.host_name(alloc); + (void)s2; + + std::string s3 = entry1.service_name(); + (void)s3; + + std::string s4 = entry1.service_name(alloc); + (void)s4; + } + catch (std::exception&) + { + } +} + +} // namespace ip_tcp_resolver_compile +//------------------------------------------------------------------------------ + ASIO_TEST_SUITE ( "ip/tcp", @@ -1033,4 +1089,5 @@ ASIO_TEST_SUITE ASIO_TEST_CASE(ip_tcp_acceptor_compile::test) ASIO_TEST_CASE(ip_tcp_acceptor_runtime::test) ASIO_TEST_CASE(ip_tcp_resolver_compile::test) + ASIO_TEST_CASE(ip_tcp_resolver_entry_compile::test) )