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 | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 21 | nameCompare(const ndn::Name& name1, const ndn::Name& name2) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 22 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 23 | return name1 == name2; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 24 | } |
25 | |||||
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 26 | int32_t |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 27 | NamePrefixList::insert(const ndn::Name& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 28 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 29 | 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))); | ||||
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 33 | if (it != m_nameList.end()) |
34 | { | ||||
35 | return -1; | ||||
36 | } | ||||
37 | m_nameList.push_back(name); | ||||
38 | return 0; | ||||
39 | } | ||||
40 | |||||
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 41 | int32_t |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 42 | NamePrefixList::remove(const ndn::Name& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 43 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 44 | 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))); | ||||
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 48 | if (it != m_nameList.end()) |
49 | { | ||||
50 | m_nameList.erase(it); | ||||
51 | } | ||||
52 | return -1; | ||||
53 | } | ||||
54 | |||||
55 | void | ||||
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 56 | NamePrefixList::sort() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 57 | { |
58 | m_nameList.sort(); | ||||
59 | } | ||||
60 | |||||
61 | void | ||||
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 62 | NamePrefixList::print() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 63 | { |
64 | int i = 1; | ||||
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 65 | for (std::list<ndn::Name>::iterator it = m_nameList.begin(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 66 | it != m_nameList.end(); |
67 | it++) | ||||
68 | { | ||||
69 | cout << "Name " << i << " : " << (*it) << endl; | ||||
70 | i++; | ||||
71 | } | ||||
72 | } | ||||
73 | |||||
74 | }//namespace nlsr |