NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  shared_ptr<T>
44  getStrategyInfo() const;
45 
49  template<typename T>
50  void
51  setStrategyInfo(shared_ptr<T> strategyInfo);
52 
59  template<typename T, typename ...A>
60  shared_ptr<T>
61  getOrCreateStrategyInfo(A&&... args);
62 
65  void
67 
68 private:
69  std::map<int, shared_ptr<fw::StrategyInfo>> m_items;
70 };
71 
72 
73 template<typename T>
74 shared_ptr<T>
76 {
77  static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
78  "T must inherit from StrategyInfo");
79 
80  auto it = m_items.find(T::getTypeId());
81  if (it == m_items.end()) {
82  return nullptr;
83  }
84  return static_pointer_cast<T, fw::StrategyInfo>(it->second);
85 }
86 
87 template<typename T>
88 void
90 {
91  static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
92  "T must inherit from StrategyInfo");
93 
94  if (item == nullptr) {
95  m_items.erase(T::getTypeId());
96  }
97  else {
98  m_items[T::getTypeId()] = item;
99  }
100 }
101 
102 template<typename T, typename ...A>
103 shared_ptr<T>
105 {
106  static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
107  "T must inherit from StrategyInfo");
108 
109  shared_ptr<T> item = this->getStrategyInfo<T>();
110  if (!static_cast<bool>(item)) {
111  item = make_shared<T>(std::forward<A>(args)...);
112  this->setStrategyInfo(item);
113  }
114  return item;
115 }
116 
117 } // namespace nfd
118 
119 #endif // NFD_DAEMON_TABLE_STRATEGY_INFO_HOST_HPP
base class for an entity onto which StrategyInfo objects may be placed
void setStrategyInfo(shared_ptr< T > strategyInfo)
set a StrategyInfo item
shared_ptr< T > getOrCreateStrategyInfo(A &&...args)
get or create a StrategyInfo item
void clearStrategyInfo()
clear all StrategyInfo items
contains arbitrary information forwarding strategy places on table entries
shared_ptr< T > getStrategyInfo() const
get a StrategyInfo item