blob: e6cd819d6fa945db310d307e3b809df453064505 [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#include<iostream>
2#include<algorithm>
3
4#include "nlsr_npl.hpp"
akmhoque05d5fcf2014-04-15 14:58:45 -05005#include "utility/nlsr_logger.hpp"
6
7#define THIS_FILE "nlsr_npl.cpp"
akmhoque298385a2014-02-13 14:13:09 -06008
akmhoque1fd8c1e2014-02-19 19:41:49 -06009namespace nlsr
akmhoque298385a2014-02-13 14:13:09 -060010{
akmhoque298385a2014-02-13 14:13:09 -060011
akmhoque5a44dd42014-03-12 18:11:32 -050012 using namespace std;
akmhoque298385a2014-02-13 14:13:09 -060013
akmhoque5a44dd42014-03-12 18:11:32 -050014 Npl::Npl()
15 {
16 }
akmhoque298385a2014-02-13 14:13:09 -060017
akmhoque5a44dd42014-03-12 18:11:32 -050018 Npl::~Npl()
19 {
20 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060021
akmhoque5a44dd42014-03-12 18:11:32 -050022 static bool
23 nameCompare(string& s1, string& s2)
24 {
25 return s1==s2;
26 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060027
akmhoque5a44dd42014-03-12 18:11:32 -050028 int
akmhoque05d5fcf2014-04-15 14:58:45 -050029 Npl::insert(string& name)
akmhoque5a44dd42014-03-12 18:11:32 -050030 {
akmhoque05d5fcf2014-04-15 14:58:45 -050031 std::list<string >::iterator it = std::find_if( m_nameList.begin(),
32 m_nameList.end(),
akmhoque5a44dd42014-03-12 18:11:32 -050033 bind(&nameCompare, _1 , name));
akmhoque05d5fcf2014-04-15 14:58:45 -050034 if( it != m_nameList.end() )
akmhoque1fd8c1e2014-02-19 19:41:49 -060035 {
akmhoque5a44dd42014-03-12 18:11:32 -050036 return -1;
akmhoque1fd8c1e2014-02-19 19:41:49 -060037 }
akmhoque05d5fcf2014-04-15 14:58:45 -050038 m_nameList.push_back(name);
akmhoque5a44dd42014-03-12 18:11:32 -050039 return 0;
40 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060041
akmhoque5a44dd42014-03-12 18:11:32 -050042 int
akmhoque05d5fcf2014-04-15 14:58:45 -050043 Npl::remove(string& name)
akmhoque5a44dd42014-03-12 18:11:32 -050044 {
akmhoque05d5fcf2014-04-15 14:58:45 -050045 std::list<string >::iterator it = std::find_if( m_nameList.begin(),
46 m_nameList.end(),
akmhoque5a44dd42014-03-12 18:11:32 -050047 bind(&nameCompare, _1 , name));
akmhoque05d5fcf2014-04-15 14:58:45 -050048 if( it != m_nameList.end() )
akmhoque1fd8c1e2014-02-19 19:41:49 -060049 {
akmhoque05d5fcf2014-04-15 14:58:45 -050050 m_nameList.erase(it);
akmhoque1fd8c1e2014-02-19 19:41:49 -060051 }
akmhoque5a44dd42014-03-12 18:11:32 -050052 return -1;
53 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060054
akmhoque5a44dd42014-03-12 18:11:32 -050055 void
akmhoque05d5fcf2014-04-15 14:58:45 -050056 Npl::sort()
akmhoque5a44dd42014-03-12 18:11:32 -050057 {
akmhoque05d5fcf2014-04-15 14:58:45 -050058 m_nameList.sort();
akmhoque5a44dd42014-03-12 18:11:32 -050059 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060060
akmhoque5a44dd42014-03-12 18:11:32 -050061 void
akmhoque05d5fcf2014-04-15 14:58:45 -050062 Npl::print()
akmhoque5a44dd42014-03-12 18:11:32 -050063 {
64 int i=1;
akmhoque05d5fcf2014-04-15 14:58:45 -050065 for( std::list<string>::iterator it=m_nameList.begin(); it != m_nameList.end();
akmhoque5a44dd42014-03-12 18:11:32 -050066 it++)
akmhoque1fd8c1e2014-02-19 19:41:49 -060067 {
akmhoque5a44dd42014-03-12 18:11:32 -050068 cout<<"Name "<<i<<" : "<<(*it)<<endl;
69 i++;
akmhoque1fd8c1e2014-02-19 19:41:49 -060070 }
akmhoque5a44dd42014-03-12 18:11:32 -050071 }
akmhoqueb1710aa2014-02-19 17:13:36 -060072
73}//namespace nlsr