#include #include #include #include #include using namespace std ; #include "IntFamily.h" #include "ParseFamily.h" #define INBUFFSIZE 4096 vector *ParseFamily(istream *myInput) { char Inbuff[INBUFFSIZE+1] ; vector *retList = new vector() ; while (myInput->getline(Inbuff, INBUFFSIZE) && myInput->gcount()) { if (myInput->gcount() >= INBUFFSIZE-1) { cerr << "Ridiculous input" << endl ; exit(1) ; } // I added the '\n' to make MS Windows happy Inbuff[myInput->gcount()-1] = '\n' ; Inbuff[myInput->gcount()] = '\0' ; string *inLine = new string(Inbuff) ; istringstream lineStream(*inLine) ; bool goodLine = true ; int parent ; lineStream >> parent ; if (!lineStream.good()) cerr << "Bad parent name in: " << *inLine << endl ; else { char c1 = '?' ; char c2 = '?' ; lineStream >> c1 ; lineStream.get(c2) ; if (c1 != '-' || c2 != '>') cerr << "Missing -> in: " << *inLine << endl ; else { IntFamily *newFamily = new IntFamily(parent) ; int child ; lineStream >> child ; if (!lineStream.eof()) { if (!lineStream.good()) goodLine = false ; // Looking for , NNNN , NNNN etc. newFamily->addChild(child) ; while (goodLine && lineStream.good()) { char c = '?' ; lineStream >> c ; if (lineStream.eof()) ; else if (c != ',' || lineStream.bad()) goodLine = false ; else { lineStream >> child ; if (lineStream.good()) newFamily->addChild(child) ; else goodLine = false ; } } } if (!goodLine) { cerr << "Bad child list: " << *inLine << endl ; delete newFamily ; } else retList->push_back(*newFamily) ; } delete inLine ; } } return retList ; }