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

mapnode.c

Go to the documentation of this file.
00001 /**********************************************************************
00002 *       FILE:     MAPNODE.c
00003 *       AUTHOR:   E. Otis O
00004 *       DATE:     17 April 1993
00005 *       MODIFIED: 30 April 1993 (5:00 pm)
00006 *       PURPOSE:
00007 *         Functions to store and manipulate a node.
00008 ***********************************************************************/
00009 
00010 #include <assert.h>
00011 #include "mapnode.h"
00012 
00013 
00014 /**********************************************************************
00015 *       Public Functions
00016 ***********************************************************************/
00017 
00018 bool MapNode::is_link (mode transportation) {
00019 
00020   int i= 0;
00021 
00022   // if bit vector "transportation" is on...
00023   while ( (i < numLinks) && !(links[i].type & On << transportation) ) i++;
00024   // ...then "i" should be less than numLinks so return True, else False
00025   return (i < numLinks) ? True : False;
00026 }
00027 
00028 /************************************************************/
00029 
00030 bool MapNode::is_link (int link, mode transportation) {
00031 // Determine if node is a taxi link
00032 
00033   int i= 0;
00034  
00035   while (link != links[i].destination) i++;  // find the link...
00036   // ...and return whether its transportation bit is on or off
00037   return (links[i].type & On << transportation);
00038 }
00039 
00040 /************************************************************/
00041 
00042 vect MapNode::find_vector (int link) {
00043 // Return the bit vector of a given link
00044 
00045   int i= 0;
00046 
00047   while (link != links[i].destination) i++;  // find the link...
00048   // ...and return its bit vector
00049   return links[i].type;
00050 }
00051 
00052 /************************************************************/
00053 
00054 int MapNode::find_link (int linkNum) {
00055   if ( between(linkNum, 0, numLinks) ) return links[linkNum].destination;
00056   else {
00057     cerr << "Link " << linkNum << " out of range ("
00058          << 0 << ".." << numLinks << ")\n";
00059     return 0;  // node 0 points to NULL
00060   }
00061 }
00062 
00063 
00064 /************************************************************/
00065 
00066 void MapNode::get_name (char *nodeName, int size) {
00067 // Input a node name (if one exists) of size "size"
00068 
00069   if (size > 1) {
00070     name= new char[size];
00071     for (int i= 0; i < size; i++) name[i]= nodeName[i];
00072   }
00073 }
00074 
00075 /*************************************************************/
00076 
00077 void MapNode::get_link (int node, mode transportation) {
00078 // Input a link and establish its "transportation" type in the bit
00079 // vector
00080 
00081   Route *oldLinks= links;
00082   int   num= 0;
00083 
00084   if (numLinks > 0)
00085     while ((node != links[num].destination) && (num < numLinks)) num++;
00086 
00087   if (num >= numLinks) {
00088     num= numLinks;
00089 
00090     links= new Route[++numLinks];
00091     assert( links != 0 );
00092 
00093     for (int i= 0; i < num; i++)
00094       links[i]= oldLinks[i];  // copy the array 
00095 
00096     links[num].destination= node;
00097   }
00098   // turn transportation bit on
00099   links[num].type |= On << transportation;
00100 }
00101 
00102 /*************************************************************/
00103 
00104 void MapNode::show_node (void) {
00105 // Output a node in a tabular (sort of) format for debugging purposes
00106 
00107   int i;
00108 
00109   cout << "\nTaxi: ";
00110   for (i= 0; i < numLinks; i++)  // find all taxi routes
00111     if (links[i].type & On << Taxi) cout << ' ' << links[i].destination;
00112   cout << "\nBus: ";
00113   for (i= 0; i < numLinks; i++)  // find all bus routes
00114     if (links[i].type & On << Bus) cout << ' ' << links[i].destination;
00115   cout << "\nSubway: ";
00116   for (i= 0; i < numLinks; i++)  // find all subway routes
00117     if (links[i].type & On << Subway) cout << ' ' << links[i].destination;
00118   cout << "\nAll:  ";
00119   for (i= 0; i < numLinks; i++)  // show all routes and (bit vector)s
00120     cout << links[i].destination << " (" << links[i].type << ") ";
00121   cout << "\nName: ``";
00122   if (name == NULL) cout << "(null)";
00123   else cout << name;
00124   cout << "''\n";
00125   cout << "x: " << x << "   y: " << y << "\n";
00126 }
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 

Generated on Sun Jul 6 23:07:15 2003 for Scotland Yard by doxygen1.2.15