blob: f00d0d09c53611129ecb1c1bd748bed67c143069 [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"
akmhoque53353462014-04-22 08:43:45 -05007
8namespace nlsr {
9
10using namespace std;
11
akmhoquec8a10f72014-04-25 18:42:55 -050012NamePrefixList::NamePrefixList()
akmhoque53353462014-04-22 08:43:45 -050013{
14}
15
akmhoquec8a10f72014-04-25 18:42:55 -050016NamePrefixList::~NamePrefixList()
akmhoque53353462014-04-22 08:43:45 -050017{
18}
19
20static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050021nameCompare(const ndn::Name& name1, const ndn::Name& name2)
akmhoque53353462014-04-22 08:43:45 -050022{
akmhoque31d1d4b2014-05-05 22:08:14 -050023 return name1 == name2;
akmhoque53353462014-04-22 08:43:45 -050024}
25
akmhoquefdbddb12014-05-02 18:35:19 -050026int32_t
akmhoque31d1d4b2014-05-05 22:08:14 -050027NamePrefixList::insert(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050028{
akmhoque31d1d4b2014-05-05 22:08:14 -050029 std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
30 m_nameList.end(),
31 ndn::bind(&nameCompare, _1 ,
32 ndn::cref(name)));
akmhoque157b0a42014-05-13 00:26:37 -050033 if (it != m_nameList.end()) {
akmhoque53353462014-04-22 08:43:45 -050034 return -1;
35 }
36 m_nameList.push_back(name);
37 return 0;
38}
39
akmhoquefdbddb12014-05-02 18:35:19 -050040int32_t
akmhoque31d1d4b2014-05-05 22:08:14 -050041NamePrefixList::remove(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050042{
akmhoque31d1d4b2014-05-05 22:08:14 -050043 std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
44 m_nameList.end(),
45 ndn::bind(&nameCompare, _1 ,
46 ndn::cref(name)));
akmhoque157b0a42014-05-13 00:26:37 -050047 if (it != m_nameList.end()) {
akmhoque53353462014-04-22 08:43:45 -050048 m_nameList.erase(it);
49 }
50 return -1;
51}
52
53void
akmhoquec8a10f72014-04-25 18:42:55 -050054NamePrefixList::sort()
akmhoque53353462014-04-22 08:43:45 -050055{
56 m_nameList.sort();
57}
58
59void
akmhoquec8a10f72014-04-25 18:42:55 -050060NamePrefixList::print()
akmhoque53353462014-04-22 08:43:45 -050061{
62 int i = 1;
akmhoque31d1d4b2014-05-05 22:08:14 -050063 for (std::list<ndn::Name>::iterator it = m_nameList.begin();
akmhoque157b0a42014-05-13 00:26:37 -050064 it != m_nameList.end(); it++) {
akmhoque53353462014-04-22 08:43:45 -050065 cout << "Name " << i << " : " << (*it) << endl;
66 i++;
67 }
68}
69
70}//namespace nlsr