src: Updating code style to conform (more or less) to ndn-cxx style
Also, adding .clang-format that describes the applied style. Note that
this style requires a slightly customized version of clang-format.
diff --git a/model/ndn-face.cpp b/model/ndn-face.cpp
index 6b23dd7..505c2b4 100644
--- a/model/ndn-face.cpp
+++ b/model/ndn-face.cpp
@@ -39,25 +39,24 @@
#include <boost/ref.hpp>
-NS_LOG_COMPONENT_DEFINE ("ndn.Face");
+NS_LOG_COMPONENT_DEFINE("ndn.Face");
namespace ns3 {
namespace ndn {
-NS_OBJECT_ENSURE_REGISTERED (Face);
+NS_OBJECT_ENSURE_REGISTERED(Face);
TypeId
-Face::GetTypeId ()
+Face::GetTypeId()
{
- static TypeId tid = TypeId ("ns3::ndn::Face")
- .SetParent<Object> ()
- .SetGroupName ("Ndn")
- .AddAttribute ("Id", "Face id (unique integer for the Ndn stack on this node)",
- TypeId::ATTR_GET, // allow only getting it.
- UintegerValue (0),
- MakeUintegerAccessor (&Face::m_id),
- MakeUintegerChecker<uint32_t> ())
- ;
+ static TypeId tid =
+ TypeId("ns3::ndn::Face")
+ .SetParent<Object>()
+ .SetGroupName("Ndn")
+ .AddAttribute("Id", "Face id (unique integer for the Ndn stack on this node)",
+ TypeId::ATTR_GET, // allow only getting it.
+ UintegerValue(0), MakeUintegerAccessor(&Face::m_id),
+ MakeUintegerChecker<uint32_t>());
return tid;
}
@@ -66,26 +65,26 @@
* with no IP addresses. Before becoming useable, the user must
* invoke SetUp on them once an Ndn address and mask have been set.
*/
-Face::Face (Ptr<Node> node)
- : m_node (node)
- , m_upstreamInterestHandler (MakeNullCallback< void, Ptr<Face>, Ptr<Interest> > ())
- , m_upstreamDataHandler (MakeNullCallback< void, Ptr<Face>, Ptr<Data> > ())
- , m_ifup (false)
- , m_id ((uint32_t)-1)
- , m_metric (0)
- , m_flags (0)
+Face::Face(Ptr<Node> node)
+ : m_node(node)
+ , m_upstreamInterestHandler(MakeNullCallback<void, Ptr<Face>, Ptr<Interest>>())
+ , m_upstreamDataHandler(MakeNullCallback<void, Ptr<Face>, Ptr<Data>>())
+ , m_ifup(false)
+ , m_id((uint32_t)-1)
+ , m_metric(0)
+ , m_flags(0)
{
- NS_LOG_FUNCTION (this << node);
+ NS_LOG_FUNCTION(this << node);
- NS_ASSERT_MSG (node != 0, "node cannot be NULL. Check the code");
+ NS_ASSERT_MSG(node != 0, "node cannot be NULL. Check the code");
}
-Face::~Face ()
+Face::~Face()
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION_NOARGS();
}
-Face::Face (const Face &)
+Face::Face(const Face&)
{
}
@@ -95,152 +94,146 @@
}
Ptr<Node>
-Face::GetNode () const
+Face::GetNode() const
{
return m_node;
}
void
-Face::RegisterProtocolHandlers (const InterestHandler &interestHandler, const DataHandler &dataHandler)
+Face::RegisterProtocolHandlers(const InterestHandler& interestHandler,
+ const DataHandler& dataHandler)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION_NOARGS();
m_upstreamInterestHandler = interestHandler;
m_upstreamDataHandler = dataHandler;
}
void
-Face::UnRegisterProtocolHandlers ()
+Face::UnRegisterProtocolHandlers()
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION_NOARGS();
- m_upstreamInterestHandler = MakeNullCallback< void, Ptr<Face>, Ptr<Interest> > ();
- m_upstreamDataHandler = MakeNullCallback< void, Ptr<Face>, Ptr<Data> > ();
-}
-
-
-bool
-Face::SendInterest (Ptr<const Interest> interest)
-{
- NS_LOG_FUNCTION (this << boost::cref (*this) << interest->GetName ());
-
- if (!IsUp ())
- {
- return false;
- }
-
- return Send (Wire::FromInterest (interest));
+ m_upstreamInterestHandler = MakeNullCallback<void, Ptr<Face>, Ptr<Interest>>();
+ m_upstreamDataHandler = MakeNullCallback<void, Ptr<Face>, Ptr<Data>>();
}
bool
-Face::SendData (Ptr<const Data> data)
+Face::SendInterest(Ptr<const Interest> interest)
{
- NS_LOG_FUNCTION (this << data);
+ NS_LOG_FUNCTION(this << boost::cref(*this) << interest->GetName());
- if (!IsUp ())
- {
- return false;
- }
+ if (!IsUp()) {
+ return false;
+ }
- return Send (Wire::FromData (data));
+ return Send(Wire::FromInterest(interest));
}
bool
-Face::Send (Ptr<Packet> packet)
+Face::SendData(Ptr<const Data> data)
+{
+ NS_LOG_FUNCTION(this << data);
+
+ if (!IsUp()) {
+ return false;
+ }
+
+ return Send(Wire::FromData(data));
+}
+
+bool
+Face::Send(Ptr<Packet> packet)
{
FwHopCountTag hopCount;
- bool tagExists = packet->RemovePacketTag (hopCount);
- if (tagExists)
- {
- hopCount.Increment ();
- packet->AddPacketTag (hopCount);
- }
+ bool tagExists = packet->RemovePacketTag(hopCount);
+ if (tagExists) {
+ hopCount.Increment();
+ packet->AddPacketTag(hopCount);
+ }
return true;
}
bool
-Face::Receive (Ptr<const Packet> p)
+Face::Receive(Ptr<const Packet> p)
{
- NS_LOG_FUNCTION (this << p << p->GetSize ());
+ NS_LOG_FUNCTION(this << p << p->GetSize());
- if (!IsUp ())
- {
- // no tracing here. If we were off while receiving, we shouldn't even know that something was there
+ if (!IsUp()) {
+ // no tracing here. If we were off while receiving, we shouldn't even know that something was
+ // there
+ return false;
+ }
+
+ Ptr<Packet> packet = p->Copy(); // give upper layers a rw copy of the packet
+ try {
+ HeaderHelper::Type type = HeaderHelper::GetNdnHeaderType(packet);
+ switch (type) {
+ case HeaderHelper::INTEREST_NDNSIM:
+ return ReceiveInterest(Wire::ToInterest(packet, Wire::WIRE_FORMAT_NDNSIM));
+ case HeaderHelper::INTEREST_CCNB:
+ return ReceiveInterest(Wire::ToInterest(packet, Wire::WIRE_FORMAT_CCNB));
+ case HeaderHelper::CONTENT_OBJECT_NDNSIM:
+ return ReceiveData(Wire::ToData(packet, Wire::WIRE_FORMAT_NDNSIM));
+ case HeaderHelper::CONTENT_OBJECT_CCNB:
+ return ReceiveData(Wire::ToData(packet, Wire::WIRE_FORMAT_CCNB));
+ default:
+ NS_FATAL_ERROR("Not supported NDN header");
return false;
}
- Ptr<Packet> packet = p->Copy (); // give upper layers a rw copy of the packet
- try
- {
- HeaderHelper::Type type = HeaderHelper::GetNdnHeaderType (packet);
- switch (type)
- {
- case HeaderHelper::INTEREST_NDNSIM:
- return ReceiveInterest (Wire::ToInterest (packet, Wire::WIRE_FORMAT_NDNSIM));
- case HeaderHelper::INTEREST_CCNB:
- return ReceiveInterest (Wire::ToInterest (packet, Wire::WIRE_FORMAT_CCNB));
- case HeaderHelper::CONTENT_OBJECT_NDNSIM:
- return ReceiveData (Wire::ToData (packet, Wire::WIRE_FORMAT_NDNSIM));
- case HeaderHelper::CONTENT_OBJECT_CCNB:
- return ReceiveData (Wire::ToData (packet, Wire::WIRE_FORMAT_CCNB));
- default:
- NS_FATAL_ERROR ("Not supported NDN header");
- return false;
- }
-
- // exception will be thrown if packet is not recognized
- }
- catch (UnknownHeaderException)
- {
- NS_FATAL_ERROR ("Unknown NDN header. Should not happen");
- return false;
- }
+ // exception will be thrown if packet is not recognized
+ }
+ catch (UnknownHeaderException) {
+ NS_FATAL_ERROR("Unknown NDN header. Should not happen");
+ return false;
+ }
return false;
}
bool
-Face::ReceiveInterest (Ptr<Interest> interest)
+Face::ReceiveInterest(Ptr<Interest> interest)
{
- if (!IsUp ())
- {
- // no tracing here. If we were off while receiving, we shouldn't even know that something was there
- return false;
- }
+ if (!IsUp()) {
+ // no tracing here. If we were off while receiving, we shouldn't even know that something was
+ // there
+ return false;
+ }
- m_upstreamInterestHandler (this, interest);
+ m_upstreamInterestHandler(this, interest);
return true;
}
bool
-Face::ReceiveData (Ptr<Data> data)
+Face::ReceiveData(Ptr<Data> data)
{
- if (!IsUp ())
- {
- // no tracing here. If we were off while receiving, we shouldn't even know that something was there
- return false;
- }
+ if (!IsUp()) {
+ // no tracing here. If we were off while receiving, we shouldn't even know that something was
+ // there
+ return false;
+ }
- m_upstreamDataHandler (this, data);
+ m_upstreamDataHandler(this, data);
return true;
}
void
-Face::SetMetric (uint16_t metric)
+Face::SetMetric(uint16_t metric)
{
- NS_LOG_FUNCTION (metric);
+ NS_LOG_FUNCTION(metric);
m_metric = metric;
}
uint16_t
-Face::GetMetric (void) const
+Face::GetMetric(void) const
{
return m_metric;
}
void
-Face::SetFlags (uint32_t flags)
+Face::SetFlags(uint32_t flags)
{
m_flags = flags;
}
@@ -248,8 +241,9 @@
bool
Face::operator== (const Face &face) const
{
- NS_ASSERT_MSG (m_node->GetId () == face.m_node->GetId (),
- "Faces of different nodes should not be compared to each other: " << *this << " == " << face);
+ NS_ASSERT_MSG(m_node->GetId() == face.m_node->GetId(),
+ "Faces of different nodes should not be compared to each other: " << *this << " == "
+ << face);
return (m_id == face.m_id);
}
@@ -257,26 +251,26 @@
bool
Face::operator< (const Face &face) const
{
- NS_ASSERT_MSG (m_node->GetId () == face.m_node->GetId (),
- "Faces of different nodes should not be compared to each other: " << *this << " == " << face);
+ NS_ASSERT_MSG(m_node->GetId() == face.m_node->GetId(),
+ "Faces of different nodes should not be compared to each other: " << *this << " == "
+ << face);
return (m_id < face.m_id);
}
std::ostream&
-Face::Print (std::ostream &os) const
+Face::Print(std::ostream& os) const
{
- os << "id=" << GetId ();
+ os << "id=" << GetId();
return os;
}
std::ostream&
-operator<< (std::ostream& os, const Face &face)
+operator<<(std::ostream& os, const Face& face)
{
- face.Print (os);
+ face.Print(os);
return os;
}
} // namespace ndn
} // namespace ns3
-