00001
00002
00003
00004
00005
00006
00007
00008 #include <map>
00009 using namespace std;
00010
00011 typedef int Node_Id;
00012 typedef int Link_Id;
00013
00014 #define INVALID_LINK_ID (-1)
00015
00027
00028 class Routing_Table
00029 {
00041 typedef map<Node_Id, Link_Id> Routing_Map;
00042
00045 Routing_Map m_routing_Map;
00046
00047 public:
00048 enum Status {FAILURE, SUCCESS};
00049
00062
00063 void Print()
00064 {
00065
00066
00067 Routing_Map::iterator it;
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 for (it = m_routing_Map.begin(); it != m_routing_Map.end(); it++)
00084 {
00085 printf ("Node_Id = %d, Link_Id = %d\n", it->first, it->second);
00086 }
00087 }
00088
00098
00099 Status Add_Routing_Entry(Node_Id node_Id, Link_Id link_Id)
00100 {
00101 Status status;
00102
00103
00104 if (m_routing_Map.find(node_Id) != m_routing_Map.end())
00105 {
00106
00107
00108 status = FAILURE;
00109 }
00110 else
00111 {
00112
00113
00114 m_routing_Map[node_Id] = link_Id;
00115
00116 status = SUCCESS;
00117 }
00118 }
00119
00126
00127 Status Remove_Routing_Entry(Node_Id node_Id)
00128 {
00129 Status status;
00130
00131 if (m_routing_Map.find(node_Id) != m_routing_Map.end())
00132 {
00133
00134 m_routing_Map.erase(node_Id);
00135 status = SUCCESS;
00136 }
00137 else
00138 {
00139 status = FAILURE;
00140 }
00141
00142 return status;
00143 }
00144
00152
00153 Link_Id Route(Node_Id node_Id)
00154 {
00155 Link_Id link_Id = INVALID_LINK_ID;
00156
00157 if (m_routing_Map.find(node_Id) != m_routing_Map.end())
00158 {
00159 link_Id = m_routing_Map[node_Id];
00160 }
00161 return link_Id;
00162 }
00163 };