blob: e8356cbcdd3fc7d1540ac548cf73d557c441fd76 [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#include<iostream>
2#include<algorithm>
3
4#include "nlsr_npl.hpp"
5
akmhoque1fd8c1e2014-02-19 19:41:49 -06006namespace nlsr
akmhoque298385a2014-02-13 14:13:09 -06007{
akmhoque298385a2014-02-13 14:13:09 -06008
akmhoque1fd8c1e2014-02-19 19:41:49 -06009 using namespace std;
akmhoque298385a2014-02-13 14:13:09 -060010
akmhoque1fd8c1e2014-02-19 19:41:49 -060011 Npl::Npl()
12 {
akmhoque1fd8c1e2014-02-19 19:41:49 -060013 }
akmhoque298385a2014-02-13 14:13:09 -060014
akmhoque1fd8c1e2014-02-19 19:41:49 -060015 Npl::~Npl()
16 {
akmhoque1fd8c1e2014-02-19 19:41:49 -060017 }
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));
akmhoque1fd8c1e2014-02-19 19:41:49 -060031 if( it != nameList.end() )
32 {
33 return -1;
34 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060035 nameList.push_back(name);
36 return 0;
akmhoque1fd8c1e2014-02-19 19:41:49 -060037 }
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));
akmhoque1fd8c1e2014-02-19 19:41:49 -060045 if( it != nameList.end() )
46 {
47 nameList.erase(it);
48 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060049 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 }
akmhoqueb1710aa2014-02-19 17:13:36 -060069
70}//namespace nlsr