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