// report.cpp Functions for producing properly-formatted BAM files /******************************************************************************* // MODULE NAME: Report // INTERFACE FILE: report.h // IMPLEMENTATION FILE: report.cpp // // PURPOSE: To provide a method for producing a BAM file useful in implementing // the BAM program // // FUNCTIONS: Name Purpose // WriteBAMFile Create a BAM-formatted file // WriteBAMHeader Create section titles for BAM file // // AUTHOR: Amy Langill *2B DATE: 5/2/1999 *******************************************************************************/ #include "report.h" // For ListTypes & prototype #include "sectiontype.h" // For BALSectionType using namespace std; /******************************************************************************* // FUNCTION NAME: WriteBAMFile // // DESCRIPTION OF FUNCTION: Produces a correctly-formatted BAM file. // // DESCRIPTION OF ALGORITHM: For each section, prints out a section header, // calls the Print member function for the record type for every record in // the list. // // CALLED BY: writeFile // CALLS: WriteBAMHeader,AlleyListType::firstRecord,AlleyListType::Print, // AlleyListType::getNext,EventListType::firstRecord,EventListType::Print, // EventListType::getNext,ToolsListType::firstRecord,ToolsListType::Print, // ToolsListType::getNext,BallListType::firstRecord,BallListType::Print, // BallListType::getNext,ReleaseListType::firstRecord,ReleaseListType::Print, // ReleaseListType::getNext,ConditionsListType::firstRecord, // ConditionsListType::Print,ConditionsListType::getNext // // PARAMETERS: / in / Alleys - AlleyListType that holds the alley records to // be printed // / in / Events - EventListType that holds the event records to // be printed // / in / Tools - ToolsListType that holds the tools records to be // printed // / in / Balls - BallListType that holds the ball records to be // printed // / in / Releases - ReleaseListType that holds the release records // to be printed // / in / Conditions - ConditionsListType that hold the conditions // records to be printed // / in / Games - GameListType that holds the games records to be // printed // / in / Frames - FrameListType that holds the frames records to // be printed // / in / FileName - string that contains the full name, with // extension, of the BAM file to be produced // // PRECONDITIONS: All of the fields of all of the records in all of the lists // contain valid values. // // POSTCONDITIONS: A properly-formatted BAM file, named as specified by // FileName, which contains all the records of all the lists has been written // // AUTHOR: Amy Langill *2B DATE: 4/4/1999 *******************************************************************************/ void WriteBAMFile(AlleyListType& Alleys,EventListType& Events, ToolsListType& Tools,BallListType& Balls, ReleaseListType& Releases,ConditionsListType& Conditions, GameListType& Games,FrameListType& Frames,string FileName) { AlleyListPtr Aptr; // For moving through alley list EventListPtr Eptr; // For moving through event list ToolsListPtr Tptr; // For moving through tools list BallListPtr Bptr; // For moving through ball list ReleaseListPtr Rptr; // For moving through release list ConditionsListPtr Cptr; // For moving through conditions list GameListPtr Gptr; // For moving through games list FrameListPtr Fptr; // For moving through frames list bool RecordsInSection; // Are there any unprinted records left in the list? ofstream Report; // Report output file stream string WriteBAMHeader(BALSectionType section); // For writing section titles Report.open(FileName.c_str()); // Open up the report Report << WriteBAMHeader(ALLEY) << endl; // prints out the alleys RecordsInSection = Alleys.firstRecord(Aptr); // section of the report if (RecordsInSection) { Report << Aptr->element.Print() << endl; // Priming the while loop below RecordsInSection = Alleys.getNext(Aptr); } while (RecordsInSection) { Report << "-----------------------" << endl << Aptr->element.Print() << endl; RecordsInSection = Alleys.getNext(Aptr); } Report << WriteBAMHeader(EVENT) << endl; // Prints out the events RecordsInSection = Events.firstRecord(Eptr); // section of the report if (RecordsInSection) { Report << Eptr->element.Print() << endl; RecordsInSection = Events.getNext(Eptr); // Priming the while loop below } while (RecordsInSection) { Report << "-----------------------" << endl << Eptr->element.Print() << endl; RecordsInSection = Events.getNext(Eptr); } Report << WriteBAMHeader(TOOLS) << endl; // Prints out the tools RecordsInSection = Tools.firstRecord(Tptr); // section of the report if (RecordsInSection) { Report << Tptr->element.Print() << endl; RecordsInSection = Tools.getNext(Tptr); // priming read for while-loop } while (RecordsInSection) { Report << "-----------------------" << endl << Tptr->element.Print() << endl; RecordsInSection = Tools.getNext(Tptr); } Report << WriteBAMHeader(BALL) << endl; // Prints out the ball RecordsInSection = Balls.firstRecord(Bptr); // section of the report if (RecordsInSection) { Report << Bptr->element.Print() << endl; RecordsInSection = Balls.getNext(Bptr); // Priming the while loop } while (RecordsInSection) { Report << "-----------------------" << endl << Bptr->element.Print() << endl; RecordsInSection = Balls.getNext(Bptr); } Report << WriteBAMHeader(RELEASE) << endl; // Prints out the releases RecordsInSection = Releases.firstRecord(Rptr); // section of the report if (RecordsInSection) { Report << Rptr->element.Print() << endl; RecordsInSection = Releases.getNext(Rptr); // Priming the while loop } while (RecordsInSection) { Report << "-----------------------" << endl << Rptr->element.Print() << endl; RecordsInSection = Releases.getNext(Rptr); } Report << WriteBAMHeader(CONDITIONS) << endl; // Prints out the conditions RecordsInSection = Conditions.firstRecord(Cptr); // section of the report if (RecordsInSection) { Report << Cptr->element.Print() << endl; RecordsInSection = Conditions.getNext(Cptr); // Priming the while-loop } while (RecordsInSection) { Report << "-----------------------" << endl << Cptr->element.Print() << endl; RecordsInSection = Conditions.getNext(Cptr); } Report << WriteBAMHeader(GAME) << endl; // Prints out the games section RecordsInSection = Games.firstRecord(Gptr); // of the file if (RecordsInSection) { Report << Gptr->element.Print() << endl; RecordsInSection = Games.getNext(Gptr); } while (RecordsInSection) { Report << "-----------------------" << endl << Gptr->element.Print() << endl; RecordsInSection = Games.getNext(Gptr); } Report << WriteBAMHeader(FRAMES) << endl; // Prints out the frames section RecordsInSection = Frames.firstRecord(Fptr); // of the file if (RecordsInSection) { Report << Fptr->element.Print() << endl; RecordsInSection = Frames.getNext(Fptr); } while (RecordsInSection) { Report << "-----------------------" << endl << Fptr->element.Print() << endl; RecordsInSection = Frames.getNext(Fptr); } Report.close(); // Close the report when done return; } /******************************************************************************* // FUNCTION NAME: WriteBAMHeader // // DESCRIPTION OF FUNCTION: Produces a string that tells which section is // coming next in the BAM file // // DESCRIPTION OF ALGORITHM: Depending on the value of section, returns a // string with the section label in it. // // CALLED BY: WriteBAMFile // CALLS: none // // PARAMETERS: / in / section - BALSectionType that specifies which section's // title is to be printed // // PRECONDITIONS: none // // POSTCONDITIONS: A string is returned which contains a bunch of equals signs // and the label of the section specified in the parameter listing // // AUTHOR: Amy Langill *2B DATE: 4/3/1999 *******************************************************************************/ string WriteBAMHeader(BALSectionType section) { string label; // To hold the section title string output; // What gets returned switch (section) // Assign label the appropriate value { case ALLEY: label = "Alleys"; break; case EVENT: label = "Events"; break; case TOOLS: label = "Tools"; break; case BALL: label = "Balls"; break; case RELEASE: label = "Release"; break; case CONDITIONS: label = "Conditions"; break; case GAME: label = "Games"; break; case FRAMES: label = "Frames"; break; } // Create the output string output = "===================" + label + "==================="; return output; // Send the section header back to the caller }