// stationnode.h // // Class to hold station node information (that is, the intersection of // stations and lines) #ifndef _STATIONNODE_H_ #define _STATIONNODE_H_ #include "numstring.h" #include "line.h" #include "station.h" class StationNode : public mcThing { CString name; // artificial really, but still Station *station; Line *line; int quadrant; // comprised of quadrants int ordinal; // arbitrary number BOOL interchange; BOOL terminus; CPoint coords; public: enum quadrants { NONE = 0, // ... or Tottenham Court Road, as it's also known. QUAD1 = 1, // NE QUAD2 = 1 << 1, // SE QUAD3 = 1 << 2, // SW QUAD4 = 1 << 3, // NW UNKNOWN = -1 // unspecified }; BOOL visited; // used for node traversal StationNode(mcContext *mgr, Station *a_station, Line *a_line, int a_quadrant, int a_ordinal, BOOL a_interchange, BOOL a_terminus, CPoint a_coords) : mcThing(mgr) ,station(a_station) ,line(a_line) ,quadrant(a_quadrant) // should be able to derive from coords... ,ordinal(a_ordinal) ,interchange(a_interchange) ,terminus(a_terminus) ,coords(a_coords) ,visited(FALSE) { name = deriveName(station->getName(), line->getName(), ordinal); } // Accessors - get accessors only! CString getName() { return name; } Station *getStation() { return station; } int getStationID() { return station->getId(); } Line *getLine() { return line; } int getLineID() { return line->getId(); } int getQuadrant() { return quadrant; } int getOrdinal() { return ordinal; } BOOL getInterchange() { return interchange; } BOOL getTerminus() { return terminus; } const CPoint &getCoords() { return coords; } mcThing::type getType() { return mcThing::STATION_NODE; } // Utility function used to derive StationNode name text static CString deriveName(const CString &station, const CString &line, int nodeOrdinal) { return station + " (" + line + "):" + CNumString(nodeOrdinal); } // SQL members CString getSqlTable() { return "STATION_NODE"; } CString getSqlInsertData() { // STATION_NODE := ID, STATION_ID, LINE_ID, ORDINAL, QUADRANT, INTERCHANGE, TERMINUS, X, Y return CNumString(getId()) + ", " + CNumString(station->getId()) + ", " + CNumString(line->getId()) + ", " + CNumString(ordinal) + ", " + literal(quadToString(quadrant)) + ", " + literal(interchange ? "Y" : "N") + ", " + literal(terminus ? "Y" : "N") + ", " + CNumString(coords.x) + ", " + CNumString(coords.y); } static CString quadToString(int quad) { CString result; switch (quad) { case NONE: break; // empty is sufficient case QUAD1: result = "NE"; break; case QUAD2: result = "SE"; break; case QUAD3: result = "SW"; break; case QUAD4: result = "NW"; break; case QUAD1 | QUAD4: result = "N"; break; case QUAD2 | QUAD1: result = "E"; break; case QUAD3 | QUAD2: result = "S"; break; case QUAD4 | QUAD3: result = "W"; break; default: result = "?"; break; } return result; }; }; #endif // _STATIONNODE_H_