blob: c6d1bd7f13206ba7c7ada5a2dc67d726256695d3 [file] [log] [blame]
akmhoque53353462014-04-22 08:43:45 -05001#include <iostream>
2#include <algorithm>
3
akmhoquec8a10f72014-04-25 18:42:55 -05004#include <ndn-cxx/common.hpp>
5
6#include "name-prefix-list.hpp"
akmhoque674b0b12014-05-20 14:33:28 -05007#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -05008
9namespace nlsr {
10
akmhoque674b0b12014-05-20 14:33:28 -050011INIT_LOGGER("NamePrefixList");
12
akmhoque53353462014-04-22 08:43:45 -050013using namespace std;
14
akmhoquec8a10f72014-04-25 18:42:55 -050015NamePrefixList::NamePrefixList()
akmhoque53353462014-04-22 08:43:45 -050016{
17}
18
akmhoquec8a10f72014-04-25 18:42:55 -050019NamePrefixList::~NamePrefixList()
akmhoque53353462014-04-22 08:43:45 -050020{
21}
22
23static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050024nameCompare(const ndn::Name& name1, const ndn::Name& name2)
akmhoque53353462014-04-22 08:43:45 -050025{
akmhoque31d1d4b2014-05-05 22:08:14 -050026 return name1 == name2;
akmhoque53353462014-04-22 08:43:45 -050027}
28
akmhoquefdbddb12014-05-02 18:35:19 -050029int32_t
akmhoque31d1d4b2014-05-05 22:08:14 -050030NamePrefixList::insert(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050031{
akmhoque31d1d4b2014-05-05 22:08:14 -050032 std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
33 m_nameList.end(),
34 ndn::bind(&nameCompare, _1 ,
35 ndn::cref(name)));
akmhoque157b0a42014-05-13 00:26:37 -050036 if (it != m_nameList.end()) {
akmhoque53353462014-04-22 08:43:45 -050037 return -1;
38 }
39 m_nameList.push_back(name);
40 return 0;
41}
42
akmhoquefdbddb12014-05-02 18:35:19 -050043int32_t
akmhoque31d1d4b2014-05-05 22:08:14 -050044NamePrefixList::remove(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050045{
akmhoque31d1d4b2014-05-05 22:08:14 -050046 std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
47 m_nameList.end(),
48 ndn::bind(&nameCompare, _1 ,
49 ndn::cref(name)));
akmhoque157b0a42014-05-13 00:26:37 -050050 if (it != m_nameList.end()) {
akmhoque53353462014-04-22 08:43:45 -050051 m_nameList.erase(it);
52 }
53 return -1;
54}
55
56void
akmhoquec8a10f72014-04-25 18:42:55 -050057NamePrefixList::sort()
akmhoque53353462014-04-22 08:43:45 -050058{
59 m_nameList.sort();
60}
61
62void
akmhoque674b0b12014-05-20 14:33:28 -050063NamePrefixList::writeLog()
64{
65 _LOG_DEBUG("-------Name Prefix List--------");
66 int i = 1;
67 for (std::list<ndn::Name>::iterator it = m_nameList.begin();
68 it != m_nameList.end(); it++) {
69 _LOG_DEBUG("Name " << i << " : " << (*it));
70 i++;
71 }
72}
73
74void
akmhoquec8a10f72014-04-25 18:42:55 -050075NamePrefixList::print()
akmhoque53353462014-04-22 08:43:45 -050076{
77 int i = 1;
akmhoque31d1d4b2014-05-05 22:08:14 -050078 for (std::list<ndn::Name>::iterator it = m_nameList.begin();
akmhoque157b0a42014-05-13 00:26:37 -050079 it != m_nameList.end(); it++) {
akmhoque53353462014-04-22 08:43:45 -050080 cout << "Name " << i << " : " << (*it) << endl;
81 i++;
82 }
83}
84
85}//namespace nlsr