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