akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1 | #include <iostream> |
2 | #include <algorithm> | ||||
3 | |||||
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame^] | 4 | #include <ndn-cxx/common.hpp> |
5 | |||||
6 | #include "name-prefix-list.hpp" | ||||
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 7 | |
8 | namespace nlsr { | ||||
9 | |||||
10 | using namespace std; | ||||
11 | |||||
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame^] | 12 | NamePrefixList::NamePrefixList() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 13 | { |
14 | } | ||||
15 | |||||
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame^] | 16 | NamePrefixList::~NamePrefixList() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 17 | { |
18 | } | ||||
19 | |||||
20 | static bool | ||||
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame^] | 21 | nameCompare(const string& s1, const string& s2) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 22 | { |
23 | return s1 == s2; | ||||
24 | } | ||||
25 | |||||
26 | int | ||||
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame^] | 27 | NamePrefixList::insert(string& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 28 | { |
29 | std::list<string>::iterator it = std::find_if(m_nameList.begin(), | ||||
30 | m_nameList.end(), | ||||
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame^] | 31 | ndn::bind(&nameCompare, _1 , name)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 32 | if (it != m_nameList.end()) |
33 | { | ||||
34 | return -1; | ||||
35 | } | ||||
36 | m_nameList.push_back(name); | ||||
37 | return 0; | ||||
38 | } | ||||
39 | |||||
40 | int | ||||
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame^] | 41 | NamePrefixList::remove(string& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 42 | { |
43 | std::list<string>::iterator it = std::find_if(m_nameList.begin(), | ||||
44 | m_nameList.end(), | ||||
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame^] | 45 | ndn::bind(&nameCompare, _1 , name)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 46 | if (it != m_nameList.end()) |
47 | { | ||||
48 | m_nameList.erase(it); | ||||
49 | } | ||||
50 | return -1; | ||||
51 | } | ||||
52 | |||||
53 | void | ||||
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame^] | 54 | NamePrefixList::sort() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 55 | { |
56 | m_nameList.sort(); | ||||
57 | } | ||||
58 | |||||
59 | void | ||||
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame^] | 60 | NamePrefixList::print() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 61 | { |
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 |