// mcthing.h // // Base class for all entities in // This class is pure virtual to ensure that type is defined. #ifndef _MCTHING_H_ #define _MCTHING_H_ #include "idman.h" class mcContext; // Forward declaration to avoid circular dependency class mcThing { static IDManager idman; int id; protected: mcContext *mgr; public: mcThing(mcContext *a_mgr) : mgr(a_mgr), id(idman.getNextID()) { } virtual ~mcThing() { } // Type information enum type { LINE, STATION, STATION_NODE, LINE_SEGMENT, TYPE_COUNT // back marker }; virtual type getType() = 0; int getId() { return id; } virtual CString getName() = 0; // Function to determine whether the element can be deleted safely. // Basically, if any other elements depend on this one, then it can't // be deleted. virtual BOOL deletable() { return TRUE; } // Function to return a list of all the elements that *directly* depend // on this one. Direct dependence requires that the dependent element // includes a reference to this object (in DB parlance, contains a FK // reference). // Returns null if no dependents found. virtual CObList *getDependents() { return 0; } // SQL members // Name of the table into which elements of a particular type are to be // written virtual CString getSqlTable() = 0; // The content of the VALUES clause in the SQL INSERT statement. // Note: brackets are placed around this text, but commas and literals // must be supplied. virtual CString getSqlInsertData() = 0; protected: // Utility function for putting literals around strings // Note: the intention is to substitute '' for ' where appropriate CString literal(const CString &string) { CString result("'"); CString data(string); for (int litIdx = data.Find("'"); litIdx != -1; litIdx = data.Find("'")) { result += data.Left(litIdx) + "''"; data = data.Mid(litIdx + 1); } result += data + "'"; return result; } }; #endif // _MCTHING_H_