akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 1 | #include<iostream> |
| 2 | #include<algorithm> |
| 3 | |
| 4 | #include "nlsr_npl.hpp" |
| 5 | |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame^] | 6 | namespace nlsr { |
| 7 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 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 | return s1==s2; |
| 21 | } |
| 22 | |
| 23 | int |
| 24 | Npl::insertIntoNpl(string& name){ |
| 25 | std::list<string >::iterator it = std::find_if( nameList.begin(), |
| 26 | nameList.end(), |
| 27 | bind(&nameCompare, _1 , name)); |
| 28 | |
| 29 | if( it != nameList.end() ){ |
| 30 | return -1; |
| 31 | } |
| 32 | |
| 33 | nameList.push_back(name); |
| 34 | return 0; |
| 35 | |
| 36 | } |
| 37 | |
| 38 | int |
| 39 | Npl::removeFromNpl(string& name) |
| 40 | { |
| 41 | std::list<string >::iterator it = std::find_if( nameList.begin(), |
| 42 | nameList.end(), |
| 43 | bind(&nameCompare, _1 , name)); |
| 44 | |
| 45 | if( it != nameList.end() ){ |
| 46 | nameList.erase(it); |
| 47 | } |
| 48 | |
| 49 | return -1; |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | Npl::sortNpl() |
| 54 | { |
| 55 | nameList.sort(); |
| 56 | } |
| 57 | |
| 58 | void |
| 59 | Npl::printNpl(){ |
| 60 | int i=1; |
| 61 | for( std::list<string>::iterator it=nameList.begin(); it != nameList.end(); it++){ |
| 62 | cout<<"Name "<<i<<" : "<<(*it)<<endl; |
| 63 | i++; |
| 64 | } |
| 65 | } |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame^] | 66 | |
| 67 | }//namespace nlsr |