/* StrType.h */ #ifndef STR_TYPE #define STR_TYPE const int MAX_BUFF = 16; /* max increment for letters */ /* InType used for telling us what type of input characters will be accepted */ enum InType {ALPHA_NUM, ALPHA, NON_WHITE, NOT_NEW}; /* The StrType class */ class StrType { public: /*********************************************************************** * StrType() -- Default constructor used to initialize letters (empty) * * * * Parameters * * void * * Returns * * void * * Precondition * * NONE * * Postcondition * * Current position is prior to list. * ***********************************************************************/ StrType(); /*********************************************************************** * ~StrType() -- Default destructor used to clean up letters * * * * Parameters * * void * * Returns * * void * * Precondition * * NONE * * Postcondition * * dynamic string is removed from heap * ***********************************************************************/ ~StrType(); /*********************************************************************** * StrType() -- copy constructor used to deep copy * * * * Parameters * * the original StrType * * Returns * * NONE * * Precondition * * NONE * * Postcondition * * a deep copy of performed * ***********************************************************************/ StrType(const StrType &anotherStrType); /*********************************************************************** * MakeEmpty() -- used to empty letters and clean up heap * * * * Parameters * * void * * Returns * * void * * Precondition * * NONE * * Postcondition * * Current position is prior to list. * ***********************************************************************/ void MakeEmpty(); /*********************************************************************** * Grow() -- Grow the letters array * * * * Parameters * * void * * Returns * * bool - if the new malloc was a success * * Precondition * * NONE * * Postcondition * * letters is now larger * ***********************************************************************/ bool Grow(); /*********************************************************************** * Element() -- get the element of array at num location * * * * Parameters * * int -- the number of the array to return * * Returns * * char -- the element in that part of array * * Precondition * * NONE * * Postcondition * * the element in num location is returned * ***********************************************************************/ char Element(int num); /*********************************************************************** * SetString() -- used to copy carray into letters array * * * * Parameters * * char carray[] -- takes a character array as input * * Returns * * void * * Precondition * * NONE * * Postcondition * * letters will equal carray * ***********************************************************************/ void SetString(char []); /*********************************************************************** * GetString() -- used to get the input string * * * * Parameters * * bool skip -- read note above for true and false operations * * InType charsAllowed -- what sorts of characters we will take * * Returns * * void * * Precondition * * NONE * * Postcondition * * Letters will contain a characters * ***********************************************************************/ void GetString(const bool skip, InType charsAllowed); /*********************************************************************** * GetStringFile() -- used to read in from input file * * * * Parameters * * bool skip -- read note above for true and false operations * * InType charsAllowed -- what sorts of characters we will take * * ifstream inFile -- file handle for reading * * Returns * * void * * Precondition * * inFile exists * * Postcondition * * Letters will contain a characters * ***********************************************************************/ void GetStringFile(bool skip, InType charsAllowed, ifstream &inFile); /*********************************************************************** * CopyString() -- This will copy the contents of letters into a * * StrType that is pass by reference. * * * * Parameters * * StrType newString -- copies letters into newString.letters * * Returns * * void -- remember it is pass by reference * * Precondition * * you will want something in letters * * Postcondition * * newString will contain the same thing as letters. * ***********************************************************************/ void CopyString(StrType &newString); /*********************************************************************** * PrintToScreen() -- this will print contents letters * * * * Parameters * * bool newLine -- if true we print a newline first else opposite * * Returns * * void * * Precondition * * You will want something in letters * * Postcondition * * letters will be printed to screen. * ***********************************************************************/ void PrintToScreen(const bool newLine) const; /*********************************************************************** * PrintToFile() -- This will print the contents of letters to outFile * * * * Parameters * * bool newLine -- if true we print a newline first else opposite * * ofstream outFile -- file handle to print letters into * * Returns * * void * * Precondition * * You will want something in letters * * Postcondition * * letters will be printed to outFile * ***********************************************************************/ void PrintToFile(const bool newLine, ofstream &outFile) const; /*********************************************************************** * EqualtoCharArray() -- if input string is the same as letters * * * * Parameters * * char carray[] -- character array to compare with letters * * Returns * * bool -- returns true of equal false if !equal * * Precondition * * letters should be assigned a value * * Postcondition * * a true or false will be returned * ***********************************************************************/ bool EqualtoCharArray(char []); /*********************************************************************** * Tok() -- this is a string tokenizer similar to strtok() * * * * Parameters * * char[] -- token to use * * Returns * * char* -- pointer to the next substring pointed to * * Precondition * * something should be in letters * * Postcondition * * returns a substring * ***********************************************************************/ char* Tok(char token[]); /*********************************************************************** * LengthIs() -- figure out the length of letters * * * * Parameters * * void * * Returns * * int -- returns the numeric length of letters like strlen() * * Precondition * * something should be in letters * * Postcondition * * returns the numeric length of letters * ***********************************************************************/ int LengthIs(); /*********************************************************************** * SizeOf() -- return the max size of array * * * * Parameters * * void * * Returns * * int -- returns the numeric size of letters like sizeof() * * Precondition * * none * * Postcondition * * returns the numeric size of letters * ***********************************************************************/ int SizeOf(); /*********************************************************************** * operator<() -- if letters is less then otherString * * * * Parameters * * StrType otherString -- the passed string object * * Returns * * bool -- returns true if less then otherString else false * * Precondition * * you will want something in letters * * Postcondition * * returns true if less then otherString else false * ***********************************************************************/ bool operator<(StrType otherString); /*********************************************************************** * operator==() -- if letters is equal to otherString * * * * Parameters * * StrType otherString -- the passed string object * * Returns * * bool -- returns true if equal to otherString else false * * Precondition * * You will want something in letters * * Postcondition * * returns true if equal to otherString else false * ***********************************************************************/ bool operator==(StrType otherString); /*********************************************************************** * operator=() -- copies otherString into letters * * * * Parameters * * StrType otherString -- the passed string object * * Returns * * void -- remember letters will now equal otherString * * Precondition * * NONE * * Postcondition * * letters will contain otherString after assignment * ***********************************************************************/ void operator=(StrType otherString); /*********************************************************************** * operator=() -- copies carray into letters * * * * Parameters * * char[] -- the char array to copy into letters * * Returns * * void -- remember letters will now equal otherString * * Precondition * * NONE * * Postcondition * * letters will contain carray after assignment * ***********************************************************************/ void operator=(char carray[]); /*********************************************************************** * GetAlphaNum() -- take in input if it's an alpha or numeric char * * * * Parameters * * bool skip -- read note above for true and false operations * * Returns * * void * * Precondition * * NONE * * Postcondition * * Letters contains only alphabetic characters and numbers. * ***********************************************************************/ void GetAlphaNum(bool skip); /*********************************************************************** * GetTilNew() -- get everything up to the newline char * * * * Parameters * * bool skip -- read note above for true and false operations * * Returns * * void * * Precondition * * NONE * * Postcondition * * letters contains everything up to the newline character. * ***********************************************************************/ void GetTilNew(bool skip); /*********************************************************************** * GetAlphaNumFile() -- get alphanum characters from the file * * * * Parameters * * bool skip -- read note on skip above * * ifstream inFile -- infilestream inFile * * Returns * * void * * Precondition * * inFile exists * * Postcondition * * Letters contains only alphabetic characters and numbers. * ***********************************************************************/ void GetAlphaNumFile(bool skip, ifstream &inFile); /*********************************************************************** * GetTilNewFile() -- get until newline from the file * * * * Parameters * * bool skip -- read note on skip above * * ifstream inFile -- infilestream inFile * * Returns * * void * * Precondition * * inFile exists * * Postcondition * * Letters contains everything up to the newline character. * ***********************************************************************/ void GetTilNewFile(bool skip, ifstream &inFile); /* NOT IMPLEMENTED YET void GetAlpha(bool skip); // Post: letters array contains only alphabetic characters. void GetNonWhite(bool skip); // Post: letters array contains only non-white space characters. void GetAlphaFile(bool skip, ifstream& inFile); // Post: letters array contains only alphabetic characters. void GetNonWhiteFile(bool skip, ifstream& inFile); // Post: letters array contains only non-white space characters. */ private: char *letters; /* our letters array */ long unsigned int buffSize; /* size of the letters buffer */ bool tok; /* do we have a token or not */ }; #endif