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 | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 33 | if (it != m_nameList.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | return -1; |
35 | } | ||||
36 | m_nameList.push_back(name); | ||||
37 | return 0; | ||||
38 | } | ||||
39 | |||||
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 40 | int32_t |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 41 | NamePrefixList::remove(const ndn::Name& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 42 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 43 | 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))); | ||||
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 47 | if (it != m_nameList.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 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; | ||||
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 63 | for (std::list<ndn::Name>::iterator it = m_nameList.begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 64 | it != m_nameList.end(); it++) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 65 | cout << "Name " << i << " : " << (*it) << endl; |
66 | i++; | ||||
67 | } | ||||
68 | } | ||||
69 | |||||
70 | }//namespace nlsr |