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