#ifndef IP_ADDRESS_HPP_ #define IP_ADDRESS_HPP_ #include #include #include #include "detail/address_convenience.hpp" namespace ariba { namespace addressing { using boost::asio::ip::address; using boost::asio::ip::address_v4; using boost::asio::ip::address_v6; /** * TODO: Doc * * @author Sebastian Mies */ class ip_address: public detail::address_convenience { private: address addr; static const std::string type_name_ip; public: ip_address() : addr() { } ip_address(const ip_address& copy) : addr(copy.addr) { } ip_address(const address& addr) : addr(addr) { } ip_address(const address_v4& addr) : addr(addr) { } ip_address(const address_v6& addr) : addr(addr) { } ip_address(const std::string& text) { assign(text); } ip_address(const char* text) { assign(std::string(text)); } ip_address(const uint8_t* bytes, size_t size) { assign(bytes, size); } //--- compare operations -------------------------------------------------- /// implements comparison operators int compare_to(const ip_address& rhs) const { if (addr == rhs.addr) return 0; if (addr < rhs.addr) return -1; else return 1; } //--- byte representation ------------------------------------------------- /// returns true, if this address has a fixed size in bytes bool is_bytes_size_static() const { return false; } /// returns the number of bytes used for serialization of this address size_t to_bytes_size() const { return addr.is_v4() ? 4 : 16; } /// converts this address to a binary representation void to_bytes(uint8_t* bytes) const { if (addr.is_v4()) { address_v4::bytes_type bytes_ = addr.to_v4().to_bytes(); for (size_t i=0; iaddr = addr; } }; }} // namespace ariba::addressing namespace boost { // boost hash function template<> struct hash: public std::unary_function { std::size_t operator()(const ariba::addressing::ip_address& ep) const { return hash_value(ep.to_string()); } }; } #endif /* IP_ADDRESS_HPP_ */