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