table: rename StrategyInfoHost::getOrCreateStrategyInfo to insertStrategyInfo
refs #3205
Change-Id: Icd3ab9e4fdb5a2ffc39a8d0e0c713e22f13fe28c
diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp
index 9d4df0c..a7eed83 100644
--- a/daemon/fw/access-strategy.cpp
+++ b/daemon/fw/access-strategy.cpp
@@ -136,7 +136,7 @@
this->sendInterest(pitEntry, *face);
// schedule RTO timeout
- shared_ptr<PitInfo> pi = pitEntry->getOrCreateStrategyInfo<PitInfo>();
+ shared_ptr<PitInfo> pi = pitEntry->insertStrategyInfo<PitInfo>();
pi->rtoTimer = scheduler::schedule(rto,
bind(&AccessStrategy::afterRtoTimeout, this, weak_ptr<pit::Entry>(pitEntry),
inFace.getId(), mi.lastNexthop));
@@ -229,14 +229,14 @@
{
measurements::Entry* me = this->getMeasurements().findLongestPrefixMatch(pitEntry);
if (me == nullptr) {
- return std::forward_as_tuple(Name(), nullptr);
+ return std::make_tuple(Name(), nullptr);
}
shared_ptr<MtInfo> mi = me->getStrategyInfo<MtInfo>();
BOOST_ASSERT(mi != nullptr);
// XXX after runtime strategy change, it's possible that me exists but mi doesn't exist;
// this case needs another longest prefix match until mi is found
- return std::forward_as_tuple(me->getName(), mi);
+ return std::make_tuple(me->getName(), mi);
}
shared_ptr<AccessStrategy::MtInfo>
@@ -255,7 +255,7 @@
static const time::nanoseconds ME_LIFETIME = time::seconds(8);
this->getMeasurements().extendLifetime(*me, ME_LIFETIME);
- return me->getOrCreateStrategyInfo<MtInfo>();
+ return me->insertStrategyInfo<MtInfo>();
}
AccessStrategy::FaceInfo::FaceInfo()
diff --git a/daemon/fw/asf-measurements.cpp b/daemon/fw/asf-measurements.cpp
index c15aca0..c7f68c9 100644
--- a/daemon/fw/asf-measurements.cpp
+++ b/daemon/fw/asf-measurements.cpp
@@ -228,7 +228,7 @@
// Set or update entry lifetime
extendLifetime(*me);
- shared_ptr<NamespaceInfo> info = me->getOrCreateStrategyInfo<NamespaceInfo>();
+ shared_ptr<NamespaceInfo> info = me->insertStrategyInfo<NamespaceInfo>();
BOOST_ASSERT(info != nullptr);
return info;
@@ -252,7 +252,7 @@
// Set or update entry lifetime
extendLifetime(*me);
- shared_ptr<NamespaceInfo> info = me->getOrCreateStrategyInfo<NamespaceInfo>();
+ shared_ptr<NamespaceInfo> info = me->insertStrategyInfo<NamespaceInfo>();
BOOST_ASSERT(info != nullptr);
return *info;
diff --git a/daemon/fw/ncc-strategy.cpp b/daemon/fw/ncc-strategy.cpp
index b127fea..c56eef4 100644
--- a/daemon/fw/ncc-strategy.cpp
+++ b/daemon/fw/ncc-strategy.cpp
@@ -54,7 +54,7 @@
return;
}
- shared_ptr<PitEntryInfo> pitEntryInfo = pitEntry->getOrCreateStrategyInfo<PitEntryInfo>();
+ shared_ptr<PitEntryInfo> pitEntryInfo = pitEntry->insertStrategyInfo<PitEntryInfo>();
bool isNewPitEntry = !hasPendingOutRecords(*pitEntry);
if (!isNewPitEntry) {
return;
diff --git a/daemon/fw/retx-suppression-exponential.cpp b/daemon/fw/retx-suppression-exponential.cpp
index 3cca0ab..5edff29 100644
--- a/daemon/fw/retx-suppression-exponential.cpp
+++ b/daemon/fw/retx-suppression-exponential.cpp
@@ -82,7 +82,7 @@
time::steady_clock::TimePoint now = time::steady_clock::now();
time::steady_clock::Duration sinceLastOutgoing = now - lastOutgoing;
- shared_ptr<PitInfo> pi = pitEntry.getOrCreateStrategyInfo<PitInfo>(m_initialInterval);
+ shared_ptr<PitInfo> pi = pitEntry.insertStrategyInfo<PitInfo>(m_initialInterval);
bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
if (shouldSuppress) {
diff --git a/daemon/fw/strategy-info.hpp b/daemon/fw/strategy-info.hpp
index 133d53c..aae3862 100644
--- a/daemon/fw/strategy-info.hpp
+++ b/daemon/fw/strategy-info.hpp
@@ -38,7 +38,7 @@
public:
#ifdef DOXYGEN
/** \return an integer that uniquely identifies this StrategyInfo type
- * \sa http://redmine.named-data.net/projects/nfd/wiki/StrategyInfoType
+ * \sa https://redmine.named-data.net/projects/nfd/wiki/StrategyInfoType
*/
static constexpr int
getTypeId()
@@ -48,15 +48,12 @@
#endif
virtual
- ~StrategyInfo();
+ ~StrategyInfo() = default;
+
+protected:
+ StrategyInfo() = default;
};
-
-inline
-StrategyInfo::~StrategyInfo()
-{
-}
-
} // namespace fw
} // namespace nfd
diff --git a/daemon/table/strategy-info-host.hpp b/daemon/table/strategy-info-host.hpp
index 7afe50d..23b5fcc 100644
--- a/daemon/table/strategy-info-host.hpp
+++ b/daemon/table/strategy-info-host.hpp
@@ -30,35 +30,65 @@
namespace nfd {
-/** \brief base class for an entity onto which StrategyInfo objects may be placed
+/** \brief base class for an entity onto which StrategyInfo items may be placed
*/
class StrategyInfoHost
{
public:
/** \brief get a StrategyInfo item
- * \tparam T type of StrategyInfo, must be a subclass of from nfd::fw::StrategyInfo
- * \retval nullptr if no StrategyInfo of type T is stored
+ * \tparam T type of StrategyInfo, must be a subclass of fw::StrategyInfo
+ * \return an existing StrategyInfo item of type T, or nullptr if it does not exist
*/
template<typename T>
shared_ptr<T>
- getStrategyInfo() const;
+ getStrategyInfo() const
+ {
+ static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
+ "T must inherit from StrategyInfo");
+
+ auto it = m_items.find(T::getTypeId());
+ if (it == m_items.end()) {
+ return nullptr;
+ }
+ return static_pointer_cast<T, fw::StrategyInfo>(it->second);
+ }
/** \brief set a StrategyInfo item
- * \tparam T type of StrategyInfo, must be a subclass of from nfd::fw::StrategyInfo
+ * \tparam T type of StrategyInfo, must be a subclass of nfd::fw::StrategyInfo
*/
template<typename T>
void
- setStrategyInfo(shared_ptr<T> strategyInfo);
+ setStrategyInfo(shared_ptr<T> item)
+ {
+ static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
+ "T must inherit from StrategyInfo");
- /** \brief get or create a StrategyInfo item
- * \tparam T type of StrategyInfo, must be a subclass of from nfd::fw::StrategyInfo
- *
- * If no StrategyInfo of type T is stored, it's created with \p args;
- * otherwise, the existing item is returned.
+ if (item == nullptr) {
+ m_items.erase(T::getTypeId());
+ }
+ else {
+ m_items[T::getTypeId()] = item;
+ }
+ }
+
+ /** \brief insert a StrategyInfo item
+ * \tparam T type of StrategyInfo, must be a subclass of fw::StrategyInfo
+ * \return a new or existing StrategyInfo item of type T
*/
template<typename T, typename ...A>
shared_ptr<T>
- getOrCreateStrategyInfo(A&&... args);
+ insertStrategyInfo(A&&... args)
+ {
+ static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
+ "T must inherit from StrategyInfo");
+
+ shared_ptr<T> item = this->getStrategyInfo<T>();
+ if (!static_cast<bool>(item)) {
+ item = std::make_shared<T>(std::forward<A>(args)...);
+ this->setStrategyInfo(item);
+ }
+ return item;
+ }
/** \brief clear all StrategyInfo items
*/
@@ -69,51 +99,6 @@
std::map<int, shared_ptr<fw::StrategyInfo>> m_items;
};
-
-template<typename T>
-shared_ptr<T>
-StrategyInfoHost::getStrategyInfo() const
-{
- static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
- "T must inherit from StrategyInfo");
-
- auto it = m_items.find(T::getTypeId());
- if (it == m_items.end()) {
- return nullptr;
- }
- return static_pointer_cast<T, fw::StrategyInfo>(it->second);
-}
-
-template<typename T>
-void
-StrategyInfoHost::setStrategyInfo(shared_ptr<T> item)
-{
- static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
- "T must inherit from StrategyInfo");
-
- if (item == nullptr) {
- m_items.erase(T::getTypeId());
- }
- else {
- m_items[T::getTypeId()] = item;
- }
-}
-
-template<typename T, typename ...A>
-shared_ptr<T>
-StrategyInfoHost::getOrCreateStrategyInfo(A&&... args)
-{
- static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
- "T must inherit from StrategyInfo");
-
- shared_ptr<T> item = this->getStrategyInfo<T>();
- if (!static_cast<bool>(item)) {
- item = std::make_shared<T>(std::forward<A>(args)...);
- this->setStrategyInfo(item);
- }
- return item;
-}
-
} // namespace nfd
#endif // NFD_DAEMON_TABLE_STRATEGY_INFO_HOST_HPP