Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Map Class Reference

#include <map.h>

List of all members.

Public Methods

 Map (void)
 ~Map ()
bool load_map (char *)
void show_map (void)
int max_x (void)
int max_y (void)
int x (int node)
int y (int node)
int first_node (void)
int num_nodes (void)
int connected_to (int, int, int=-1)
int num_connections (int, int=-1)
char * get_name (int node)
int next_short (int, int, bool, bool, bool)
bool taxi (int node)
bool bus (int node)
bool subway (int node)
bool taxi (int fromNode, int toNode)
bool bus (int fromNode, int toNode)
bool subway (int fromNode, int toNode)
vect vehicle (int fromNode, int toNode)

Private Methods

void initialize (int *array, int size)
void get_field (int, mode)

Private Attributes

int numNodes
int maxX
int maxY
MapNodenodes
ifstream mapFile


Constructor & Destructor Documentation

Map::Map void    [inline]
 

Definition at line 42 of file map.h.

References maxX, maxY, and numNodes.

00042 { numNodes= 0; nodes= NULL; maxX= 0; maxY= 0; }

Map::~Map   [inline]
 

Definition at line 43 of file map.h.

00043 { delete [] nodes; }


Member Function Documentation

bool Map::bus int    fromNode,
int    toNode
[inline]
 

Definition at line 71 of file map.h.

References Bus, and MapNode::is_link().

00072     { return nodes[fromNode].is_link(toNode, Bus); }

bool Map::bus int    node [inline]
 

Definition at line 65 of file map.h.

References Bus, and MapNode::is_link().

00065 { return nodes[node].is_link(Bus); }

int Map::connected_to int   ,
int   ,
int    = -1
 

Definition at line 113 of file map.c.

References between(), MapNode::find_join(), MapNode::find_link(), FIRST, nodes, and numNodes.

00113                                                    {
00114 
00115   if ( between(node, FIRST, numNodes) )
00116     if ( join > -1 )
00117       return nodes[node].find_join(link, join);
00118     else {
00119       return nodes[node].find_link(link);
00120 }  
00121 
00122   else {
00123     cerr << "Node " << node << " out of range ("
00124    << FIRST << ".." << numNodes << ")\n";
00125     return 0;  // node 0 points to NULL
00126   }
00127 }

int Map::first_node void    [inline]
 

Definition at line 54 of file map.h.

References FIRST.

00054 { return FIRST; }

void Map::get_field int   ,
mode   
[private]
 

Definition at line 23 of file map.c.

References FIELD, MapNode::get_join(), MapNode::get_link(), mapFile, mode, nodes, SUB1, and SUB2.

Referenced by load_map().

00023                                                   {
00024 // Input a transportation field from the map file.
00025 
00026   char ch;
00027   int  link;
00028 
00029   mapFile >> ch;
00030   if ( ch != FIELD ) {
00031     mapFile.putback(ch);
00032     while ( ch != FIELD ) {
00033       mapFile >> link >> ch;
00034       nodes[node].get_link(link, transportation);
00035       if ( ch == SUB1 ) {  // if a subfield is found...
00036   while ( ch != SUB2 ) {  // ...loop through the subfield until end
00037     mapFile >> link >> ch;
00038     nodes[node].get_join(link);
00039   }
00040         mapFile >> ch;  // pattern always ")," or ");"
00041       }
00042     }
00043   }
00044 }

char* Map::get_name int    node [inline]
 

Definition at line 60 of file map.h.

References MapNode::find_name().

00060 { return nodes[node].find_name(node); }

void Map::initialize int *    array,
int    size
[private]
 

Definition at line 18 of file map.c.

00019     { for (int i= 0; i < size; i++) array[i]= 0; }

bool Map::load_map char *   
 

Definition at line 67 of file map.c.

References Bus, EOLN, FIRST, get_field(), MapNode::get_name(), mapFile, maxX, maxY, nodes, numNodes, Subway, Taxi, MapNode::x, and MapNode::y.

Referenced by main().

00067                                  {
00068 // Read in a map and construct a data representation
00069 
00070   const int  BUFFER= 40;    // size of the "node name" input buffer
00071   const char COMMENT= '/';  // lines beginning with COMMENT are ignored
00072 
00073   char text[BUFFER], ch;
00074   int nodeNum= 0;
00075 
00076   mapFile.open(mapName, ios::in);
00077 
00078   if ( !mapFile.fail() ) {
00079     mapFile >> numNodes;
00080 
00081     nodes= new MapNode[numNodes + FIRST];  // store the adjacency list here
00082     assert (nodes != 0);
00083 
00084     while ( nodeNum < numNodes ) {
00085       // ignore lines commented with COMMENT
00086   if (mapFile.peek() == COMMENT) while (mapFile.get() != EOLN) ;
00087       mapFile >> nodeNum >> ch;
00088 
00089       get_field(nodeNum, Taxi);
00090       get_field(nodeNum, Bus);
00091       get_field(nodeNum, Subway);
00092 
00093       mapFile >> nodes[nodeNum].x >> ch;
00094       if (nodes[nodeNum].x > maxX) maxX= nodes[nodeNum].x; 
00095       mapFile >> nodes[nodeNum].y >> ch;
00096       if (nodes[nodeNum].y > maxY) maxY= nodes[nodeNum].y;
00097 
00098       ch= mapFile.get();
00099       while (ch == ' ') ch= mapFile.get();  // ignore whitespace
00100       mapFile.putback(ch);  // put the last read character back into the buffer
00101       mapFile.getline(text, BUFFER, EOLN);  // input node name and...
00102       // ...store name in adjacency list
00103       nodes[nodeNum].get_name(text, mapFile.gcount());
00104     }
00105   }
00106 
00107   mapFile.close();
00108   return (bool) mapFile.good();  // return true if all file operations went well
00109 }

