src: improve constness
Change-Id: I8b3084e311642578628ea7c1017dc2a58979ab83
refs: #4472
diff --git a/src/adjacency-list.cpp b/src/adjacency-list.cpp
index c41917c..d5e6dfe 100644
--- a/src/adjacency-list.cpp
+++ b/src/adjacency-list.cpp
@@ -85,7 +85,7 @@
}
bool
-AdjacencyList::operator==(AdjacencyList& adl) const
+AdjacencyList::operator==(const AdjacencyList& adl) const
{
if (size() != adl.size()) {
return false;
@@ -127,9 +127,9 @@
}
bool
-AdjacencyList::isNeighbor(const ndn::Name& adjName)
+AdjacencyList::isNeighbor(const ndn::Name& adjName) const
{
- std::list<Adjacent>::iterator it = find(adjName);
+ std::list<Adjacent>::const_iterator it = find(adjName);
if (it == m_adjList.end())
{
return false;
@@ -158,9 +158,9 @@
}
int32_t
-AdjacencyList::getTimedOutInterestCount(const ndn::Name& neighbor)
+AdjacencyList::getTimedOutInterestCount(const ndn::Name& neighbor) const
{
- std::list<Adjacent>::iterator it = find(neighbor);
+ std::list<Adjacent>::const_iterator it = find(neighbor);
if (it == m_adjList.end()) {
return -1;
}
@@ -168,9 +168,9 @@
}
Adjacent::Status
-AdjacencyList::getStatusOfNeighbor(const ndn::Name& neighbor)
+AdjacencyList::getStatusOfNeighbor(const ndn::Name& neighbor) const
{
- std::list<Adjacent>::iterator it = find(neighbor);
+ std::list<Adjacent>::const_iterator it = find(neighbor);
if (it == m_adjList.end()) {
return Adjacent::STATUS_UNKNOWN;
@@ -225,10 +225,10 @@
}
int32_t
-AdjacencyList::getNumOfActiveNeighbor()
+AdjacencyList::getNumOfActiveNeighbor() const
{
int32_t actNbrCount = 0;
- for (std::list<Adjacent>::iterator it = m_adjList.begin(); it != m_adjList.end(); it++) {
+ for (std::list<Adjacent>::const_iterator it = m_adjList.begin(); it != m_adjList.end(); it++) {
if (it->getStatus() == Adjacent::STATUS_ACTIVE) {
actNbrCount++;
@@ -247,6 +247,17 @@
return it;
}
+std::list<Adjacent>::const_iterator
+AdjacencyList::find(const ndn::Name& adjName) const
+{
+ std::list<Adjacent>::const_iterator it = std::find_if(m_adjList.cbegin(),
+ m_adjList.cend(),
+ std::bind(&Adjacent::compare,
+ _1, std::cref(adjName)));
+ return it;
+}
+
+
AdjacencyList::iterator
AdjacencyList::findAdjacent(const ndn::Name& adjName)
{
diff --git a/src/adjacency-list.hpp b/src/adjacency-list.hpp
index 6d37a94..61205c8 100644
--- a/src/adjacency-list.hpp
+++ b/src/adjacency-list.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2017, The University of Memphis,
+ * Copyright (c) 2014-2018, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -74,16 +74,16 @@
getAdjList() const;
bool
- isNeighbor(const ndn::Name& adjName);
+ isNeighbor(const ndn::Name& adjName) const;
void
incrementTimedOutInterestCount(const ndn::Name& neighbor);
int32_t
- getTimedOutInterestCount(const ndn::Name& neighbor);
+ getTimedOutInterestCount(const ndn::Name& neighbor) const;
Adjacent::Status
- getStatusOfNeighbor(const ndn::Name& neighbor);
+ getStatusOfNeighbor(const ndn::Name& neighbor) const;
void
setStatusOfNeighbor(const ndn::Name& neighbor, Adjacent::Status status);
@@ -120,13 +120,13 @@
isAdjLsaBuildable(const uint32_t interestRetryNo) const;
int32_t
- getNumOfActiveNeighbor();
+ getNumOfActiveNeighbor() const;
Adjacent
getAdjacent(const ndn::Name& adjName);
bool
- operator==(AdjacencyList& adl) const;
+ operator==(const AdjacencyList& adl) const;
size_t
size() const
@@ -187,6 +187,9 @@
iterator
find(const ndn::Name& adjName);
+ const_iterator
+ find(const ndn::Name& adjName) const;
+
private:
std::list<Adjacent> m_adjList;
};
diff --git a/src/adjacent.hpp b/src/adjacent.hpp
index 1e6eac5..72a8d98 100644
--- a/src/adjacent.hpp
+++ b/src/adjacent.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2017, The University of Memphis,
+ * Copyright (c) 2014-2018, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
@@ -140,19 +140,19 @@
operator<(const Adjacent& adjacent) const;
inline bool
- compare(const ndn::Name& adjacencyName)
+ compare(const ndn::Name& adjacencyName) const
{
return m_name == adjacencyName;
}
inline bool
- compareFaceId(const uint64_t faceId)
+ compareFaceId(const uint64_t faceId) const
{
return m_faceId == faceId;
}
inline bool
- compareFaceUri(const ndn::FaceUri& faceUri)
+ compareFaceUri(const ndn::FaceUri& faceUri) const
{
return m_faceUri == faceUri;
}
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 0a29184..d3b8737 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -123,18 +123,36 @@
return m_confParam;
}
+ const ConfParameter&
+ getConfParameter() const
+ {
+ return m_confParam;
+ }
+
AdjacencyList&
getAdjacencyList()
{
return m_adjacencyList;
}
+ const AdjacencyList&
+ getAdjacencyList() const
+ {
+ return m_adjacencyList;
+ }
+
NamePrefixList&
getNamePrefixList()
{
return m_namePrefixList;
}
+ const NamePrefixList&
+ getNamePrefixList() const
+ {
+ return m_namePrefixList;
+ }
+
ndn::Face&
getNlsrFace()
{