EventHelix.com: CASE Tools; Real-time and Embedded System Design; Object Oriented Design EventStudio 2.0: System Engineering CASE ToolEventStudio 2.5
Sequence diagram based system design and modeling
Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Routing_Table.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include <map>      // Header file include for map
00009 using namespace std;          // STL containers are defined in std namespace
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       // STL defines a nested type iterator. Here we have declared an instance
00066       // of this nested type.
00067       Routing_Map::iterator it;
00068       
00069       // Iterator it "points" to a structure defined as:
00070       // struct Pair
00071       // {
00072       //     Node_Id first;
00073       //     Link_Id second;
00074       // }; 
00075       
00076       // map supports predefined begin() and end() markers. begin() "points"
00077       // to the first entry in the map. end() points BEYOND the last entry
00078       // in the map (i.e. the last entry is the entry just before end()
00079       
00080       // STL provides pointer like symantics to iterators, thus it++ moves
00081       // the iterator to the next entry in the map.
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       // First check if the entry already exists
00104       if (m_routing_Map.find(node_Id) != m_routing_Map.end())
00105       {
00106           // Iterator returns a value other than end, thus this
00107           // is a duplicate addition, return failure
00108          status = FAILURE;
00109       }
00110       else
00111       {
00112          // The end iterator was returned, signifying that
00113          // no entry currently exists, so a new one can be added.
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       // Check if the terminal is present
00131       if (m_routing_Map.find(node_Id) != m_routing_Map.end())
00132       {         
00133          // Erase the entry from the map.
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       // Check if the route entry is present
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 };

Generated on Sun Feb 13 21:30:18 2005 for Object Oriented Design Examples by doxygen 1.3.4
 Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Copyright © 2000-2005 EventHelix.com Inc. All Rights Reserved.