npl: npls more conveniently instantiable
NPLs can now be instantiated using brace-init lists, as well as by passing
any iterator-capable container.
refs: #4345
Change-Id: Ib43373d5899d0ac14861027c34431fa928eec191
diff --git a/src/name-prefix-list.cpp b/src/name-prefix-list.cpp
index 7df0eef..486e350 100644
--- a/src/name-prefix-list.cpp
+++ b/src/name-prefix-list.cpp
@@ -34,6 +34,21 @@
{
}
+NamePrefixList::NamePrefixList(const std::initializer_list<ndn::Name>& names)
+{
+ std::vector<NamePrefixList::NamePair> namePairs;
+ std::transform(names.begin(), names.end(), std::back_inserter(namePairs),
+ [] (const ndn::Name& name) {
+ return NamePrefixList::NamePair{name, {""}};
+ });
+ m_names = std::move(namePairs);
+}
+
+NamePrefixList::NamePrefixList(const std::initializer_list<NamePrefixList::NamePair>& namesAndSources)
+ : m_names(namesAndSources)
+{
+}
+
NamePrefixList::~NamePrefixList()
{
}
diff --git a/src/name-prefix-list.hpp b/src/name-prefix-list.hpp
index 8351b3b..0912fb3 100644
--- a/src/name-prefix-list.hpp
+++ b/src/name-prefix-list.hpp
@@ -40,6 +40,18 @@
NamePrefixList();
+ NamePrefixList(const std::initializer_list<ndn::Name>& names);
+
+ NamePrefixList(const std::initializer_list<NamePrefixList::NamePair>& namesAndSources);
+
+ template<class ContainerType>
+ NamePrefixList(const ContainerType& names)
+ {
+ for (const auto& elem : names) {
+ m_names.push_back(NamePair{elem, {""}});
+ }
+ }
+
~NamePrefixList();
/*! \brief inserts name into NamePrefixList