blob: f8969e1a5b2ad62b15131378682d5cde9de2dca3 [file] [log] [blame]
akmhoque87347a32014-01-31 11:00:44 -06001#include<iostream>
2#include<algorithm>
3
4#include "adl.hpp"
5#include "adjacent.hpp"
6
7Adl::Adl(){
8}
9
10Adl::~Adl(){
11
12}
13
14static bool
15adjacent_compare(Adjacent& adj1, Adjacent& adj2){
16 return adj1.getAdjacentName()==adj2.getAdjacentName();
17}
18
19int
20Adl::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}
30int
31Adl::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
48int
49Adl::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
65std::list<Adjacent>
66Adl::getAdjList(){
67 return adjList;
68}
69
70// used for debugging purpose
71void
72Adl::printAdl(){
73 for( std::list<Adjacent>::iterator it=adjList.begin(); it!= adjList.end() ; it++){
74 cout<< (*it) <<endl;
75 }
76}