#include #include #include #include #include #include #include #include using namespace std ; #include "IntFamily.h" #include "ParseFamily.h" #include "GTNode.h" #define FAMSLOTS 1000000 main(int argc, char *argv[]) { vector *parsedFamilies ; if (argc==1) parsedFamilies = ParseFamily(&cin) ; else { ifstream myFInput(argv[1]) ; if (myFInput.bad()) { cerr << "Unable to open " << argv[1] << endl ; exit(1) ; } parsedFamilies = ParseFamily(&myFInput) ; myFInput.close() ; } // Originally this was allocated on the stack // However, that made MS/Windows unhappy GTNode **IntPeople = new GTNode *[FAMSLOTS] ; for (int i=0; i *)NULL; 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) { 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 ; // Print the ancestry for (int i=0; i *nodePres = IntPeople[i] ; while (nodePres->parent() != NULL) { cout << nodePres->value() << " <- " ; nodePres = nodePres->parent() ; } cout << nodePres->value() << endl ; } } return 0; }