blob: c8d9285b5d4fa970036921c1ce86870168308216 [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)));
akmhoque53353462014-04-22 08:43:45 -050033 if (it != m_nameList.end())
34 {
35 return -1;
36 }
37 m_nameList.push_back(name);
38 return 0;
39}
40
akmhoquefdbddb12014-05-02 18:35:19 -050041int32_t
akmhoque31d1d4b2014-05-05 22:08:14 -050042NamePrefixList::remove(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050043{
akmhoque31d1d4b2014-05-05 22:08:14 -050044 std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
45 m_nameList.end(),
46 ndn::bind(&nameCompare, _1 ,
47 ndn::cref(name)));
akmhoque53353462014-04-22 08:43:45 -050048 if (it != m_nameList.end())
49 {
50 m_nameList.erase(it);
51 }
52 return -1;
53}
54
55void
akmhoquec8a10f72014-04-25 18:42:55 -050056NamePrefixList::sort()
akmhoque53353462014-04-22 08:43:45 -050057{
58 m_nameList.sort();
59}
60
61void
akmhoquec8a10f72014-04-25 18:42:55 -050062NamePrefixList::print()
akmhoque53353462014-04-22 08:43:45 -050063{
64 int i = 1;
akmhoque31d1d4b2014-05-05 22:08:14 -050065 for (std::list<ndn::Name>::iterator it = m_nameList.begin();
akmhoque53353462014-04-22 08:43:45 -050066 it != m_nameList.end();
67 it++)
68 {
69 cout << "Name " << i << " : " << (*it) << endl;
70 i++;
71 }
72}
73
74}//namespace nlsr