// // host.hpp // ~~~~~~~~ // // Copyright (c) 2003-2005 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_IPV4_HOST_HPP #define BOOST_ASIO_IPV4_HOST_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include #include #include #include #include #include #include #include namespace boost { namespace asio { namespace ipv4 { /// Encapsulates information about an IP version 4 host. /** * The boost::asio::ipv4::host structure contains properties to describe a host. * * @par Thread Safety: * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Unsafe. * * @par Concepts: * CopyConstructible, Assignable. */ class host { public: /// Default constructor. host() { } /// Construct from component properties. host(const std::string& name, const boost::asio::ipv4::address& addr) : name_(name) { addresses_.push_back(boost::asio::ipv4::address::any()); } /// Construct from component properties. template host(const std::string& name, const boost::asio::ipv4::address& addr, Name_Iterator alternate_names_begin, Name_Iterator alternate_names_end, Address_Iterator other_addresses_begin, Address_Iterator other_addresses_end) : name_(name) { addresses_.push_back(addr); alternate_names_.insert(alternate_names_.end(), alternate_names_begin, alternate_names_end); addresses_.insert(addresses_.end(), other_addresses_begin, other_addresses_end); } /// Get the name of the host. std::string name() const { return name_; } /// Get the number of alternate names for the host. std::size_t alternate_name_count() const { return alternate_names_.size(); } /// Get the alternate name at the specified index. std::string alternate_name(std::size_t index) const { return alternate_names_[index]; } /// Get the number of addresses for the host. std::size_t address_count() const { return addresses_.size(); } /// Get the address at the specified index. boost::asio::ipv4::address address(std::size_t index) const { return addresses_[index]; } /// Swap the host object's values with another host. void swap(host& other) { name_.swap(other.name_); alternate_names_.swap(other.alternate_names_); addresses_.swap(other.addresses_); } private: // The name of the host. std::string name_; // Alternate names for the host. std::vector alternate_names_; // All IP addresses of the host. std::vector addresses_; }; } // namespace ipv4 } // namespace asio } // namespace boost #include #endif // BOOST_ASIO_IPV4_HOST_HPP