00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "map.h"
00012
00013
00014
00015
00016
00017
00018 void Map::initialize(int *array, int size)
00019 { for (int i= 0; i < size; i++) array[i]= 0; }
00020
00021
00022
00023 void Map::get_field (int node, mode transportation) {
00024
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 ) {
00036 while ( ch != SUB2 ) {
00037 mapFile >> link >> ch;
00038 nodes[node].get_join(link);
00039 }
00040 mapFile >> ch;
00041 }
00042 }
00043 }
00044 }
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 void Map::show_map (void) {
00055
00056
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 }
00064
00065
00066
00067 bool Map::load_map (char *mapName) {
00068
00069
00070 const int BUFFER= 40;
00071 const char COMMENT= '/';
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];
00082 assert (nodes != 0);
00083
00084 while ( nodeNum < numNodes ) {
00085
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();
00100 mapFile.putback(ch);
00101 mapFile.getline(text, BUFFER, EOLN);
00102
00103 nodes[nodeNum].get_name(text, mapFile.gcount());
00104 }
00105 }
00106
00107 mapFile.close();
00108 return (bool) mapFile.good();
00109 }
00110
00111
00112
00113 int Map::connected_to (int node, int link, int join) {
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;
00126 }
00127 }
00128
00129
00130
00131 int Map::num_connections (int node, int join) {
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;
00142 }
00143 }
00144
00145
00146
00147 int Map::next_short (int, int, bool, bool, bool) {
00148
00149
00150
00151
00152
00153
00154
00155 return 0;
00156 }
00157
00158
00159