int Map::max_x void    [inline]
 

Definition at line 48 of file map.h.

References maxX.

00048 { return maxX; }

int Map::max_y void    [inline]
 

Definition at line 49 of file map.h.

References maxY.

00049 { return maxY; }

int Map::next_short int   ,
int   ,
bool   ,
bool   ,
bool   
 

Definition at line 147 of file map.c.

00147                                                {
00148 // This would have been a function to return the next nearest
00149 // link in a path using Dijkstra's shortest path algorithm.
00150 // Design changes, however, have made this function obsolete.
00151 // A nearest-neighbor algorithm is used instead.  We have
00152 // decided to implement this algorithm outside of the map
00153 // module.
00154 
00155    return 0;
00156 }

int Map::num_connections int   ,
int    = -1
 

Definition at line 131 of file map.c.

References between(), FIRST, nodes, MapNode::num_joins(), MapNode::numLinks, and numNodes.

00131                                             {
00132 
00133   if ( between(node, FIRST, numNodes) )
00134     if ( join > -1 ) 
00135       return nodes[node].num_joins(join);
00136     else
00137       return nodes[node].numLinks;
00138   else {
00139     cerr << "Node " << node << " out of range ("
00140    << FIRST << ".." << numNodes << ")\n";
00141     return 0;  // node 0 points to NULL
00142   }
00143 }

int Map::num_nodes void    [inline]
 

Definition at line 55 of file map.h.

References numNodes.

00055 { return numNodes; }

void Map::show_map void   
 

Definition at line 54 of file map.c.

References EOLN, FIRST, maxX, maxY, nodes, numNodes, and MapNode::show_node().

00054                         {
00055 // Show a tabular representation of the map for testing/debugging
00056 // purposes.
00057 
00058   for (int i= FIRST; i < numNodes; i++) {
00059     cout << "\nNODE #" << i << ": ";
00060     nodes[i].show_node();
00061   }
00062   cout << "\nmax x: " << maxX << "\nmax y: " << maxY << EOLN;
00063 }

bool Map::subway int    fromNode,
int    toNode
[inline]
 

Definition at line 74 of file map.h.

References MapNode::is_link(), and Subway.

00075     { return nodes[fromNode].is_link(toNode, Subway); }

bool Map::subway int    node [inline]
 

Definition at line 66 of file map.h.

References MapNode::is_link(), and Subway.

00066 { return nodes[node].is_link(Subway); }

bool Map::taxi int    fromNode,
int    toNode
[inline]
 

Definition at line 68 of file map.h.

References MapNode::is_link(), and Taxi.

00069     { return nodes[fromNode].is_link(toNode, Taxi); }

bool Map::taxi int    node [inline]
 

Definition at line 64 of file map.h.

References MapNode::is_link(), and Taxi.

00064 { return nodes[node].is_link(Taxi); }

vect Map::vehicle int    fromNode,
int    toNode
[inline]
 

Definition at line 77 of file map.h.

References MapNode::find_vector(), and vect.

00078     { return nodes[fromNode].find_vector(toNode); }

int Map::x int    node [inline]
 

Definition at line 51 of file map.h.

References MapNode::x.

00051 { return nodes[node].x; }

int Map::y int    node [inline]
 

Definition at line 52 of file map.h.

References MapNode::y.

00052 { return nodes[node].y; }


Member Data Documentation

ifstream Map::mapFile [private]
 

Definition at line 36 of file map.h.

Referenced by get_field(), and load_map().

int Map::maxX [private]
 

Definition at line 31 of file map.h.

Referenced by load_map(), Map(), max_x(), and show_map().

int Map::maxY [private]
 

Definition at line 31 of file map.h.

Referenced by load_map(), Map(), max_y(), and show_map().

MapNode* Map::nodes [private]
 

Definition at line 35 of file map.h.

Referenced by connected_to(), get_field(), load_map(), num_connections(), and show_map().

int Map::numNodes [private]
 

Definition at line 31 of file map.h.

Referenced by connected_to(), load_map(), Map(), num_connections(), num_nodes(), and show_map().


The documentation for this class was generated from the following files:
Generated on Sun Jul 6 23:07:17 2003 for Scotland Yard by doxygen1.2.15