akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 1 | #include<iostream> |
2 | #include<algorithm> | ||||
3 | |||||
4 | #include "nlsr_npl.hpp" | ||||
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 5 | #include "utility/nlsr_logger.hpp" |
6 | |||||
7 | #define THIS_FILE "nlsr_npl.cpp" | ||||
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 8 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 9 | namespace nlsr |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 10 | { |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 11 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 12 | using namespace std; |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 13 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 14 | Npl::Npl() |
15 | { | ||||
16 | } | ||||
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 17 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 18 | Npl::~Npl() |
19 | { | ||||
20 | } | ||||
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 21 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 22 | static bool |
23 | nameCompare(string& s1, string& s2) | ||||
24 | { | ||||
25 | return s1==s2; | ||||
26 | } | ||||
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 27 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 28 | int |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 29 | Npl::insert(string& name) |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 30 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 31 | std::list<string >::iterator it = std::find_if( m_nameList.begin(), |
32 | m_nameList.end(), | ||||
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 33 | bind(&nameCompare, _1 , name)); |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 34 | if( it != m_nameList.end() ) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 35 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 36 | return -1; |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 37 | } |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 38 | m_nameList.push_back(name); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 39 | return 0; |
40 | } | ||||
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 41 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 42 | int |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 43 | Npl::remove(string& name) |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 44 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 45 | std::list<string >::iterator it = std::find_if( m_nameList.begin(), |
46 | m_nameList.end(), | ||||
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 47 | bind(&nameCompare, _1 , name)); |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 48 | if( it != m_nameList.end() ) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 49 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 50 | m_nameList.erase(it); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 51 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 52 | return -1; |
53 | } | ||||
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 54 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 55 | void |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 56 | Npl::sort() |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 57 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 58 | m_nameList.sort(); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 59 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 60 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 61 | void |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 62 | Npl::print() |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 63 | { |
64 | int i=1; | ||||
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 65 | for( std::list<string>::iterator it=m_nameList.begin(); it != m_nameList.end(); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 66 | it++) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 67 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 68 | cout<<"Name "<<i<<" : "<<(*it)<<endl; |
69 | i++; | ||||
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 70 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 71 | } |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 72 | |
73 | }//namespace nlsr |