// framerecord.cpp Implementation file for FrameRecord class /******************************************************************************* // MODULE NAME: FrameRecord // INTERFACE FILE: framerecord.h // IMPLEMENTATION FILE: framerecord.cpp // // PURPOSE: To provide a FrameRecord type useful in implementing the BAL program // which allows the user to create a record, update a field in the record, print // the current value of a field in the record, test the validity of a field in // the record, compare one record to another to determine sorting order, and // produce strings with the record information in them which are formatted for // output either to standard output or to a BAM file. // // FUNCTIONS: Name Purpose // FrameRecord Paramterless constructor // FrameRecord Constructor w/specified Game Index // FrameRecord Constructor w/specified gdex, bdex, rdex // LessThan Test whether this record should precede another // GreaterThan Test whether this record should follow another // Equals Show whether this record has the same index as // another one // fieldOK Determine if anything is wrong with a field of // the record // FieldContains Print the contents of the field // FieldDefault Print the default contents of a field // FieldLimits Print the limits in effect on the field // FieldLabel Print the correct label for the field // FieldWidth Print the correct width for the field // IndexIs Indicate the index of the record // NewIndex Change the index of a record // Update Change the contents of a field // Reset Reset the value of a field to its default // Reset Reset all fields to their defaults // Replace Change all the fields of a record to the values // of all the fields of another record // List Create a string which holds the record's // contents formatted for on-screen viewing // Print Create a string which holds the record's // contents formatted for BAM file viewing // // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ #include "framerecord.h" /********************************CONSTRUCTORS**********************************/ /******************************************************************************* // FUNCTION NAME: FrameRecord // // DESCRIPTION OF FUNCTION: Parameterless Constructor // // DESCRIPTION OF ALGORITHM: Create an object of class FrameRecord w/default // values in all the fields by initializing each field to the appropriate // defaults with the member functions of the field types // // CALLED BY: client // CALLS: LimitInt::setLimit,LimitInt::SetSize,setChar::setString, // LimitFloat::setLimit,LimitFloat::SetSize // // PARAMETERS: none // // PRECONDITIONS: none // // POSTCONDITIONS: A FrameRecord object has been created w/the appropriate // default field values // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ FrameRecord::FrameRecord() { // Initialize gdex: gdex.setLimit(GREATERTHAN,F_GDEX_LIMIT); gdex.SetSize(F_GDEX_WIDTH); // Initialize frame: frame.setLimit(GREATERTHAN,F_FRAME_LOWER_LIMIT,LESSTHAN,F_FRAME_UPPER_LIMIT); frame.SetSize(F_FRAME_WIDTH); // Initialize shot: shot.setLimit(GREATERTHAN,F_SHOT_LOWER_LIMIT,LESSTHAN,F_SHOT_UPPER_LIMIT); shot.SetSize(F_SHOT_WIDTH); // Initialize bdex: bdex.setLimit(GREATERTHAN,F_BDEX_LIMIT); bdex.SetSize(F_BDEX_WIDTH); // Initialize rdex: rdex.setLimit(GREATERTHAN,F_RDEX_LIMIT); rdex.SetSize(F_RDEX_WIDTH); // Initialize approach: approach.setLimit(GREATERTHAN,F_APPROACH_LOWER_LIMIT,LESSTHANEQUALS, F_APPROACH_UPPER_LIMIT); approach.SetSize(F_APPROACH_WIDTH); // Initialize feet: feet.setLimit(GREATERTHAN,F_FEET_LOWER_LIMIT,LESSTHAN,F_FEET_UPPER_LIMIT); feet.SetSize(F_FEET_WIDTH); // Initialize mark: mark.setLimit(GREATERTHAN,F_MARK_LOWER_LIMIT,LESSTHAN,F_MARK_UPPER_LIMIT); mark.SetSize(F_MARK_WIDTH); // Initialize accuracy: accuracy.setLimit(GREATERTHAN,F_ACCURACY_LOWER_LIMIT,LESSTHAN, F_ACCURACY_UPPER_LIMIT); accuracy.SetSize(F_ACCURACY_WIDTH); // Initialize pinHit: pinHit.setLimit(GREATERTHANEQUALS,F_PINHIT_LOWER_LIMIT,LESSTHANEQUALS, F_PINHIT_UPPER_LIMIT); pinHit.SetSize(F_PINHIT_WIDTH); // Initialize score: score.setString(F_SCORE_STRING); // Initialize leave: leave.setString(F_LEAVE_STRING); } /******************************************************************************* // FUNCTION NAME: FrameRecord // // DESCRIPTION OF FUNCTION: Constructor w/specified Game Index // // DESCRIPTION OF ALGORITHM: Creates an object of class FrameRecord w/user- // specified index and default values for all other fields by calling the // appropriate member functions of each of the field types // // CALLED BY: client // CALLS: LimitInt::setLimit,LimitInt::SetSize,LimitInt::Store, // setChar::setString,LimitFloat::setLimit,LimitFloat::SetSize // // PARAMETERS: / in / gameIndex - int value of desired index // // PRECONDITIONS: none // // POSTCONDITIONS: A new FrameRecord has been created such that the value of // gdex is the specified gameIndex and all other fields contain default values // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ FrameRecord::FrameRecord(int gameIndex) { // Initialize gdex: gdex.setLimit(GREATERTHAN,F_GDEX_LIMIT); gdex.SetSize(F_GDEX_WIDTH); gdex.Store(gameIndex); // Initialize frame: frame.setLimit(GREATERTHAN,F_FRAME_LOWER_LIMIT,LESSTHAN,F_FRAME_UPPER_LIMIT); frame.SetSize(F_FRAME_WIDTH); // Initialie shot: shot.setLimit(GREATERTHAN,F_SHOT_LOWER_LIMIT,LESSTHAN,F_SHOT_UPPER_LIMIT); shot.SetSize(F_SHOT_WIDTH); // Initialize bdex: bdex.setLimit(GREATERTHAN,F_BDEX_LIMIT); bdex.SetSize(F_BDEX_WIDTH); // Initialize rdex: rdex.setLimit(GREATERTHAN,F_RDEX_LIMIT); rdex.SetSize(F_RDEX_WIDTH); // Initialize approach: approach.setLimit(GREATERTHAN,F_APPROACH_LOWER_LIMIT,LESSTHANEQUALS, F_APPROACH_UPPER_LIMIT); approach.SetSize(F_APPROACH_WIDTH); // Initialize feet: feet.setLimit(GREATERTHAN,F_FEET_LOWER_LIMIT,LESSTHAN,F_FEET_UPPER_LIMIT); feet.SetSize(F_FEET_WIDTH); // Initialize mark: mark.setLimit(GREATERTHAN,F_MARK_LOWER_LIMIT,LESSTHAN,F_MARK_UPPER_LIMIT); mark.SetSize(F_MARK_WIDTH); // Initialize accuracy: accuracy.setLimit(GREATERTHAN,F_ACCURACY_LOWER_LIMIT,LESSTHAN, F_ACCURACY_UPPER_LIMIT); accuracy.SetSize(F_ACCURACY_WIDTH); // Initialize pinHit: pinHit.setLimit(GREATERTHANEQUALS,F_PINHIT_LOWER_LIMIT,LESSTHANEQUALS, F_PINHIT_UPPER_LIMIT); pinHit.SetSize(F_PINHIT_WIDTH); // Initialize score: score.setString(F_SCORE_STRING); // Initialize leave: leave.setString(F_LEAVE_STRING); }; /******************************************************************************* // FUNCTION NAME: FrameRecord // // DESCRIPTION OF FUNCTION: Constructor w/specified Game Index, Ball Index, and // Release Index // // DESCRIPTION OF ALGORITHM: Creates an object of class FrameRecord w/user- // specified game, ball and release indexes and default values for all other // fields by calling the appropriate member functions of each of the field // types // // CALLED BY: client // CALLS: LimitInt::setLimit,LimitInt::SetSize,LimitInt::Store, // setChar::setString,LimitFloat::setLimit,LimitFloat::SetSize // // PARAMETERS: / in / gameIndex - int value of desired Game index // / in / ballIndex - int value of desired Ball index // / in / releaseIndex - int value of desired Release index // // PRECONDITIONS: none // // POSTCONDITIONS: A new FrameRecord has been created such that the value of // gdex is the specified gameIndex, bdex is the specified ballIndex, rdex is the // specified releaseIndex, and all other fields contain default values // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ FrameRecord::FrameRecord(int gameIndex,int ballIndex,int releaseIndex) { // Initialize gdex: gdex.setLimit(GREATERTHAN,F_GDEX_LIMIT); gdex.SetSize(F_GDEX_WIDTH); gdex.Store(gameIndex); // Initialize frame: frame.setLimit(GREATERTHAN,F_FRAME_LOWER_LIMIT,LESSTHAN,F_FRAME_UPPER_LIMIT); frame.SetSize(F_FRAME_WIDTH); // Initialize shot: shot.setLimit(GREATERTHAN,F_SHOT_LOWER_LIMIT,LESSTHAN,F_SHOT_UPPER_LIMIT); shot.SetSize(F_SHOT_WIDTH); // Initialize bdex: bdex.setLimit(GREATERTHAN,F_BDEX_LIMIT); bdex.SetSize(F_BDEX_WIDTH); bdex.Store(ballIndex); // Initialize rdex: rdex.setLimit(GREATERTHAN,F_RDEX_LIMIT); rdex.SetSize(F_RDEX_WIDTH); rdex.Store(releaseIndex); // Initialize approach: approach.setLimit(GREATERTHAN,F_APPROACH_LOWER_LIMIT,LESSTHANEQUALS, F_APPROACH_UPPER_LIMIT); approach.SetSize(F_APPROACH_WIDTH); // Initialize feet: feet.setLimit(GREATERTHAN,F_FEET_LOWER_LIMIT,LESSTHAN,F_FEET_UPPER_LIMIT); feet.SetSize(F_FEET_WIDTH); // Initialize mark: mark.setLimit(GREATERTHAN,F_MARK_LOWER_LIMIT,LESSTHAN,F_MARK_UPPER_LIMIT); mark.SetSize(F_MARK_WIDTH); // Initialize accuracy: accuracy.setLimit(GREATERTHAN,F_ACCURACY_LOWER_LIMIT,LESSTHAN, F_ACCURACY_UPPER_LIMIT); accuracy.SetSize(F_ACCURACY_WIDTH); // Initialize pinHit: pinHit.setLimit(GREATERTHANEQUALS,F_PINHIT_LOWER_LIMIT,LESSTHANEQUALS, F_PINHIT_UPPER_LIMIT); pinHit.SetSize(F_PINHIT_WIDTH); // Initialize score: score.setString(F_SCORE_STRING); // Initialize leave: leave.setString(F_LEAVE_STRING); }; /*********************************OBSERVERS************************************/ /******************************************************************************* // FUNCTION NAME: LessThan // // DESCRIPTION OF FUNCTION: Test whether this record should precede another // // DESCRIPTION OF ALGORITHM: Uses the LessThan member function of LimitInt to // compare the derived indices of the two records // // CALLED BY: client // CALLS: LimitInt::LessThan // // PARAMETERS: / in / another - FrameRecord this one is being compared to // // PRECONDITIONS: none // // POSTCONDITIONS: Returns true if the derived frame index of this record is // less than that of another record // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ bool FrameRecord::LessThan(FrameRecord another) { if (gdex.LessThan(another.gdex)) return true; if ((gdex.Equals(another.gdex))&&(shot.LessThan(another.shot))) return true; return false; } /******************************************************************************* // FUNCTION NAME: GreaterThan // // DESCRIPTION OF FUNCTION: Test whether this record should follow another one // // DESCRIPTION OF ALGORITHM: Using the GreaterThan member function of LimitInt, // compares the derived frame indices of the two records against each other. // // CALLED BY: client // CALLS: LimitInt::GreaterThan // // PARAMETERS: / in / another - FrameRecord this one is being compared to // // PRECONDITIONS: none // // POSTCONDITIONS: if the derived frame index of this record is greater than // that of the other record, returns true. Returns false otherwise. // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ bool FrameRecord::GreaterThan(FrameRecord another) { if (gdex.GreaterThan(another.gdex)) return true; if ((gdex.Equals(another.gdex))&&(shot.GreaterThan(another.shot))) return true; return false; } /******************************************************************************* // FUNCTION NAME: Equals // // DESCRIPTION OF FUNCTION: Test whether this record has the same derived frame // index value as another record // // DESCRIPTION OF ALGORITHM: Using the Equals member function of LimitInt, // compares the index of this record with the index of another // // CALLED BY: client // CALLS: LimitInt::Equals // // PARAMETERS: / in / another - FrameRecord this one is being compared to // // PRECONDITIONS: none // // POSTCONDITIONS: If the indices of the two records are exactly equal, returns // true. Returns false otherwise. // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ bool FrameRecord::Equals(FrameRecord another) { return ((gdex.Equals(another.gdex))&&(shot.Equals(another.shot))); } /******************************************************************************* // FUNCTION NAME: fieldOK // // DESCRIPTION OF FUNCTION: Detect whether there's an error in a field // // DESCRIPTION OF ALGORITHM: Depending upon the fieldToCheck variable, function // calls the appropriate error-checking function for the type of field in // question and returns the type of error detected in the field // // CALLED BY: client // CALLS: LimitInt::isValid,LimitFloat::isValid,setChar::isValid, // LaneType::isValid // // PARAMETERS: / in / fieldToCheck - FrameFieldType that indicates which field // of the record is to be checked for errors // // PRECONDITIONS: none // // POSTCONDITIONS: Returns the type of error found in the given field, if any // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ DataErrorType FrameRecord::fieldOK(FrameFieldType fieldToCheck) { DataErrorType error=NO_PROB; switch (fieldToCheck) // check the fields which have limits to see { // if they are invalid and report the type of error // These are all indexes case F_GDEX: if (!(gdex.isValid())) error=INDEX_RANGE_ERR; break; case F_BDEX: if (!(bdex.isValid())) error=INDEX_RANGE_ERR; break; case F_RDEX: if (!(rdex.isValid())) error=INDEX_RANGE_ERR; break; // These are setChars case F_SCORE: if (!(score.isValid())) error=CHAR_ERR; break; case F_LEAVE: if (!(leave.isValid())) error=CHAR_ERR; break; // Check the LaneType one case F_LANES: if (!(lanes.isValid())) error=LANES_ERR; break; // Limited ints and Limited floats case F_FRAME: if (!(frame.isValid())) error=RANGE_ERR; break; case F_SHOT: if (!(shot.isValid())) error=RANGE_ERR; break; case F_APPROACH: if (!(approach.isValid())) error=RANGE_ERR; break; case F_FEET: if (!(feet.isValid())) error=RANGE_ERR; break; case F_MARK: if (!(mark.isValid())) error=RANGE_ERR; break; case F_ACCURACY: if (!(accuracy.isValid())) error=RANGE_ERR; break; case F_PINHIT: if (!(pinHit.isValid())) error=RANGE_ERR; break; } return error; // Tell calling function status of that field } /******************************************************************************* // FUNCTION NAME: FieldContains // // DESCRIPTION OF FUNCTION: Report the contents of a given field // // DESCRIPTION OF ALGORITHM: Depending on the value of fieldToPrint, calls the // Print member function of that field's type // // CALLED BY: Replace, client // CALLS: LimitInt::Print,setChar::Print,LimitFloat::Print,LaneType::Print // // PARAMETERS: / in / fieldToPrint - FrameFieldType that specifies which field // is to be printed to the output string // // PRECONDITIONS: none // // POSTCONDITIONS: A string is returned which contains the current value of the // specified field and is the same width as that field's print size // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ string FrameRecord::FieldContains(FrameFieldType fieldToPrint) { string fieldString; // hold the string to report back switch (fieldToPrint) // Call the print function for the appropriate field { case F_GDEX: fieldString = gdex.Print(); break; case F_LANES: fieldString = lanes.Print(); break; case F_FRAME: fieldString = frame.Print(); break; case F_SHOT: fieldString = shot.Print(); break; case F_BDEX: fieldString = bdex.Print(); break; case F_RDEX: fieldString = rdex.Print(); break; case F_APPROACH: fieldString = approach.Print(); break; case F_FEET: fieldString = feet.Print(); break; case F_MARK: fieldString = mark.Print(); break; case F_ACCURACY: fieldString = accuracy.Print(); break; case F_PINHIT: fieldString = pinHit.Print(); break; case F_SCORE: fieldString = score.Print(); break; case F_LEAVE: fieldString = leave.Print(); break; } return fieldString; // Return the string with the field info in it } /******************************************************************************* // FUNCTION NAME: FieldDefault // // DESCRIPTION OF FUNCTION: Print the default contents of the specified field // // DESCRIPTION OF ALGORITHM: Depending on the value of fieldToCheck, calls the // Default member function for that field's type // // CALLED BY: client // CALLS: LimitInt::Default,setChar::Default,LimitFloat::Default, // LaneType::Default // // PARAMETERS: / in / fieldToCheck - FrameFieldType that indicates which // field's default string is to be returned // // PRECONDITIONS: none // // POSTCONDITIONS: A string containing the default value of the specified field // which has the appropriate width for that field is returned // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ string FrameRecord::FieldDefault(FrameFieldType fieldToCheck) { string defaultString; switch (fieldToCheck) // Call the Default() function for the appropriate field { case F_GDEX: defaultString = gdex.Default(); break; case F_LANES: defaultString = lanes.Default(); break; case F_FRAME: defaultString = frame.Default(); break; case F_SHOT: defaultString = shot.Default(); break; case F_BDEX: defaultString = bdex.Default(); break; case F_RDEX: defaultString = rdex.Default(); break; case F_APPROACH: defaultString = approach.Default(); break; case F_FEET: defaultString = feet.Default(); break; case F_MARK: defaultString = mark.Default(); break; case F_ACCURACY: defaultString = accuracy.Default(); break; case F_PINHIT: defaultString = pinHit.Default(); break; case F_SCORE: defaultString = score.Default(); break; case F_LEAVE: defaultString = leave.Default(); break; } return defaultString; // Return the string with the field info in it } /******************************************************************************* // FUNCTION NAME: FieldLimits // // DESCRIPTION OF FUNCTION: Create a string that has the info for a field's // constraints. // // DESCRIPTION OF ALGORITHM: Depending on the value of fieldToCheck, calls the // Limits member function of the appropriate field type // // CALLED BY: client // CALLS: LimitInt::Limits,setChar::Limits,LimitFloat::Limits,LaneType::Limits // // PARAMETERS: / in / fieldToCheck - FrameFieldType that indicates which // field's limits are to be output // // PRECONDITIONS: none // // POSTCONDITIONS: A string containing a message about the limits in effect // on the specified field is returned. // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ string FrameRecord::FieldLimits(FrameFieldType fieldToCheck) { string limitString; switch (fieldToCheck) // Find the limit string for the appropriate field { case F_GDEX: limitString = gdex.Limits(); break; case F_LANES: limitString = lanes.Limits(); break; case F_FRAME: limitString = frame.Limits(); break; case F_SHOT: limitString = shot.Limits(); break; case F_BDEX: limitString = bdex.Limits(); break; case F_RDEX: limitString = rdex.Limits(); break; case F_APPROACH: limitString = approach.Limits(); break; case F_FEET: limitString = feet.Limits(); break; case F_MARK: limitString = mark.Limits(); break; case F_ACCURACY: limitString = accuracy.Limits(); break; case F_PINHIT: limitString = pinHit.Limits(); break; case F_SCORE: limitString = score.Limits(); break; case F_LEAVE: limitString = leave.Limits(); break; } return limitString; // Report on the limits for that field } /******************************************************************************* // FUNCTION NAME: FieldLabel // // DESCRIPTION OF FUNCTION: Report the label of a given field // // DESCRIPTION OF ALGORITHM: Depending on the value of fieldToPrint, returns // the named constant which contains that field's label // // CALLED BY: client // CALLS: none // // PARAMETERS: / in / fieldToPrint - FrameFieldType that specifies which field // is being addressed // // PRECONDITIONS: none // // POSTCONDITIONS: A string is returned which contains the label as defined in // the record type's interface file. // // AUTHOR: Amy Langill *2B DATE: 3/28/1999 *******************************************************************************/ string FrameRecord::FieldLabel(FrameFieldType fieldToPrint) { string label; switch (fieldToPrint) { case F_GDEX: label = F_GDEX_LABEL; break; case F_LANES: label = F_LANES_LABEL; break; case F_FRAME: label = F_FRAME_LABEL; break; case F_SHOT: label = F_SHOT_LABEL; break; case F_BDEX: label = F_BDEX_LABEL; break; case F_RDEX: label = F_RDEX_LABEL; break; case F_APPROACH: label = F_APPROACH_LABEL; break; case F_FEET: label = F_FEET_LABEL; break; case F_MARK: label = F_MARK_LABEL; break; case F_ACCURACY: label = F_ACCURACY_LABEL; break; case F_PINHIT: label = F_PINHIT_LABEL; break; case F_SCORE: label = F_SCORE_LABEL; break; case F_LEAVE: label = F_LEAVE_LABEL; break; } return label; } /******************************************************************************* // FUNCTION NAME: FieldWidth // // DESCRIPTION OF FUNCTION: Reports the print size of the indicated field // // DESCRIPTION OF ALGORITHM: Depending on the value of fieldToCheck, returns // the named constant that represents that field's width // // CALLED BY: client // CALLS: none // // PARAMETERS: / in / fieldToCheck - FrameFieldType that indicates which part // of the record is being accessed // // PRECONDITIONS: none // // POSTCONDITIONS: An int is returned which indicates the defined width of the // desired field as specified by fieldToCheck. // // AUTHOR: Amy Langill *2B DATE: 3/28/1999 *******************************************************************************/ int FrameRecord::FieldWidth(FrameFieldType fieldToCheck) { int width=0; switch (fieldToCheck) { case F_GDEX: width = F_GDEX_WIDTH; break; case F_FRAME: width = F_FRAME_WIDTH; break; case F_SHOT: width = F_SHOT_WIDTH; break; case F_BDEX: width = F_BDEX_WIDTH; break; case F_RDEX: width = F_RDEX_WIDTH; break; case F_APPROACH: width = F_APPROACH_WIDTH; break; case F_FEET: width = F_FEET_WIDTH; break; case F_MARK: width = F_MARK_WIDTH; break; case F_ACCURACY: width = F_ACCURACY_WIDTH; break; case F_PINHIT: width = F_PINHIT_WIDTH; break; case F_LANES: width = LANE_WDTH; break; case F_SCORE: case F_LEAVE: width = CHAR_WIDTH; break; } return width; } /******************************************************************************* // FUNCTION NAME: IndexIs // // DESCRIPTION OF FUNCTION: Reports the index of the record // // DESCRIPTION OF ALGORITHM: Derives a frame index from the current value of // gdex and shot. // // CALLED BY: client // CALLS: LimitInt::valueIs // // PARAMETERS: none // // PRECONDITIONS: Both gdex and shot must contain meaningful values. // // POSTCONDITIONS: The current value of the record's index is returned. // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ int FrameRecord::IndexIs() { int index; index = (gdex.valueIs() * F_GDEX_MULTIPLIER) + shot.valueIs(); return index; } /********************************TRANSFORMERS**********************************/ /******************************************************************************* // FUNCTION NAME: NewIndex // // DESCRIPTION OF FUNCTION: Changes the index of the record to a new value // // DESCRIPTION OF ALGORITHM: Assigns the newIndexValue to shot with the // LimitInt::Store function // // CALLED BY: client // CALLS: LimitInt::Store // // PARAMETERS: / in / newIndexValue - int that tells what new index should be // // PRECONDITIONS: none // // POSTCONDITIONS: value of shot has been changed to newIndexValue // // AUTHOR: Amy Langill *2B DATE: 3/28/1999 *******************************************************************************/ void FrameRecord::NewIndex(int newIndexValue) { shot.Store(newIndexValue%F_GDEX_MULTIPLIER); return; } /******************************************************************************* // FUNCTION NAME: Update // // DESCRIPTION OF FUNCTION: Change the value of a specified field to the value // contained in the dataString // // DESCRIPTION OF ALGORITHM: Depending on the field to be updated, as indicated // by fieldToChange, function converts the string to a different type if // necessary and calls the Store member function of the field's type // // CALLED BY: Replace, client // CALLS: LimitInt::Store,setChar::Store,LimitFloat::Store,LaneType::Store // // PARAMETERS: / in / dataString - string that contains the value to be stored // in the field // / in / fieldToChange - FrameFieldType that indicates the field // to be changed to a new value // // PRECONDITIONS: dataString contains a value that can be converted to the // appropriate data type without difficulty // // POSTCONDITIONS: The field indicated by fieldToChange has been modified to // the value in dataString // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ void FrameRecord::Update(string dataString,FrameFieldType fieldToChange) { istringstream data(dataString); // For converting from string type int newIntValue; // Hold converted int data char newCharValue; // Hold converted char data float newFloatValue; // Hold converted float data switch (fieldToChange) // Store the data based on the field to be changed { case F_GDEX: data >> newIntValue; // Convert to int and store gdex.Store(newIntValue); // into gdex break; case F_BDEX: data >> newIntValue; // Convert to int and store bdex.Store(newIntValue); // into bdex break; case F_RDEX: data >> newIntValue; // Convert to int and store rdex.Store(newIntValue); // into rdex break; case F_FRAME: data >> newIntValue; // Convert to int and store frame.Store(newIntValue); // into frame break; case F_SHOT: data >> newIntValue; // Convert to int and store shot.Store(newIntValue); // into shot break; case F_APPROACH: data >> newFloatValue; // Convert to float and store approach.Store(newFloatValue); // into approach break; case F_FEET: data >> newFloatValue; // Convert to float and store feet.Store(newFloatValue); // into feet break; case F_MARK: data >> newFloatValue; // Convert to float and store mark.Store(newFloatValue); // into mark break; case F_ACCURACY: data >> newFloatValue; // Convert to float and store accuracy.Store(newFloatValue); // into accuracy break; case F_PINHIT: data >> newFloatValue; // Convert to float and store pinHit.Store(newFloatValue); // into pinHit break; case F_SCORE: data >> newCharValue; // Convert to char and store into score score.Store(newCharValue); break; case F_LEAVE: data >> newCharValue; // Convert to char and store into leave leave.Store(newCharValue); break; case F_LANES: lanes.Store(dataString); // No conversion. Store into lanes break; } return; } /******************************************************************************* // FUNCTION NAME: Reset // // DESCRIPTION OF FUNCTION: Reset the value of a specified field of the record // to its default value // // DESCRIPTION OF ALGORITHM: Depending on the value of fieldToChange, calls the // appropriate resetting member function of each field's type // // CALLED BY: client // CALLS: LimitInt::ResetValue,setChar::ResetValue,LimitFloat::ResetValue, // LaneType::Reset // // PARAMETERS: / in / fieldToChange - FrameFieldType that indicates which field // is to be changed to its default value // // PRECONDITIONS: none // // POSTCONDITIONS: The value of the specified field has been changd to the // default value for that field // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ void FrameRecord::Reset(FrameFieldType fieldToChange) { switch (fieldToChange) // depending on the field, call the function to change { // that element to its default value case F_GDEX: gdex.ResetValue(); break; case F_LANES: lanes.Reset(); break; case F_FRAME: frame.ResetValue(); break; case F_SHOT: shot.ResetValue(); break; case F_BDEX: bdex.ResetValue(); break; case F_RDEX: rdex.ResetValue(); break; case F_APPROACH: approach.ResetValue(); break; case F_FEET: feet.ResetValue(); break; case F_MARK: mark.ResetValue(); break; case F_ACCURACY: accuracy.ResetValue(); break; case F_PINHIT: pinHit.ResetValue(); break; case F_SCORE: score.ResetValue(); break; case F_LEAVE: leave.ResetValue(); break; } return; } /******************************************************************************* // FUNCTION NAME: Reset // // DESCRIPTION OF FUNCTION: Reset the value of all the fields of the record to // their respective default values // // DESCRIPTION OF ALGORITHM: Calls the appropriate resetting member function of // each field type for each field in the record // // CALLED BY: client // CALLS: LimitInt::ResetValue,setChar::ResetValue,LimitFloat::ResetValue, // LaneType::Reset // // PARAMETERS: none // // PRECONDITIONS: none // // POSTCONDITIONS: The value of all of the fields have been changed to the // default values for those fields // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ void FrameRecord::Reset() { // depending on the field, call the function to change // that element to its default value gdex.ResetValue(); lanes.Reset(); frame.ResetValue(); shot.ResetValue(); bdex.ResetValue(); rdex.ResetValue(); approach.ResetValue(); feet.ResetValue(); mark.ResetValue(); accuracy.ResetValue(); pinHit.ResetValue(); score.ResetValue(); leave.ResetValue(); return; } /******************************************************************************* // FUNCTION NAME: Replace // // DESCRIPTION OF FUNCTION: Replaces the contents of the current record with // the contents of another record. // // DESCRIPTION OF ALGORITHM: Updates each field in this record with the field // contents of newRecord. // // CALLED BY: client // CALLS: Update,FieldContains // // PARAMETERS: / in / newRecord - FrameRecord whose contents are to be stored // into this record // // PRECONDITIONS: none // // POSTCONDITIONS: The field values of every field in newRecord have been // stored into the appropriate fields of this record // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ void FrameRecord::Replace(FrameRecord newRecord) { FrameFieldType currFld; for (currFld=F_GDEX;currFld<=F_LEAVE;currFld=FrameFieldType(currFld+1)) this->Update(newRecord.FieldContains(currFld),currFld); return; } /**********************************ITERATORS***********************************/ /******************************************************************************* // FUNCTION NAME: List // // DESCRIPTION OF FUNCTION: Generate a string that holds the record information // formatted for screen output // // DESCRIPTION OF ALGORITHM: Creates a string that holds field labels and // contents as created by the Print member functionof each field's type for // every field in the record, delimited with spaces between the fields. // // CALLED BY: client // CALLS: LimitInt::Print,setChar::Print,LimitFloat::Print,LaneType::Print // // PARAMETERS: none // // PRECONDITIONS: none // // POSTCONDITIONS: A string has been created which contains the current data // stored in the record formatted for screen viewing // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ string FrameRecord::List() { string outputString; // To hold formatted output // print out label, data, spacing character for each field outputString = F_GDEX_LABEL + gdex.Print() + F_FLD_SEPARATOR; outputString += F_LANES_LABEL + lanes.Print() + F_FLD_SEPARATOR; outputString += F_FRAME_LABEL + frame.Print() + F_FLD_SEPARATOR; outputString += F_SHOT_LABEL + shot.Print() + F_FLD_SEPARATOR; outputString += F_BDEX_LABEL + bdex.Print() + F_FLD_SEPARATOR; outputString += F_RDEX_LABEL + rdex.Print() + '\n'; // Screen is only 80 characters wide, so we start another line outputString += F_APPROACH_LABEL + approach.Print() + F_FLD_SEPARATOR; outputString += F_FEET_LABEL + feet.Print() + F_FLD_SEPARATOR; outputString += F_MARK_LABEL + mark.Print() + F_FLD_SEPARATOR; outputString += F_ACCURACY_LABEL + accuracy.Print() + F_FLD_SEPARATOR; outputString += F_PINHIT_LABEL + pinHit.Print() + F_FLD_SEPARATOR; outputString += F_SCORE_LABEL + score.Print() + '\n'; // Ran out of room, need a third line outputString += F_LEAVE_LABEL + leave.Print(); return outputString; // send back the screen-formatted output } /******************************************************************************* // FUNCTION NAME: Print // // DESCRIPTION OF FUNCTION: Generate a string that holds the record formatted // for BAM file output // // DESCRIPTION OF ALGORITHM: Creates a string which contains the field labels // and contents for each field delimited by spaces through successive // assignment to the output string // // CALLED BY: client // CALLS: LimitInt::Print,setChar::Print,LimitFloat::Print,DateType::Print // // PARAMETERS: none // // PRECONDITIONS: none // // POSTCONDITIONS: A string has been created which contains the current data // stored in the record formatted for BAM file output // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ string FrameRecord::Print() { string outputString; // To hold formatted output // for each field, printout label, data, space outputString = F_GDEX_LABEL + gdex.Print() + F_FLD_SEPARATOR; outputString += F_LANES_LABEL + lanes.Print() + F_FLD_SEPARATOR; outputString += F_FRAME_LABEL + frame.Print() + F_FLD_SEPARATOR; outputString += F_SHOT_LABEL + shot.Print() + F_FLD_SEPARATOR; outputString += F_BDEX_LABEL + bdex.Print() + F_FLD_SEPARATOR; outputString += F_RDEX_LABEL + rdex.Print() + '\n'; // Record stretches over 2 lines outputString += F_APPROACH_LABEL + approach.Print() + F_FLD_SEPARATOR; outputString += F_FEET_LABEL + feet.Print() + F_FLD_SEPARATOR; outputString += F_MARK_LABEL + mark.Print() + F_FLD_SEPARATOR; outputString += F_ACCURACY_LABEL + accuracy.Print() + F_FLD_SEPARATOR; outputString += F_PINHIT_LABEL + pinHit.Print() + F_FLD_SEPARATOR; outputString += F_SCORE_LABEL + score.Print() + F_FLD_SEPARATOR; outputString += F_LEAVE_LABEL + leave.Print(); return outputString; // send back the report-formatted output }