home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / WORDSEQ / TOYWORD.H < prev    next >
Text File  |  1995-03-15  |  2KB  |  61 lines

  1. /*************************************************************************
  2.   IBM C/C++ Tools Version 3.00 - Collection Class Library
  3.  (C) Copyright IBM Corporation 1992 ,1995, Licensed Program-Property of
  4.  IBM.  All Rights Reserved.  US Government Users Restricted Rights - Use,
  5.  duplication or disclosure restricted by GSA ADP Schedule Contract with
  6.  IBM Corp.
  7.  *************************************************************************/
  8.  
  9. /*-------------------------------------------------------------*\
  10. |  toyword.h  -  Class Word for use with coding examples.       |
  11. \*-------------------------------------------------------------*/
  12.  
  13. #if defined (_SUN)
  14. #include <istring.h>
  15. #else
  16. #include <istring.hpp>
  17. #endif
  18.  
  19. class Word  {
  20.  
  21.         IString       ivWord;
  22.         unsigned      ivKey;
  23.  
  24. public:
  25.  
  26.   //Constructor to be used for sample: wordbag.c
  27.   Word (IString word, unsigned theLength) : ivWord(word),
  28.                                             ivKey(theLength)
  29.                                             {}
  30.  
  31.   //Constructor to be used for sample: wordseq.c
  32.   Word (IString word) : ivWord(word)
  33.                         {}
  34.  
  35.   IBoolean operator> (Word const& w1)
  36.            {
  37.             return this->ivWord > w1.ivWord;
  38.            }
  39.  
  40.   unsigned setKey()
  41.             {
  42.              this->ivKey = this->ivWord.length();
  43.              return this->ivKey;
  44.             }
  45.  
  46.   IString const& getWord() const
  47.             {
  48.              return this->ivWord;
  49.             }
  50.  
  51.   unsigned const& getKey() const
  52.             {
  53.              return this->ivKey;
  54.             }
  55. };
  56.  
  57.        // Key access.  The length of the word is the key.
  58. inline unsigned const& key (Word const &aWord)
  59. { return aWord.getKey();
  60. }
  61.