akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 1 | #include<iostream> |
| 2 | #include<algorithm> |
| 3 | |
akmhoque | 204e754 | 2014-01-31 16:08:25 -0600 | [diff] [blame] | 4 | #include "nlsr_npl.hpp" |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 5 | |
| 6 | using namespace std; |
| 7 | |
| 8 | Npl::Npl(){ |
| 9 | |
| 10 | } |
| 11 | |
| 12 | Npl::~Npl(){ |
| 13 | |
| 14 | } |
| 15 | |
| 16 | static bool |
| 17 | nameCompare(string& s1, string& s2){ |
| 18 | return s1==s2; |
| 19 | } |
| 20 | |
| 21 | int |
| 22 | Npl::insertIntoNpl(string& name){ |
| 23 | std::list<string >::iterator it = std::find_if( nameList.begin(), |
| 24 | nameList.end(), |
| 25 | bind(&nameCompare, _1 , name)); |
| 26 | |
| 27 | if( it != nameList.end() ){ |
| 28 | return -1; |
| 29 | } |
| 30 | |
| 31 | nameList.push_back(name); |
| 32 | return 0; |
| 33 | |
| 34 | } |
| 35 | |
akmhoque | 62a8e40 | 2014-02-08 12:00:27 -0600 | [diff] [blame] | 36 | int |
| 37 | Npl::removeFromNpl(string& name) |
| 38 | { |
| 39 | std::list<string >::iterator it = std::find_if( nameList.begin(), |
| 40 | nameList.end(), |
| 41 | bind(&nameCompare, _1 , name)); |
| 42 | |
| 43 | if( it != nameList.end() ){ |
| 44 | nameList.erase(it); |
| 45 | } |
| 46 | |
| 47 | return -1; |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | Npl::sortNpl() |
| 52 | { |
| 53 | nameList.sort(); |
| 54 | } |
| 55 | |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 56 | void |
| 57 | Npl::printNpl(){ |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 58 | int i=1; |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 59 | for( std::list<string>::iterator it=nameList.begin(); it != nameList.end(); it++){ |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 60 | cout<<"Name "<<i<<" : "<<(*it)<<endl; |
| 61 | i++; |
akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 62 | } |
| 63 | } |