table: don't use shared_ptr in Measurements

refs #3164

Change-Id: I7705d00ac155b15b5db69809610b68e96360a0ae
diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp
index 69c1a39..bb41fba 100644
--- a/daemon/fw/access-strategy.cpp
+++ b/daemon/fw/access-strategy.cpp
@@ -235,7 +235,7 @@
 std::tuple<Name, shared_ptr<AccessStrategy::MtInfo>>
 AccessStrategy::findPrefixMeasurements(const pit::Entry& pitEntry)
 {
-  shared_ptr<measurements::Entry> me = this->getMeasurements().findLongestPrefixMatch(pitEntry);
+  measurements::Entry* me = this->getMeasurements().findLongestPrefixMatch(pitEntry);
   if (me == nullptr) {
     return std::forward_as_tuple(Name(), nullptr);
   }
@@ -250,8 +250,8 @@
 shared_ptr<AccessStrategy::MtInfo>
 AccessStrategy::addPrefixMeasurements(const Data& data)
 {
-  shared_ptr<measurements::Entry> me;
-  if (data.getName().size() >= 1) {
+  measurements::Entry* me = nullptr;
+  if (!data.getName().empty()) {
     me = this->getMeasurements().get(data.getName().getPrefix(-1));
   }
   if (me == nullptr) { // parent of Data Name is not in this strategy, or Data Name is empty
diff --git a/daemon/fw/asf-measurements.cpp b/daemon/fw/asf-measurements.cpp
index 1a2eca2..11249f8 100644
--- a/daemon/fw/asf-measurements.cpp
+++ b/daemon/fw/asf-measurements.cpp
@@ -219,14 +219,14 @@
 shared_ptr<NamespaceInfo>
 AsfMeasurements::getNamespaceInfo(const ndn::Name& prefix)
 {
-  shared_ptr<measurements::Entry> me = m_measurements.findLongestPrefixMatch(prefix);
+  measurements::Entry* me = m_measurements.findLongestPrefixMatch(prefix);
 
   if (me == nullptr) {
     return nullptr;
   }
 
   // Set or update entry lifetime
-  extendLifetime(me);
+  extendLifetime(*me);
 
   shared_ptr<NamespaceInfo> info = me->getOrCreateStrategyInfo<NamespaceInfo>();
   BOOST_ASSERT(info != nullptr);
@@ -237,7 +237,7 @@
 NamespaceInfo&
 AsfMeasurements::getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const ndn::Interest& interest)
 {
-  shared_ptr<measurements::Entry> me = m_measurements.get(fibEntry);
+  measurements::Entry* me = m_measurements.get(fibEntry);
 
   // If the FIB entry is not under the strategy's namespace, find a part of the prefix
   // that falls under the strategy's namespace
@@ -250,7 +250,7 @@
   BOOST_ASSERT(me != nullptr);
 
   // Set or update entry lifetime
-  extendLifetime(me);
+  extendLifetime(*me);
 
   shared_ptr<NamespaceInfo> info = me->getOrCreateStrategyInfo<NamespaceInfo>();
   BOOST_ASSERT(info != nullptr);
@@ -259,11 +259,9 @@
 }
 
 void
-AsfMeasurements::extendLifetime(shared_ptr<measurements::Entry> me)
+AsfMeasurements::extendLifetime(measurements::Entry& me)
 {
-  if (me != nullptr) {
-    m_measurements.extendLifetime(*me, MEASUREMENTS_LIFETIME);
-  }
+  m_measurements.extendLifetime(me, MEASUREMENTS_LIFETIME);
 }
 
 } // namespace asf
diff --git a/daemon/fw/asf-measurements.hpp b/daemon/fw/asf-measurements.hpp
index 8339d97..64f88c2 100644
--- a/daemon/fw/asf-measurements.hpp
+++ b/daemon/fw/asf-measurements.hpp
@@ -294,8 +294,9 @@
   NamespaceInfo&
   getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const ndn::Interest& interest);
 
+private:
   void
-  extendLifetime(shared_ptr<measurements::Entry> me);
+  extendLifetime(measurements::Entry& me);
 
 public:
   static constexpr time::microseconds MEASUREMENTS_LIFETIME = time::seconds(300);
diff --git a/daemon/fw/ncc-strategy.cpp b/daemon/fw/ncc-strategy.cpp
index fc9cd20..213ce59 100644
--- a/daemon/fw/ncc-strategy.cpp
+++ b/daemon/fw/ncc-strategy.cpp
@@ -66,23 +66,22 @@
     return;
   }
 
-  shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
-    this->getMeasurementsEntryInfo(pitEntry);
+  MeasurementsEntryInfo& meInfo = this->getMeasurementsEntryInfo(pitEntry);
 
   time::microseconds deferFirst = DEFER_FIRST_WITHOUT_BEST_FACE;
   time::microseconds deferRange = DEFER_RANGE_WITHOUT_BEST_FACE;
   size_t nUpstreams = nexthops.size();
 
-  shared_ptr<Face> bestFace = measurementsEntryInfo->getBestFace();
+  shared_ptr<Face> bestFace = meInfo.getBestFace();
   if (bestFace != nullptr && fibEntry.hasNextHop(*bestFace) &&
       canForwardToLegacy(*pitEntry, *bestFace)) {
     // TODO Should we use `randlow = 100 + nrand48(h->seed) % 4096U;` ?
-    deferFirst = measurementsEntryInfo->prediction;
+    deferFirst = meInfo.prediction;
     deferRange = time::microseconds((deferFirst.count() + 1) / 2);
     --nUpstreams;
     this->sendInterest(pitEntry, *bestFace);
     pitEntryInfo->bestFaceTimeout = scheduler::schedule(
-      measurementsEntryInfo->prediction,
+      meInfo.prediction,
       bind(&NccStrategy::timeoutOnBestFace, this, weak_ptr<pit::Entry>(pitEntry)));
   }
   else {
@@ -96,7 +95,7 @@
     }
   }
 
