32 for (
const auto& name : names) {
40 auto& soucePrefixInfo = m_namesSources[name];
42 return soucePrefixInfo.sources.insert(source).second;
48 auto& soucePrefixInfo = m_namesSources[nameCost.
getName()];
49 soucePrefixInfo.costObj = nameCost;
50 return soucePrefixInfo.sources.insert(
"").second;
56 auto it = m_namesSources.find(name);
57 if (it == m_namesSources.end()) {
61 bool isRemoved = it->second.sources.erase(source);
62 if (it->second.sources.empty()) {
63 m_namesSources.erase(it);
71 auto it = m_namesSources.find(name);
72 BOOST_ASSERT(it != m_namesSources.end());
73 return it->second.costObj;
79 std::list<ndn::Name> names;
80 for (
const auto& [name, sources] : m_namesSources) {
81 names.emplace_back(name);
89 std::list<PrefixInfo> nameCosts;
90 for (
const auto& [name, soucePrefixInfo] : m_namesSources) {
91 nameCosts.emplace_back(name, soucePrefixInfo.costObj.getCost());
99NamePrefixList::getSources(
const ndn::Name& name)
const
101 if (
auto it = m_namesSources.find(name); it != m_namesSources.end()) {
102 return it->second.sources;
112 os <<
"Name prefix list: {\n";
113 for (
const auto& [name, sources] : list.m_namesSources) {
114 os << name <<
"\nSources:\n";
115 for (
const auto& source : sources.sources) {
116 os <<
" " << source <<
"\n";
119 os <<
"}" << std::endl;
123template<ndn::encoding::Tag TAG>
127 size_t totalLength = 0;
129 totalLength += prependDoubleBlock(encoder,
nlsr::tlv::Cost, m_prefixCost);
131 totalLength += m_prefixName.wireEncode(encoder);
133 totalLength += encoder.prependVarNumber(totalLength);
144 if (m_wire.hasWire()) {
148 ndn::EncodingEstimator estimator;
151 ndn::EncodingBuffer buffer(estimatedSize, 0);
154 m_wire = buffer.block();
165 NDN_THROW(
Error(
"PrefixInfo", m_wire.type()));
170 auto val = m_wire.elements_begin();
172 if (val != m_wire.elements_end() && val->type() == ndn::tlv::Name) {
173 m_prefixName.wireDecode(*val);
177 NDN_THROW(
Error(
"Missing required Name field"));
181 m_prefixCost = ndn::encoding::readDouble(*val);
185 NDN_THROW(
Error(
"Missing required Cost field"));
std::list< PrefixInfo > getPrefixInfo() const
bool erase(const ndn::Name &name, const std::string &source="")
Deletes name and source combination.
const PrefixInfo & getPrefixInfoForName(const ndn::Name &name) const
std::list< ndn::Name > getNames() const
bool insert(const ndn::Name &name, const std::string &source="", double cost=0)
Inserts name and source combination.
const ndn::Block & wireEncode() const
const ndn::Name & getName() const
void wireDecode(const ndn::Block &wire)
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Adjacent)