blob: 763fc0dbb9b1f4e4c003653652b5bb645f3203cb [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
akmhoquec8a10f72014-04-25 18:42:55 -050021nameCompare(const string& s1, const string& s2)
akmhoque53353462014-04-22 08:43:45 -050022{
23 return s1 == s2;
24}
25
26int
akmhoquec8a10f72014-04-25 18:42:55 -050027NamePrefixList::insert(string& name)
akmhoque53353462014-04-22 08:43:45 -050028{
29 std::list<string>::iterator it = std::find_if(m_nameList.begin(),
30 m_nameList.end(),
akmhoquec8a10f72014-04-25 18:42:55 -050031 ndn::bind(&nameCompare, _1 , name));
akmhoque53353462014-04-22 08:43:45 -050032 if (it != m_nameList.end())
33 {
34 return -1;
35 }
36 m_nameList.push_back(name);
37 return 0;
38}
39
40int
akmhoquec8a10f72014-04-25 18:42:55 -050041NamePrefixList::remove(string& name)
akmhoque53353462014-04-22 08:43:45 -050042{
43 std::list<string>::iterator it = std::find_if(m_nameList.begin(),
44 m_nameList.end(),
akmhoquec8a10f72014-04-25 18:42:55 -050045 ndn::bind(&nameCompare, _1 , name));
akmhoque53353462014-04-22 08:43:45 -050046 if (it != m_nameList.end())
47 {
48 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;
63 for (std::list<string>::iterator it = m_nameList.begin();
64 it != m_nameList.end();
65 it++)
66 {
67 cout << "Name " << i << " : " << (*it) << endl;
68 i++;
69 }
70}
71
72}//namespace nlsr