-  shared_ptr<Face> previousFace = measurementsEntryInfo->previousFace.lock();
+  shared_ptr<Face> previousFace = meInfo.previousFace.lock();
   if (previousFace != nullptr && fibEntry.hasNextHop(*previousFace) &&
       canForwardToLegacy(*pitEntry, *previousFace)) {
     --nUpstreams;
@@ -131,10 +130,9 @@
   // from a timer set by NccStrategy.
   BOOST_ASSERT(pitEntryInfo != nullptr);
 
-  shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
-    this->getMeasurementsEntryInfo(pitEntry);
+  MeasurementsEntryInfo& meInfo = this->getMeasurementsEntryInfo(pitEntry);
 
-  shared_ptr<Face> previousFace = measurementsEntryInfo->previousFace.lock();
+  shared_ptr<Face> previousFace = meInfo.previousFace.lock();
   if (previousFace != nullptr && fibEntry.hasNextHop(*previousFace) &&
       canForwardToLegacy(*pitEntry, *previousFace)) {
     this->sendInterest(pitEntry, *previousFace);
@@ -156,8 +154,7 @@
       pitEntryInfo->maxInterval.count() - 1);
     time::nanoseconds deferNext = time::nanoseconds(dist(getGlobalRng()));
     pitEntryInfo->propagateTimer = scheduler::schedule(deferNext,
-    bind(&NccStrategy::doPropagate, this,
-         weak_ptr<pit::Entry>(pitEntry)));
+      bind(&NccStrategy::doPropagate, this, weak_ptr<pit::Entry>(pitEntry)));
   }
 }
 
