#include #include #include #include #include #include #include #include using namespace std ; #include "IntFamily.h" #include "ParseFamily.h" #include "GTNode.h" typedef map*> GTNMap ; main(int argc, char *argv[]) { vector *parsedFamilies ; if (argc != 3) { cerr << "Usage: " << argv[0] << " FAMILYFILE TESTFILE" << endl ; exit(1) ; } ifstream myFInput(argv[1]) ; if (myFInput.bad()) { cerr << "Unable to open " << argv[1] << endl ; exit(1) ; } parsedFamilies = ParseFamily(&myFInput) ; myFInput.close() ; ifstream myFTest(argv[2]) ; if (myFTest.bad()) { cerr << "Unable to open " << argv[2] << endl ; exit(1) ; } // Leave this one open for a while GTNMap IntPeople ; // Preallocate node 1 IntPeople[1] = new GTNode(1) ; vector::iterator ptrFamily ; for (ptrFamily = parsedFamilies->begin() ; ptrFamily != parsedFamilies->end() ; ++ptrFamily ) { bool goodFamily = true ; int intParent = ptrFamily->getParent() ; GTNode *nodeParent ; if (intParent < 1) { cerr << "Parent may not be negative: " << intParent << endl ; goodFamily = false ; } else { nodeParent = IntPeople[intParent] ; if (nodeParent == NULL) { cerr << "Parent has not previously been a child: " << intParent << endl ; goodFamily = false ; } else if (!nodeParent->isLeaf()) { cerr << "Parent already has a family: " << intParent << endl ; goodFamily = false ; } } // Test the children int numChildren = ptrFamily->getSize() ; for (int i=numChildren-1; i>=0; --i) { int intChild = ptrFamily->getChild(i) ; if (intChild < 1) { cerr << "Child may not be negative: " << intChild << endl ; goodFamily = false ; } else if (intChild == intParent) { cerr << "Child may not be own parent: " << intChild << endl ; goodFamily = false ; } else if (IntPeople[intChild] != NULL) { // The preceding tests seems to create extra vales cerr << "Child already has a parent: " << intChild << endl ; goodFamily = false ; } } if (goodFamily) { for (int i=numChildren-1; i>=0; --i) { int intChild = ptrFamily->getChild(i) ; IntPeople[intChild] = new GTNode(intChild) ; nodeParent->insert_first(IntPeople[intChild]) ; } } else cerr << "Ignoring -- " << *ptrFamily << endl ; } delete parsedFamilies ; #ifdef DEBUG GTNMap :: iterator famIter ; for (famIter = IntPeople.begin() ; famIter != IntPeople.end() ; ++famIter) { GTNode *nodePres = famIter->second ; // Need to figure out why this is necessary if (nodePres != NULL) { while (nodePres->parent() != NULL) { cout << nodePres->value() <<" <- " ; nodePres = nodePres->parent() ; } cout << nodePres->value() << endl ; } } #endif int P1, P2 ; char duh ; while (myFTest >> P1 && myFTest >> duh && myFTest >> P2) { cout << P1 << "," << P2 << endl ; } }