akmhoque | 87347a3 | 2014-01-31 11:00:44 -0600 | [diff] [blame] | 1 | #include<iostream> |
| 2 | #include<algorithm> |
| 3 | |
| 4 | #include "adl.hpp" |
| 5 | #include "adjacent.hpp" |
| 6 | |
| 7 | Adl::Adl(){ |
| 8 | } |
| 9 | |
| 10 | Adl::~Adl(){ |
| 11 | |
| 12 | } |
| 13 | |
| 14 | static bool |
| 15 | adjacent_compare(Adjacent& adj1, Adjacent& adj2){ |
| 16 | return adj1.getAdjacentName()==adj2.getAdjacentName(); |
| 17 | } |
| 18 | |
| 19 | int |
| 20 | Adl::insert(Adjacent& adj){ |
| 21 | std::list<Adjacent >::iterator it = std::find_if( adjList.begin(), |
| 22 | adjList.end(), |
| 23 | bind(&adjacent_compare, _1, adj)); |
| 24 | if ( it != adjList.end() ){ |
| 25 | return -1; |
| 26 | } |
| 27 | adjList.push_back(adj); |
| 28 | return 0; |
| 29 | } |
| 30 | int |
| 31 | Adl::updateAdjacentStatus(string adjName, int s){ |
| 32 | Adjacent adj(adjName); |
| 33 | |
| 34 | std::list<Adjacent >::iterator it = std::find_if( adjList.begin(), |
| 35 | adjList.end(), |
| 36 | bind(&adjacent_compare, _1, adj)); |
| 37 | |
| 38 | if( it == adjList.end()){ |
| 39 | return -1; |
| 40 | } |
| 41 | |
| 42 | (*it).setStatus(s); |
| 43 | return 0; |
| 44 | |
| 45 | |
| 46 | } |
| 47 | |
| 48 | int |
| 49 | Adl::updateAdjacentLinkCost(string adjName, double lc){ |
| 50 | Adjacent adj(adjName); |
| 51 | |
| 52 | std::list<Adjacent >::iterator it = std::find_if( adjList.begin(), |
| 53 | adjList.end(), |
| 54 | bind(&adjacent_compare, _1, adj)); |
| 55 | |
| 56 | if( it == adjList.end()){ |
| 57 | return -1; |
| 58 | } |
| 59 | |
| 60 | (*it).setLinkCost(lc); |
| 61 | return 0; |
| 62 | |
| 63 | } |
| 64 | |
| 65 | std::list<Adjacent> |
| 66 | Adl::getAdjList(){ |
| 67 | return adjList; |
| 68 | } |
| 69 | |
| 70 | // used for debugging purpose |
| 71 | void |
| 72 | Adl::printAdl(){ |
| 73 | for( std::list<Adjacent>::iterator it=adjList.begin(); it!= adjList.end() ; it++){ |
| 74 | cout<< (*it) <<endl; |
| 75 | } |
| 76 | } |