@@ -165,21 +162,20 @@
 NccStrategy::timeoutOnBestFace(weak_ptr<pit::Entry> pitEntryWeak)
 {
   shared_ptr<pit::Entry> pitEntry = pitEntryWeak.lock();
-  if (!static_cast<bool>(pitEntry)) {
+  if (pitEntry == nullptr) {
     return;
   }
-  shared_ptr<measurements::Entry> measurementsEntry = this->getMeasurements().get(*pitEntry);
+  measurements::Entry* measurementsEntry = this->getMeasurements().get(*pitEntry);
 
   for (int i = 0; i < UPDATE_MEASUREMENTS_N_LEVELS; ++i) {
-    if (!static_cast<bool>(measurementsEntry)) {
+    if (measurementsEntry == nullptr) {
       // going out of this strategy's namespace
-      return;
+      break;
     }
     this->getMeasurements().extendLifetime(*measurementsEntry, MEASUREMENTS_LIFETIME);
 
-    shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
-      this->getMeasurementsEntryInfo(measurementsEntry);
-    measurementsEntryInfo->adjustPredictUp();
+    MeasurementsEntryInfo& meInfo = this->getMeasurementsEntryInfo(measurementsEntry);
+    meInfo.adjustPredictUp();
 
     measurementsEntry = this->getMeasurements().getParent(*measurementsEntry);
   }
@@ -195,18 +191,17 @@
     return;
   }
 
-  shared_ptr<measurements::Entry> measurementsEntry = this->getMeasurements().get(*pitEntry);
+  measurements::Entry* measurementsEntry = this->getMeasurements().get(*pitEntry);
 
   for (int i = 0; i < UPDATE_MEASUREMENTS_N_LEVELS; ++i) {
-    if (!static_cast<bool>(measurementsEntry)) {
+    if (measurementsEntry == nullptr) {
       // going out of this strategy's namespace
       return;
     }
     this->getMeasurements().extendLifetime(*measurementsEntry, MEASUREMENTS_LIFETIME);
 
-    shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
-      this->getMeasurementsEntryInfo(measurementsEntry);
-    measurementsEntryInfo->updateBestFace(inFace);
+    MeasurementsEntryInfo& meInfo = this->getMeasurementsEntryInfo(measurementsEntry);
+    meInfo.updateBestFace(inFace);
 
     measurementsEntry = this->getMeasurements().getParent(*measurementsEntry);
   }
@@ -216,41 +211,40 @@
     scheduler::cancel(pitEntryInfo->propagateTimer);
 
     // Verify that the best face satisfied the interest before canceling the timeout call
-    shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
-      this->getMeasurementsEntryInfo(pitEntry);
-    shared_ptr<Face> bestFace = measurementsEntryInfo->getBestFace();
+    MeasurementsEntryInfo& meInfo = this->getMeasurementsEntryInfo(pitEntry);
+    shared_ptr<Face> bestFace = meInfo.getBestFace();
 
     if (bestFace.get() == &inFace)
       scheduler::cancel(pitEntryInfo->bestFaceTimeout);
   }
 }
 
-shared_ptr<NccStrategy::MeasurementsEntryInfo>
+NccStrategy::MeasurementsEntryInfo&
 NccStrategy::getMeasurementsEntryInfo(shared_ptr<pit::Entry> entry)
 {
-  shared_ptr<measurements::Entry> measurementsEntry = this->getMeasurements().get(*entry);
+  measurements::Entry* measurementsEntry = this->getMeasurements().get(*entry);
   return this->getMeasurementsEntryInfo(measurementsEntry);
 }
 
-shared_ptr<NccStrategy::MeasurementsEntryInfo>
-NccStrategy::getMeasurementsEntryInfo(shared_ptr<measurements::Entry> entry)
+NccStrategy::MeasurementsEntryInfo&
+NccStrategy::getMeasurementsEntryInfo(measurements::Entry* entry)
 {
+  BOOST_ASSERT(entry != nullptr);
   shared_ptr<MeasurementsEntryInfo> info = entry->getStrategyInfo<MeasurementsEntryInfo>();
-  if (static_cast<bool>(info)) {
-    return info;
+  if (info != nullptr) {
+    return *info;
   }
 
   info = make_shared<MeasurementsEntryInfo>();
   entry->setStrategyInfo(info);
 
-  shared_ptr<measurements::Entry> parentEntry = this->getMeasurements().getParent(*entry);
-  if (static_cast<bool>(parentEntry)) {
-    shared_ptr<MeasurementsEntryInfo> parentInfo = this->getMeasurementsEntryInfo(parentEntry);
-    BOOST_ASSERT(static_cast<bool>(parentInfo));
-    info->inheritFrom(*parentInfo);
+  measurements::Entry* parentEntry = this->getMeasurements().getParent(*entry);
+  if (parentEntry != nullptr) {
+    MeasurementsEntryInfo& parentInfo = this->getMeasurementsEntryInfo(parentEntry);
+    info->inheritFrom(parentInfo);
   }
 
-  return info;
+  return *info;
 }
 
 
@@ -275,7 +269,7 @@
 shared_ptr<Face>
 NccStrategy::MeasurementsEntryInfo::getBestFace(void) {
   shared_ptr<Face> best = this->bestFace.lock();
-  if (static_cast<bool>(best)) {
+  if (best != nullptr) {
     return best;
   }
   this->bestFace = best = this->previousFace.lock();
diff --git a/daemon/fw/ncc-strategy.hpp b/daemon/fw/ncc-strategy.hpp
index bfbb06d..80e2918 100644
--- a/daemon/fw/ncc-strategy.hpp
+++ b/daemon/fw/ncc-strategy.hpp
@@ -117,10 +117,10 @@
   };
 
 protected:
-  shared_ptr<MeasurementsEntryInfo>
-  getMeasurementsEntryInfo(shared_ptr<measurements::Entry> entry);
+  MeasurementsEntryInfo&
+  getMeasurementsEntryInfo(measurements::Entry* entry);
 
-  shared_ptr<MeasurementsEntryInfo>
+  MeasurementsEntryInfo&
   getMeasurementsEntryInfo(shared_ptr<pit::Entry> entry);
 
   /// propagate to another upstream