home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / bbxxsamk / xseq2.h__ / XSEQ2.H
Encoding:
C/C++ Source or Header  |  1992-10-26  |  3.5 KB  |  75 lines

  1. /* Copyright (c) IBM Corp. 1992 */
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5.  
  6.  
  7.  
  8. /*-------------------------- Demonstration class ---------------------------*\ 
  9. *                                                                            *
  10. | Class Word;                                                                |
  11. |                                                                            |
  12. | This class contains pointers to strings (words).                           |
  13. | Only the pointers are kept in the instance variable.                       |
  14. |                                                                            |
  15. | Instances can return the theWord pointer.                                  |
  16. |                                                                            |
  17. | Instances can be compared to each other. They have to be able to be        |
  18. | because the list might want to sort the elements.                          |
  19. *                                                                            *
  20. \*--------------------------------------------------------------------------*/
  21.  
  22. class Word
  23. {
  24.    private:
  25.       char    *theWord;                   // Our own copy of the word
  26.    public:
  27.       /*--------------------------------------------------------------------*\
  28.       *        Constructors/destructors                                      *
  29.       \*--------------------------------------------------------------------*/
  30.                Word() {                   // Constructor
  31.                   theWord = 0;
  32.                   }
  33.                Word(Word const & word) {  // copy Constructor
  34.                   theWord = word.theWord;
  35.                   }
  36.                Word(char *aString) {
  37.                   theWord = aString;
  38.                   }
  39.               ~Word() {                   // Destructor
  40.                   }
  41.  
  42.       /*--------------------------------------------------------------------*\
  43.       *        Member functions                                              *
  44.       \*--------------------------------------------------------------------*/
  45.       char *   getElement() const {
  46.                   return theWord;
  47.                   }
  48.       void     fill(char *aString) {      // Modify contents
  49.                   theWord = aString;      // Point to new string
  50.                   }
  51.  
  52.       /*--------------------------------------------------------------------*\
  53.       *        (In-)Equality operators overloading                           *
  54.       \*--------------------------------------------------------------------*/
  55.       int      operator == (Word const &anOther) const {
  56.                   return (strcmp(theWord,anOther.theWord) == 0);
  57.                   }
  58.       int      operator != (Word const &anOther) const {
  59.                   return !(*this == anOther);
  60.                   }
  61.       /*--------------------------------------------------------------------*\
  62.       *        Ordering operators overloading                                *
  63.       \*--------------------------------------------------------------------*/
  64.       int      operator <  (Word const &anOther) const {
  65.                   return (strcmp(theWord,anOther.theWord) <  0);
  66.                   }
  67.       int      operator >  (Word const &anOther) const {
  68.                   return (strcmp(theWord,anOther.theWord) >  0);
  69.                   }
  70.       int      operator <= (Word const &anOther) const { return !(*this >  anOther); }
  71.       int      operator >= (Word const &anOther) const { return !(*this <  anOther); }
  72.  
  73. };
  74.  
  75.