NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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
35
class
StrategyInfoHost
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
66
clearStrategyInfo
();
67
68
private
:
69
std::map<int, shared_ptr<fw::StrategyInfo>> m_items;
70
};
71
72
73
template
<
typename
T>
74
shared_ptr<T>
75
StrategyInfoHost::getStrategyInfo
()
const
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
89
StrategyInfoHost::setStrategyInfo
(shared_ptr<T> item)
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>
104
StrategyInfoHost::getOrCreateStrategyInfo
(A&&... args)
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
nfd::StrategyInfoHost
base class for an entity onto which StrategyInfo objects may be placed
Definition:
strategy-info-host.hpp:35
strategy-info.hpp
nfd::StrategyInfoHost::setStrategyInfo
void setStrategyInfo(shared_ptr< T > strategyInfo)
set a StrategyInfo item
Definition:
strategy-info-host.hpp:89
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-common.hpp:40
nfd::StrategyInfoHost::getOrCreateStrategyInfo
shared_ptr< T > getOrCreateStrategyInfo(A &&... args)
get or create a StrategyInfo item
Definition:
strategy-info-host.hpp:104
nfd::StrategyInfoHost::clearStrategyInfo
void clearStrategyInfo()
clear all StrategyInfo items
Definition:
strategy-info-host.cpp:31
nfd::StrategyInfoHost::getStrategyInfo
shared_ptr< T > getStrategyInfo() const
get a StrategyInfo item
Definition:
strategy-info-host.hpp:75
nfd::fw::StrategyInfo
contains arbitrary information forwarding strategy places on table entries
Definition:
strategy-info.hpp:36
ndnSIM
NFD
daemon
table
strategy-info-host.hpp
Generated on Sat Nov 12 2016 16:02:54 for ndnSIM by
1.8.12