// ************************************** // Node // ************************************** Node::Node(ifstream &in, NodeSetPtr nodes) throw(Error) { LoadName(in); CheckNameForDuplication(nodes); equatedTo = NULL; // load coordinates if (!GetAndDiscard(in, '(')) { Error e("Missing Paranthesis in node definition"); throw(e); } MoveToNextNumeric(in); // this includes '-' for negative numbers and '.' for missing leading 0's in >> x; if (!GetAndDiscard(in, ',')) { Error e("Missing Comma in node definition"); throw(e); } MoveToNextNumeric(in); in >> y; if (!GetAndDiscard(in, ')')) { Error e("Missing Paranthesis in node definition"); throw(e); } CheckForIdenticalNodes(nodes); nodes->push_back(this); #ifdef _tdebug cout << "created node " << name << endl; #endif } Node::Node(const float a, const float b, NodeSetPtr nodes) { equatedTo = NULL; x = a; y = b; name = ""; CheckForIdenticalNodes(nodes); nodes->push_back(this); } bool Node::CheckForIdenticalNodes(NodeSetPtr nodes) { // check to see that this node is not in the same location as another node for (unsigned int i=0; isize(); i++) { if (((*nodes)[i]->X() == x) && ((*nodes)[i]->Y() == y)) { // we need to equate these nodes if ((*nodes)[i]->equatedTo != NULL) equatedTo = (*nodes)[i]->equatedTo; // try and avoid chains else equatedTo = (*nodes)[i]; // from this point on, it doesn't matter what our x and y is, they will not be referred to return true; } } return false; } double Node::X() { // FIX THIS // if (equatedTo != NULL) return equatedTo->X(); return x; } double Node::Y() { // FIX THIS // if (equatedTo != NULL) return equatedTo->Y(); return y; } bool Node::CheckNameForDuplication(NodeSetPtr nodes) throw (Error) { for (unsigned int i=0; isize(); i++) { if ((*nodes)[i]->IsCalled(name)) { // error, name duplication Error e("Name duplication in node\n"); throw(e); return true; } } return false; } /*NodePtr Node::ResolveEquatedNodes(NodeSetPtr NS, bool &del) { if (equatedTo == NULL) { del = false; // don't delete this node, as it is the one with the actual coordinates return this; // way out } else { bool toDel; NodePtr temp = equatedTo->ResolveEquatedNodes(NS, toDel); if (toDel) delete equatedTo; del = true; // delete this node, it had been equated to something else // remove 'this' from NS return temp; } } */ bool operator==(Node &N1, Node &N2) { if ((N1.X() == N2.X()) && (N1.Y() == N2.Y())) return true; return false; }