/* * Copyright (c) 2002 by Cliff Green. All rights reserved. Individual files * may be covered by other copyrights (as noted in the file itself). * * Redistribution and use in source and binary forms are permitted * provided that this entire copyright notice is duplicated in all such * copies. * * This software is provided "as is" and without any expressed or implied * warranties, including, without limitation, the implied warranties of * merchantibility and fitness for any particular purpose. */ //---------------------------------------------------------------------- // Source file: word.h // Written by: Cliff Green, 2002 // Compiler: Metrowerks CodeWarrior Pro 6, g++ 3.0.4 // History: // Modified: Mar. 5, 2002 // By: Cliff Green // Comments: Word class and string utility declarations. //---------------------------------------------------------------------- // This commentheader supports documentation tools such as Doc++ and // Doxygen: http://www.doxygen.org/ //---------------------------------------------------------------------- /// Word class declaration, uses soundex.h functionality. /** * This class shows lots of design tradeoff decisions - pre-computing * as an optimization, space vs time, time vs complexity, etc. * * Pre-condition for Word constructor - parameter is a valid pointer to * a nul-char terminated C string (array of characters). * * Pre-condition for strlen_alpha - same as Word ctor. * * Pre-conditions for strcpy_alpha - source is valid pointer to * a nul-char terminated C string, dest has enough space to hold * copied chars (plus nul-char at end). * */ #ifndef WORD_H #define WORD_H extern "C" { // to get MAXSDX #include "soundex.h" } #include #include // for WordVec typedefs #include // may not work for VC++ 5 / 6 class Word { public: Word (char const* initString = ""); // regular and default ctor ~Word () { delete [] mWordPtr; } // dtor Word (Word const& rhs) : mLength(0), mWordPtr(0) { initWord (rhs.mLength, rhs.mWordPtr); } // copy ctor Word& operator= (Word const& ); // copy assign op bool isEqual (Word const&) const; bool operator== (Word const& rhs) const { return isEqual (rhs); } int compare (Word const& rhs) const { return std::strcmp(mWordPtr, rhs.mWordPtr); } bool isSoundexSame (Word const& rhs) const { return std::strcmp(mSoundexValue, rhs.mSoundexValue) == 0; } int getLength () const { return mLength; } char const* getSoundexValue () const { return mSoundexValue; } void debugPrint () const; bool operator< (Word const& rhs) const { return compare(rhs) < 0; } std::ostream& streamOut (std::ostream& ) const; private: int mLength; char* mWordPtr; char mSoundexValue[MAXSDX+1]; void initWord (int, char const* ); }; // prototype for Word output function std::ostream& operator<< (std::ostream&, Word const&); // convenience typedef's typedef std::vector WordVec; typedef WordVec::size_type WordVecSizeType; // prototypes for C string utilities int strlen_alpha (char const* str); char* strcpy_alpha (char* dest, char const* source); #endif // end of header file