// ballrecord.cpp Implementation file for BallRecord class /******************************************************************************* // MODULE NAME: BallRecord // INTERFACE FILE: ballrecord.h // IMPLEMENTATION FILE: ballrecord.cpp // // PURPOSE: To provide a BallRecord 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 // BallRecord Paramterless constructor // BallRecord Constructor w/specified Ball Index // 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 // BriefList Create a string which holds a short version of // the record's contents // Print Create a string which holds the record's // contents formatted for BAM file viewing // // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ #include "ballrecord.h" /********************************CONSTRUCTORS**********************************/ /******************************************************************************* // FUNCTION NAME: BallRecord // // DESCRIPTION OF FUNCTION: Parameterless Constructor // // DESCRIPTION OF ALGORITHM: Create an object of class BallRecord with 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,BALString::SetSize, // setChar::setString,LimitFloat::setLimit,LimitFloat::SetSize // // PARAMETERS: none // // PRECONDITIONS: none // // POSTCONDITIONS: A BallRecord object has been created w/the appropriate // default field values // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ BallRecord::BallRecord() { // Set up bdex: bdex.setLimit(GREATERTHAN,B_BDEX_LIMIT); bdex.SetSize(B_BDEX_WIDTH); // Set up co: co.SetSize(B_CO_WIDTH); // Set up model: model.SetSize(B_MODEL_WIDTH); // Set up pds: pds.setLimit(GREATERTHAN,B_PDS_LOWER_LIMIT,LESSTHAN,B_PDS_UPPER_LIMIT); pds.SetSize(B_PDS_WIDTH); // Set up oz: oz.setLimit(GREATERTHAN,B_OZ_LOWER_LIMIT,LESSTHAN,B_OZ_UPPER_LIMIT); oz.SetSize(B_OZ_WIDTH); // Set up rolls: rolls.setLimit(GREATERTHAN,B_ROLLS_LIMIT); rolls.SetSize(B_ROLLS_WIDTH); // Set up trac: trac.setString(B_TRAC_STRING); // Set up surface: surface.setString(B_SURFACE_STRING); // Set up hardness: hardness.setLimit(GREATERTHANEQUALS,B_HARDNESS_LIMIT); hardness.SetSize(B_HARDNESS_WIDTH); // Set up thumbWt: thumbWt.setLimit(GREATERTHANEQUALS,B_THUMBWT_LOWER_LIMIT,LESSTHANEQUALS, B_THUMBWT_UPPER_LIMIT); thumbWt.SetSize(B_THUMBWT_WIDTH); // Set up fingerWt: fingerWt.setLimit(GREATERTHANEQUALS,B_FINGERWT_LOWER_LIMIT,LESSTHANEQUALS, B_FINGERWT_UPPER_LIMIT); fingerWt.SetSize(B_FINGERWT_WIDTH); // Set up posWt: posWt.setLimit(GREATERTHANEQUALS,B_POSWT_LOWER_LIMIT,LESSTHANEQUALS, B_POSWT_UPPER_LIMIT); posWt.SetSize(B_POSWT_WIDTH); // Set up negWt: negWt.setLimit(GREATERTHANEQUALS,B_NEGWT_LOWER_LIMIT,LESSTHANEQUALS, B_NEGWT_UPPER_LIMIT); negWt.SetSize(B_NEGWT_WIDTH); // Set up topWt: topWt.setLimit(GREATERTHANEQUALS,B_TOPWT_LOWER_LIMIT,LESSTHANEQUALS, B_TOPWT_UPPER_LIMIT); topWt.SetSize(B_TOPWT_WIDTH); // Set up botWt: botWt.setLimit(GREATERTHANEQUALS,B_BOTWT_LOWER_LIMIT,LESSTHANEQUALS, B_BOTWT_UPPER_LIMIT); botWt.SetSize(B_BOTWT_WIDTH); } /******************************************************************************* // FUNCTION NAME: BallRecord // // DESCRIPTION OF FUNCTION: Constructor w/specified Ball Index // // DESCRIPTION OF ALGORITHM: Creates an object of class BallRecord 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, // BALString::SetSize,setChar::setString,LimitFloat::setLimit, // LimitFloat::SetSize // // PARAMETERS: / in / ballIndex - int value of desired index // // PRECONDITIONS: none // // POSTCONDITIONS: A new BallRecord has been created such that the value of // bdex is the specified ballIndex and all other fields contain default values // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ BallRecord::BallRecord(int ballIndex) { // Set up bdex: bdex.setLimit(GREATERTHAN,B_BDEX_LIMIT); bdex.SetSize(B_BDEX_WIDTH); bdex.Store(ballIndex); // Set up co: co.SetSize(B_CO_WIDTH); // Set up model: model.SetSize(B_MODEL_WIDTH); // Set up pds: pds.setLimit(GREATERTHAN,B_PDS_LOWER_LIMIT,LESSTHAN,B_PDS_UPPER_LIMIT); pds.SetSize(B_PDS_WIDTH); // Set up oz: oz.setLimit(GREATERTHAN,B_OZ_LOWER_LIMIT,LESSTHAN,B_OZ_UPPER_LIMIT); oz.SetSize(B_OZ_WIDTH); // Set up rolls: rolls.setLimit(GREATERTHAN,B_ROLLS_LIMIT); rolls.SetSize(B_ROLLS_WIDTH); // Set up trac: trac.setString(B_TRAC_STRING); // Set up surface: surface.setString(B_SURFACE_STRING); // Set up hardness: hardness.setLimit(GREATERTHANEQUALS,B_HARDNESS_LIMIT); hardness.SetSize(B_HARDNESS_WIDTH); // Set up thumbWt: thumbWt.setLimit(GREATERTHANEQUALS,B_THUMBWT_LOWER_LIMIT,LESSTHANEQUALS, B_THUMBWT_UPPER_LIMIT); thumbWt.SetSize(B_THUMBWT_WIDTH); // Set up fingerWt: fingerWt.setLimit(GREATERTHANEQUALS,B_FINGERWT_LOWER_LIMIT,LESSTHANEQUALS, B_FINGERWT_UPPER_LIMIT); fingerWt.SetSize(B_FINGERWT_WIDTH); // Set up posWt: posWt.setLimit(GREATERTHANEQUALS,B_POSWT_LOWER_LIMIT,LESSTHANEQUALS, B_POSWT_UPPER_LIMIT); posWt.SetSize(B_POSWT_WIDTH); // Set up negWt: negWt.setLimit(GREATERTHANEQUALS,B_NEGWT_LOWER_LIMIT,LESSTHANEQUALS, B_NEGWT_UPPER_LIMIT); negWt.SetSize(B_NEGWT_WIDTH); // Set up topWt: topWt.setLimit(GREATERTHANEQUALS,B_TOPWT_LOWER_LIMIT,LESSTHANEQUALS, B_TOPWT_UPPER_LIMIT); topWt.SetSize(B_TOPWT_WIDTH); // Set up botWt: botWt.setLimit(GREATERTHANEQUALS,B_BOTWT_LOWER_LIMIT,LESSTHANEQUALS, B_BOTWT_UPPER_LIMIT); botWt.SetSize(B_BOTWT_WIDTH); }; /*********************************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 indices of the two records // // CALLED BY: client // CALLS: LimitInt::LessThan // // PARAMETERS: / in / another - BallRecord this one is being compared to // // PRECONDITIONS: none // // POSTCONDITIONS: Returns true if the index of this record is less than that // of another record // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ bool BallRecord::LessThan(BallRecord another) { return (bdex.LessThan(another.bdex)); } /******************************************************************************* // 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 indices of the two records against each other. // // CALLED BY: client // CALLS: LimitInt::GreaterThan // // PARAMETERS: / in / another - BallRecord this one is being compared to // // PRECONDITIONS: none // // POSTCONDITIONS: if the 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 BallRecord::GreaterThan(BallRecord another) { return (bdex.GreaterThan(another.bdex)); } /******************************************************************************* // FUNCTION NAME: Equals // // DESCRIPTION OF FUNCTION: Test whether this record has the same 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 - BallRecord 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 BallRecord::Equals(BallRecord another) { return (bdex.Equals(another.bdex)); } /******************************************************************************* // 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, // DateType::isValid // // PARAMETERS: / in / fieldToCheck - BallFieldType 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 BallRecord::fieldOK(BallFieldType 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 case B_BDEX: if (!(bdex.isValid())) error=INDEX_RANGE_ERR; break; case B_PDS: if (!(pds.isValid())) error=RANGE_ERR; break; case B_OZ: if (!(oz.isValid())) error=RANGE_ERR; break; case B_OWN: if (!(own.isValid())) error=DATE_ERR; break; case B_ROLLS: if (!(rolls.isValid())) error=RANGE_ERR; break; case B_TRAC: if (!(trac.isValid())) error=CHAR_ERR; break; case B_SURFACE: if (!(surface.isValid())) error=CHAR_ERR; break; case B_HARDNESS: if (!(hardness.isValid())) error=RANGE_ERR; break; case B_THUMBWT: if (!(thumbWt.isValid())) error=RANGE_ERR; break; case B_FINGERWT: if (!(fingerWt.isValid())) error=RANGE_ERR; break; case B_POSWT: if (!(posWt.isValid())) error=RANGE_ERR; break; case B_NEGWT: if (!(negWt.isValid())) error=RANGE_ERR; break; case B_TOPWT: if (!(topWt.isValid())) error=RANGE_ERR; break; case B_BOTWT: if (!(botWt.isValid())) error=RANGE_ERR; break; } // Since BALStrings can't be invalid, no need to check those fields 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,BALString::Print,setChar::Print,DateType::Print, // LimitFloat::Print // // PARAMETERS: / in / fieldToPrint - BallFieldType 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 BallRecord::FieldContains(BallFieldType fieldToPrint) { string fieldString; // hold the string to report back switch (fieldToPrint) // Call the print function for the appropriate field { case B_BDEX: fieldString = bdex.Print(); break; case B_CO: fieldString = co.Print(); break; case B_MODEL: fieldString = model.Print(); break; case B_PDS: fieldString = pds.Print(); break; case B_OZ: fieldString = oz.Print(); break; case B_OWN: fieldString = own.Print(); break; case B_ROLLS: fieldString = rolls.Print(); break; case B_TRAC: fieldString = trac.Print(); break; case B_SURFACE: fieldString = surface.Print(); break; case B_HARDNESS: fieldString = hardness.Print(); break; case B_THUMBWT: fieldString = thumbWt.Print(); break; case B_FINGERWT: fieldString = fingerWt.Print(); break; case B_POSWT: fieldString = posWt.Print(); break; case B_NEGWT: fieldString = negWt.Print(); break; case B_TOPWT: fieldString = topWt.Print(); break; case B_BOTWT: fieldString = botWt.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,BALString::Default,DateType::Default, // setChar::Default,LimitFloat::Default // // PARAMETERS: / in / fieldToCheck - BallFieldType 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 BallRecord::FieldDefault(BallFieldType fieldToCheck) { string defaultString; switch (fieldToCheck) // Call the Default() function for the appropriate field { case B_BDEX: defaultString = bdex.Default(); break; case B_CO: defaultString = co.Default(); break; case B_MODEL: defaultString = model.Default(); break; case B_PDS: defaultString = pds.Default(); break; case B_OZ: defaultString = oz.Default(); break; case B_OWN: defaultString = own.Default(); break; case B_ROLLS: defaultString = rolls.Default(); break; case B_TRAC: defaultString = trac.Default(); break; case B_SURFACE: defaultString = surface.Default(); break; case B_HARDNESS: defaultString = hardness.Default(); break; case B_THUMBWT: defaultString = thumbWt.Default(); break; case B_FINGERWT: defaultString = fingerWt.Default(); break; case B_POSWT: defaultString = posWt.Default(); break; case B_NEGWT: defaultString = negWt.Default(); break; case B_TOPWT: defaultString = topWt.Default(); break; case B_BOTWT: defaultString = botWt.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 types that have limits or returns the string // literal "No Limits" for the BALString type fields // // CALLED BY: client // CALLS: LimitInt::Limits,DateType::Limits,setChar::Limits,LimitFloat::Limits // // PARAMETERS: / in / fieldToCheck - BallFieldType 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 BallRecord::FieldLimits(BallFieldType fieldToCheck) { string limitString; switch (fieldToCheck) { // These fields have limits: case B_BDEX: limitString = bdex.Limits(); break; case B_PDS: limitString = pds.Limits(); break; case B_OZ: limitString = oz.Limits(); break; case B_OWN: limitString = own.Limits(); break; case B_ROLLS: limitString = rolls.Limits(); break; case B_TRAC: limitString = trac.Limits(); break; case B_SURFACE: limitString = surface.Limits(); break; case B_HARDNESS: limitString = hardness.Limits(); break; case B_THUMBWT: limitString = thumbWt.Limits(); break; case B_FINGERWT: limitString = fingerWt.Limits(); break; case B_POSWT: limitString = posWt.Limits(); break; case B_NEGWT: limitString = negWt.Limits(); break; case B_TOPWT: limitString = topWt.Limits(); break; case B_BOTWT: limitString = botWt.Limits(); break; // Strings don't have any constraints on them case B_CO: case B_MODEL: limitString = "No 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 - BallFieldType 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 BallRecord::FieldLabel(BallFieldType fieldToPrint) { string label; switch (fieldToPrint) { case B_BDEX: label = B_BDEX_LABEL; break; case B_CO: label = B_CO_LABEL; break; case B_MODEL: label = B_MODEL_LABEL; break; case B_PDS: label = B_PDS_LABEL; break; case B_OZ: label = B_OZ_LABEL; break; case B_OWN: label = B_OWN_LABEL; break; case B_ROLLS: label = B_ROLLS_LABEL; break; case B_TRAC: label = B_TRAC_LABEL; break; case B_SURFACE: label = B_SURFACE_LABEL; break; case B_HARDNESS: label = B_HARDNESS_LABEL; break; case B_THUMBWT: label = B_THUMBWT_LABEL; break; case B_FINGERWT: label = B_FINGERWT_LABEL; break; case B_POSWT: label = B_POSWT_LABEL; break; case B_NEGWT: label = B_NEGWT_LABEL; break; case B_TOPWT: label = B_TOPWT_LABEL; break; case B_BOTWT: label = B_BOTWT_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 - BallFieldType 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 BallRecord::FieldWidth(BallFieldType fieldToCheck) { int width=0; switch (fieldToCheck) { case B_BDEX: width = B_BDEX_WIDTH; break; case B_CO: width = B_CO_WIDTH; break; case B_MODEL: width = B_MODEL_WIDTH; break; case B_PDS: width = B_PDS_WIDTH; break; case B_OZ: width = B_OZ_WIDTH; break; case B_ROLLS: width = B_ROLLS_WIDTH; break; case B_HARDNESS: width = B_HARDNESS_WIDTH; break; case B_THUMBWT: width = B_THUMBWT_WIDTH; break; case B_FINGERWT: width = B_FINGERWT_WIDTH; break; case B_POSWT: width = B_POSWT_WIDTH; break; case B_NEGWT: width = B_NEGWT_WIDTH; break; case B_TOPWT: width = B_TOPWT_WIDTH; break; case B_BOTWT: width = B_BOTWT_WIDTH; break; case B_OWN: width = DATE_WDTH; break; case B_TRAC: case B_SURFACE: width = CHAR_WIDTH; break; } return width; } /******************************************************************************* // FUNCTION NAME: IndexIs // // DESCRIPTION OF FUNCTION: Reports the index of the record // // DESCRIPTION OF ALGORITHM: Calls the LimitInt::valueIs function for bdex // // CALLED BY: client // CALLS: LimitInt::valueIs // // PARAMETERS: none // // PRECONDITIONS: none // // POSTCONDITIONS: The current value of the record's index is returned. // // AUTHOR: Amy Langill *2B DATE: 3/23/1999 *******************************************************************************/ int BallRecord::IndexIs() { return bdex.valueIs(); } /********************************TRANSFORMERS**********************************/ /******************************************************************************* // FUNCTION NAME: NewIndex // // DESCRIPTION OF FUNCTION: Changes the index of the record to a new value // // DESCRIPTION OF ALGORITHM: Assigns the newIndexValue to bdex 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 bdex has been changed to newIndexValue // // AUTHOR: Amy Langill *2B DATE: 3/28/1999 *******************************************************************************/ void BallRecord::NewIndex(int newIndexValue) { bdex.Store(newIndexValue); 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,DateType::Store,BALString::Store,setChar::Store, // LimitFloat::Store // // PARAMETERS: / in / dataString - string that contains the value to be stored // in the field // / in / fieldToChange - BallFieldType 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 BallRecord::Update(string dataString,BallFieldType fieldToChange) { istringstream data(dataString); // For converting from string type int newIntValue=INT_MIN; // Hold converted int data char newCharValue; // Hold converted char data float newFloatValue=FLT_MIN; // Hold converted float data switch (fieldToChange) // Store the data based on the field to be changed { case B_BDEX: data >> newIntValue; // Convert to int and store bdex.Store(newIntValue); // into bdex break; case B_PDS: data >> newIntValue; // Convert to int and store pds.Store(newIntValue); // into pds break; case B_OZ: data >> newIntValue; // Convert to int and store oz.Store(newIntValue); // into oz break; case B_ROLLS: data >> newIntValue; // Convert to int and store rolls.Store(newIntValue); // into rolls break; case B_HARDNESS: data >> newIntValue; // Convert to int and store hardness.Store(newIntValue); // into hardness break; case B_THUMBWT: data >> newFloatValue; // Convert to float and store thumbWt.Store(newFloatValue); // into thumbWt break; case B_FINGERWT: data >> newFloatValue; // Convert to float and store fingerWt.Store(newFloatValue); // into fingerWt break; case B_POSWT: data >> newFloatValue; // Convert to float and store posWt.Store(newFloatValue); // into posWt break; case B_NEGWT: data >> newFloatValue; // Convert to float and store negWt.Store(newFloatValue); // into negWt break; case B_TOPWT: data >> newFloatValue; // Convert to float and store topWt.Store(newFloatValue); // into topWt break; case B_BOTWT: data >> newFloatValue; // Convert to float and store botWt.Store(newFloatValue); // into botWt break; case B_TRAC: data >> newCharValue; // Convert to char and store into trac trac.Store(newCharValue); break; case B_SURFACE: data >> newCharValue; // Convert to char and store into surface surface.Store(newCharValue); break; case B_OWN: own.Store(dataString); // No conversion. Store into own break; case B_CO: co.Store(dataString); // No conversion. Store into co break; case B_MODEL: model.Store(dataString); // No conversion. Store into model 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,DateType::Reset,BALString::ResetValue, // setChar::ResetValue,LimitFloat::ResetValue // // PARAMETERS: / in / fieldToChange - BallFieldType 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 BallRecord::Reset(BallFieldType fieldToChange) { switch (fieldToChange) // depending on the field, call the function to change { // that element to its default value case B_BDEX: bdex.ResetValue(); break; case B_CO: co.ResetValue(); break; case B_MODEL: model.ResetValue(); break; case B_PDS: pds.ResetValue(); break; case B_OZ: oz.ResetValue(); break; case B_OWN: own.Reset(); break; case B_ROLLS: rolls.ResetValue(); break; case B_TRAC: trac.ResetValue(); break; case B_SURFACE: surface.ResetValue(); break; case B_HARDNESS: hardness.ResetValue(); break; case B_THUMBWT: thumbWt.ResetValue(); break; case B_FINGERWT: fingerWt.ResetValue(); break; case B_POSWT: posWt.ResetValue(); break; case B_NEGWT: negWt.ResetValue(); break; case B_TOPWT: topWt.ResetValue(); break; case B_BOTWT: botWt.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,BALString::ResetValue,DateType::Reset, // setChar::ResetValue,LimitFloat::ResetValue // // 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 BallRecord::Reset() { // depending on the field, call the function to change // that element to its default value bdex.ResetValue(); co.ResetValue(); model.ResetValue(); pds.ResetValue(); oz.ResetValue(); own.Reset(); rolls.ResetValue(); trac.ResetValue(); surface.ResetValue(); hardness.ResetValue(); thumbWt.ResetValue(); fingerWt.ResetValue(); posWt.ResetValue(); negWt.ResetValue(); topWt.ResetValue(); botWt.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 - BallRecord 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 BallRecord::Replace(BallRecord newRecord) { BallFieldType currFld; for (currFld=B_BDEX;currFld<=B_BOTWT;currFld=BallFieldType(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,BALString::Print,DateType::Print,setChar::Print, // LimitFloat::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 BallRecord::List() { string outputString; // To hold formatted output // print out label, data, spacing character for each field outputString = B_BDEX_LABEL + bdex.Print() + B_FLD_SEPARATOR; outputString += B_CO_LABEL + co.Print() + B_FLD_SEPARATOR; outputString += B_MODEL_LABEL + model.Print() + B_FLD_SEPARATOR; outputString += B_PDS_LABEL + pds.Print() + B_FLD_SEPARATOR; outputString += B_OZ_LABEL + oz.Print() + '\n'; // Screen is only 80 characters wide, so we start another line outputString += B_OWN_LABEL + own.Print()+ B_FLD_SEPARATOR; outputString += B_ROLLS_LABEL + rolls.Print() + B_FLD_SEPARATOR; outputString += B_TRAC_LABEL + trac.Print() + B_FLD_SEPARATOR; outputString += B_SURFACE_LABEL + surface.Print() + B_FLD_SEPARATOR; outputString += B_HARDNESS_LABEL + hardness.Print() + B_FLD_SEPARATOR; outputString += B_THUMBWT_LABEL + thumbWt.Print() + '\n'; // Need a third line to hold the rest: outputString += B_FINGERWT_LABEL + fingerWt.Print() + B_FLD_SEPARATOR; outputString += B_POSWT_LABEL + posWt.Print() + B_FLD_SEPARATOR; outputString += B_NEGWT_LABEL + negWt.Print() + B_FLD_SEPARATOR; outputString += B_TOPWT_LABEL + topWt.Print() + B_FLD_SEPARATOR; outputString += B_BOTWT_LABEL + botWt.Print() + B_FLD_SEPARATOR; return outputString; // send back the screen-formatted output } /******************************************************************************* // FUNCTION NAME: BriefList // // DESCRIPTION OF FUNCTION: Generate a string that holds abbreviated record // information formatted for screen // // DESCRIPTION OF ALGORITHM: Creates a string that holds field labels and // contents as created by the Print member function of each field's type for // some fields in the record, delimited with spaces between the fields. // // CALLED BY: client // CALLS: LimitInt::Print,BALString::Print,setChar::Print // // PARAMETERS: none // // PRECONDITIONS: none // // POSTCONDITIONS: A string has been created which contains an abbreviated // version of the current data stored in the record formatted for viewing // // AUTHOR: Amy Langill *2B DATE: 3/29/1999 *******************************************************************************/ string BallRecord::BriefList() { string outputString; // To hold formatted output // This stuff fits on one line of the screen: outputString = bdex.Print() + B_FLD_SEPARATOR; outputString += B_CO_LABEL + co.Print() + B_FLD_SEPARATOR; outputString += B_MODEL_LABEL + model.Print() + B_FLD_SEPARATOR; outputString += B_PDS_LABEL + pds.Print() + B_FLD_SEPARATOR; outputString += B_OZ_LABEL + oz.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,BALString::Print,DateType::Print,setChar::Print, // LimitFloat::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 BallRecord::Print() { string outputString; // To hold formatted output // for each field, printout label, data, space outputString = B_BDEX_LABEL + bdex.Print() + B_FLD_SEPARATOR; outputString += B_CO_LABEL + co.Print() + B_FLD_SEPARATOR; outputString += B_MODEL_LABEL + model.Print() + B_FLD_SEPARATOR; outputString += B_PDS_LABEL + pds.Print() + B_FLD_SEPARATOR; outputString += B_OZ_LABEL + oz.Print() + B_FLD_SEPARATOR; outputString += B_OWN_LABEL + own.Print() + B_FLD_SEPARATOR; outputString += B_ROLLS_LABEL + rolls.Print() + '\n'; // Second line of record outputString += B_TRAC_LABEL + trac.Print() + B_FLD_SEPARATOR; outputString += B_SURFACE_LABEL + surface.Print() + B_FLD_SEPARATOR; outputString += B_HARDNESS_LABEL + hardness.Print() + B_FLD_SEPARATOR; outputString += B_THUMBWT_LABEL + thumbWt.Print() + B_FLD_SEPARATOR; outputString += B_FINGERWT_LABEL + fingerWt.Print() + B_FLD_SEPARATOR; outputString += B_POSWT_LABEL + posWt.Print() + B_FLD_SEPARATOR; outputString += B_NEGWT_LABEL + negWt.Print() + B_FLD_SEPARATOR; outputString += B_TOPWT_LABEL + topWt.Print() + B_FLD_SEPARATOR; outputString += B_BOTWT_LABEL + botWt.Print(); return outputString; // send back the report-formatted output }