Skip to content

Commit

Permalink
Move ostream formatter inside TransportAddress class (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
Acuadros95 authored Mar 23, 2021
1 parent f02ca72 commit 604f8dd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 69 deletions.
67 changes: 0 additions & 67 deletions include/uxr/agent/transport/util/Interface.hpp

This file was deleted.

1 change: 0 additions & 1 deletion include/uxr/agent/transport/util/InterfaceLinux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifndef UXR_AGENT_TRANSPORT_UTIL_INTERFACELINUX_HPP_
#define UXR_AGENT_TRANSPORT_UTIL_INTERFACELINUX_HPP_

#include <uxr/agent/transport/util/Interface.hpp>
#include <uxr/agent/transport/endpoint/IPv4EndPoint.hpp>
#include <uxr/agent/transport/endpoint/IPv6EndPoint.hpp>
#include <uxr/agent/logger/Logger.hpp>
Expand Down
1 change: 0 additions & 1 deletion include/uxr/agent/transport/util/InterfaceWindows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifndef UXR_AGENT_TRANSPORT_UTIL_INTERFACEWINDOWS_HPP_
#define UXR_AGENT_TRANSPORT_UTIL_INTERFACEWINDOWS_HPP_

#include <uxr/agent/transport/util/Interface.hpp>
#include <uxr/agent/transport/endpoint/IPv4EndPoint.hpp>
#include <uxr/agent/transport/endpoint/IPv6EndPoint.hpp>
#include <uxr/agent/logger/Logger.hpp>
Expand Down
51 changes: 51 additions & 0 deletions include/uxr/agent/types/XRCETypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <array>
#include <string>
#include <vector>
#include <iostream>

namespace eprosima { namespace fastcdr {

Expand Down Expand Up @@ -943,6 +944,56 @@ class TransportAddress
*/
virtual void deserialize(eprosima::fastcdr::Cdr &cdr);

/*!
* @brief This function formats the IP address and port to ostream, for logging purpuses.
* @param os ostream object.
* @param address TransportAddress object to format.
* @return ostream object with formated address.
*/
friend std::ostream & operator<<(std::ostream & os, TransportAddress const & address)
{
switch (address._d())
{
case ADDRESS_FORMAT_MEDIUM:
os << int(address.medium_locator().address().at(0)) << "."
<< int(address.medium_locator().address().at(1)) << "."
<< int(address.medium_locator().address().at(2)) << "."
<< int(address.medium_locator().address().at(3)) << ":"
<< address.medium_locator().port();
break;
case ADDRESS_FORMAT_LARGE:
os << std::hex << "["
<< int(address.large_locator().address().at(0))
<< int(address.large_locator().address().at(1))
<< ":"
<< int(address.large_locator().address().at(2))
<< int(address.large_locator().address().at(3))
<< ":"
<< int(address.large_locator().address().at(4))
<< int(address.large_locator().address().at(5))
<< ":"
<< int(address.large_locator().address().at(6))
<< int(address.large_locator().address().at(7))
<< ":"
<< int(address.large_locator().address().at(8))
<< int(address.large_locator().address().at(9))
<< ":"
<< int(address.large_locator().address().at(10))
<< int(address.large_locator().address().at(11))
<< ":"
<< int(address.large_locator().address().at(12))
<< int(address.large_locator().address().at(13))
<< ":"
<< int(address.large_locator().address().at(14))
<< int(address.large_locator().address().at(15))
<< "]:" << std::dec
<< address.large_locator().port();
default:
break;
}
return os;
}

private:
TransportAddressFormat m__d;

Expand Down

0 comments on commit 604f8dd

Please sign in to comment.