blob: d8b20879d99bca8b5044f5fa1d8c338d60e880c2 [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
akmhoque5a44dd42014-03-12 18:11:32 -05009 using namespace std;
akmhoque298385a2014-02-13 14:13:09 -060010
akmhoque5a44dd42014-03-12 18:11:32 -050011 Npl::Npl()
12 {
13 }
akmhoque298385a2014-02-13 14:13:09 -060014
akmhoque5a44dd42014-03-12 18:11:32 -050015 Npl::~Npl()
16 {
17 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060018
akmhoque5a44dd42014-03-12 18:11:32 -050019 static bool
20 nameCompare(string& s1, string& s2)
21 {
22 return s1==s2;
23 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060024
akmhoque5a44dd42014-03-12 18:11:32 -050025 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() )
akmhoque1fd8c1e2014-02-19 19:41:49 -060032 {
akmhoque5a44dd42014-03-12 18:11:32 -050033 return -1;
akmhoque1fd8c1e2014-02-19 19:41:49 -060034 }
akmhoque5a44dd42014-03-12 18:11:32 -050035 nameList.push_back(name);
36 return 0;
37 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060038
akmhoque5a44dd42014-03-12 18:11:32 -050039 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() )
akmhoque1fd8c1e2014-02-19 19:41:49 -060046 {
akmhoque5a44dd42014-03-12 18:11:32 -050047 nameList.erase(it);
akmhoque1fd8c1e2014-02-19 19:41:49 -060048 }
akmhoque5a44dd42014-03-12 18:11:32 -050049 return -1;
50 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060051
akmhoque5a44dd42014-03-12 18:11:32 -050052 void
53 Npl::sortNpl()
54 {
55 nameList.sort();
56 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060057
akmhoque5a44dd42014-03-12 18:11:32 -050058 void
59 Npl::printNpl()
60 {
61 int i=1;
62 for( std::list<string>::iterator it=nameList.begin(); it != nameList.end();
63 it++)
akmhoque1fd8c1e2014-02-19 19:41:49 -060064 {
akmhoque5a44dd42014-03-12 18:11:32 -050065 cout<<"Name "<<i<<" : "<<(*it)<<endl;
66 i++;
akmhoque1fd8c1e2014-02-19 19:41:49 -060067 }
akmhoque5a44dd42014-03-12 18:11:32 -050068 }
akmhoqueb1710aa2014-02-19 17:13:36 -060069
70}//namespace nlsr