#ifndef BALLRECORD_H #define BALLRECORD_H // ballrecord.h Interface file for the 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 // for strings & string operations #include // for stringstreams #include // for INT_MIN,INT_MAX #include "balint.h" // for LimitInt #include "balstring.h" // for BALString #include "baldate.h" // for DateType #include "balchar.h" // for setChar #include "balfloat.h" // for LimitFloat #include "errortype.h" // for error reporting using namespace std; typedef enum { B_BDEX, // Ball index B_CO, // Company B_MODEL, // Model name B_PDS, // Pounds B_OZ, // Ounces B_OWN, // Purchase date B_ROLLS, // # of games rolled with ball B_TRAC, // Track code B_SURFACE, // Composition B_HARDNESS, // Density B_THUMBWT, // Weight B_FINGERWT, // " B_POSWT, // " B_NEGWT, // " B_TOPWT, // " B_BOTWT // " } BallFieldType; const int B_BDEX_WIDTH=5; // store the field widths as named constants const int B_CO_WIDTH=20; // const int B_MODEL_WIDTH=20; // const int B_PDS_WIDTH=2; // const int B_OZ_WIDTH=2; // const int B_ROLLS_WIDTH=5; // const int B_HARDNESS_WIDTH=2; // const int B_THUMBWT_WIDTH=5; // const int B_FINGERWT_WIDTH=5; // const int B_POSWT_WIDTH=5; // const int B_NEGWT_WIDTH=5; // const int B_TOPWT_WIDTH=5; // const int B_BOTWT_WIDTH=5; // const int B_BDEX_LIMIT=-1; // store field constraints as named const int B_PDS_LOWER_LIMIT=0; // constants const int B_PDS_UPPER_LIMIT=16; // const int B_OZ_LOWER_LIMIT=-1; // const int B_OZ_UPPER_LIMIT=16; // const int B_ROLLS_LIMIT=-1; // const int B_HARDNESS_LIMIT=72; // const string B_TRAC_STRING="FHLSO"; // const string B_SURFACE_STRING="HLPRUO"; // const float B_THUMBWT_LOWER_LIMIT=0; // const float B_THUMBWT_UPPER_LIMIT=1.0; // const float B_FINGERWT_LOWER_LIMIT=0; // const float B_FINGERWT_UPPER_LIMIT=1.0; // const float B_POSWT_LOWER_LIMIT=0; // const float B_POSWT_UPPER_LIMIT=1.0; // const float B_NEGWT_LOWER_LIMIT=0; // const float B_NEGWT_UPPER_LIMIT=1.0; // const float B_TOPWT_LOWER_LIMIT=0; // const float B_TOPWT_UPPER_LIMIT=3.0; // const float B_BOTWT_LOWER_LIMIT=0; // const float B_BOTWT_UPPER_LIMIT=3.0; // const string B_BDEX_LABEL="Bdex: "; // store the field labels as named const string B_CO_LABEL="Co: "; // constants for future reference const string B_MODEL_LABEL="Model: "; // const string B_PDS_LABEL="Pds: "; // const string B_OZ_LABEL="Oz: "; // const string B_OWN_LABEL="Own: "; // const string B_ROLLS_LABEL="Rolls: "; // const string B_TRAC_LABEL="Trac: "; // const string B_SURFACE_LABEL="Surface: "; // const string B_HARDNESS_LABEL="Hardness: "; // const string B_THUMBWT_LABEL="ThumbWt: "; // const string B_FINGERWT_LABEL="FingerWt: "; // const string B_POSWT_LABEL="PosWt: "; // const string B_NEGWT_LABEL="NegWt: "; // const string B_TOPWT_LABEL="TopWt: "; // const string B_BOTWT_LABEL="BotWt: "; // const char B_FLD_SEPARATOR=' '; // for formatting record output class BallRecord { public: // Constructors BallRecord(); // parameterless BallRecord(int ballIndex); // w/specified Ball Index // Observers bool LessThan(BallRecord another); // Is this record < another? bool GreaterThan(BallRecord another); // Is this record > another? bool Equals(BallRecord another); // Is this record == another? DataErrorType fieldOK(BallFieldType fieldToCheck); // Is the field valid? string FieldContains(BallFieldType fieldToPrint); // What's stored in the // field? string FieldDefault(BallFieldType fieldToCheck); // Find the default of a // particular field string FieldLimits(BallFieldType fieldToCheck); // Find the limits on a // particular field string FieldLabel(BallFieldType fieldToPrint); // Print the field's label int FieldWidth(BallFieldType fieldToCheck); // Report on field's width int IndexIs(); // What is the index of this record? // Transformers void NewIndex(int newIndexValue); // Change the index of the record void Update(string dataString, // Change a field in the record BallFieldType fieldToChange); // to a different value void Reset(BallFieldType fieldToChange); // Reset a field to its default void Reset(); // Reset all fields to their defaults void Replace(BallRecord newRecord); // Replace all fields with those in // another record // Iterators string List(); // Produce a string w/the record data formatted for the screen string Print(); // Produce a string w/the record data formatted for a report string BriefList(); // Produce a string w/abbreviated record data private: LimitInt bdex; BALString co; BALString model; LimitInt pds; LimitInt oz; DateType own; LimitInt rolls; setChar trac; setChar surface; LimitInt hardness; LimitFloat thumbWt; LimitFloat fingerWt; LimitFloat posWt; LimitFloat negWt; LimitFloat topWt; LimitFloat botWt; }; #endif