NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
strategy-info-host.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_TABLE_STRATEGY_INFO_HOST_HPP
27 #define NFD_DAEMON_TABLE_STRATEGY_INFO_HOST_HPP
28 
29 #include "fw/strategy-info.hpp"
30 
31 namespace nfd {
32 
36 {
37 public:
42  template<typename T>
43  T*
45  {
46  static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
47  "T must inherit from StrategyInfo");
48 
49  auto it = m_items.find(T::getTypeId());
50  if (it == m_items.end()) {
51  return nullptr;
52  }
53  return static_cast<T*>(it->second.get());
54  }
55 
61  template<typename T, typename ...A>
62  std::pair<T*, bool>
63  insertStrategyInfo(A&&... args)
64  {
65  static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
66  "T must inherit from StrategyInfo");
67 
68  unique_ptr<fw::StrategyInfo>& item = m_items[T::getTypeId()];
69  bool isNew = (item == nullptr);
70  if (isNew) {
71  item.reset(new T(std::forward<A>(args)...));
72  }
73  return {static_cast<T*>(item.get()), isNew};
74  }
75 
80  template<typename T>
81  size_t
83  {
84  static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
85  "T must inherit from StrategyInfo");
86 
87  return m_items.erase(T::getTypeId());
88  }
89 
92  void
94 
95 private:
96  std::unordered_map<int, unique_ptr<fw::StrategyInfo>> m_items;
97 };
98 
99 } // namespace nfd
100 
101 #endif // NFD_DAEMON_TABLE_STRATEGY_INFO_HOST_HPP
size_t eraseStrategyInfo()
erase a StrategyInfo item
base class for an entity onto which StrategyInfo items may be placed
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void clearStrategyInfo()
clear all StrategyInfo items
std::pair< T *, bool > insertStrategyInfo(A &&... args)
insert a StrategyInfo item
T * getStrategyInfo() const
get a StrategyInfo item