home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 1.ddi / CLASSINC.ZIP / STRNG.H < prev   
Encoding:
C/C++ Source or Header  |  1991-02-13  |  4.6 KB  |  211 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. // Contents ----------------------------------------------------------------
  4. //
  5. //      String      
  6. //      String::isEqual
  7. //      String::isLessThan
  8. //      String::printOn
  9. //      String::operator char*
  10. //
  11. // Description
  12. //
  13. //      Defines the instance class String and inline member functions.
  14. //
  15. // End ---------------------------------------------------------------------
  16.  
  17. // Interface Dependencies ---------------------------------------------------
  18.  
  19. #ifndef _STRNG_H
  20. #define _STRNG_H
  21.  
  22. #ifndef __IOSTREAM_H
  23. #include <iostream.h>
  24. #define __IOSTREAM_H
  25. #endif
  26.  
  27. #ifndef __STRING_H
  28. #include <string.h>
  29. #define __STRING_H
  30. #endif
  31.  
  32. #ifndef __CLSTYPES_H
  33. #include <clstypes.h>
  34. #endif
  35.  
  36. #ifndef __OBJECT_H
  37. #include <object.h>
  38. #endif
  39.  
  40. #ifndef __SORTABLE_H
  41. #include <sortable.h>
  42. #endif
  43.  
  44. // End Interface Dependencies ------------------------------------------------
  45.  
  46. // Class //
  47.  
  48. class String:  public Sortable
  49. {
  50. public:
  51.             String( const char * );
  52.             String( const String& );
  53.     virtual ~String();
  54.  
  55.     virtual int             isEqual( const Object& ) const;
  56.     virtual int             isLessThan( const Object& ) const;
  57.  
  58.     virtual classType       isA() const;
  59.     virtual char            *nameOf() const;
  60.     virtual hashValueType   hashValue() const;
  61.     virtual void            printOn( ostream& ) const;
  62.  
  63.             String&         operator =( const String& );
  64.                             operator const char *() const;
  65. private:
  66.             sizeType        len;
  67.             char           *theString;
  68. };
  69.  
  70. // Description -------------------------------------------------------------
  71. //
  72. //         Defines the instance class String.  String objects may be used
  73. //      anywhere an instance object is called for.  A string object 
  74. //      is always terminated by a null.
  75. //
  76. // Constructor
  77. //
  78. //      String
  79. //
  80. //      Constructs a String object from a given character string.
  81. //
  82. // Destructor
  83. //
  84. //      ~String
  85. //
  86. //      String destructor.
  87. //
  88. // Public Members
  89. //
  90. //         isEqual
  91. //
  92. //         Returns 1 if two strings are equivalent, 0 otherwise.
  93. //         Determines equivalence by calling strcmp().
  94. //
  95. //         isLessThan
  96. //
  97. //         Returns 1 if this is less than a test String.
  98. //
  99. //         isA
  100. //
  101. //         Returns the class type of class String.
  102. //
  103. //         nameOf
  104. //
  105. //         Returns a pointer to the character string "String."
  106. //
  107. //         hashValue
  108. //
  109. //         Returns the hash value of a string object.
  110. //
  111. //         printOn
  112. //
  113. //         Prints the contents of the string.
  114. //
  115. //         operator char*
  116. //
  117. //         Character pointer conversion operator.
  118. //
  119. //         operator =
  120. //
  121. //         Assignment operator for two string objects.
  122. //
  123. // Inherited Members
  124. //
  125. //      operator new
  126. //
  127. //      Inherited from Object.
  128. //
  129. //      forEach
  130. //
  131. //      Inherited from Object.
  132. //
  133. //      firstThat
  134. //
  135. //      Inherited from Object.
  136. //
  137. //      lastThat
  138. //
  139. //      Inherited from Object.
  140. //
  141. //         isSortable
  142. //
  143. //         Inherited from Sortable.
  144. //
  145. //         isAssociation
  146. //
  147. //         Inherited from Object.
  148. //
  149. // End ---------------------------------------------------------------------
  150.  
  151.  
  152. // Constructor //
  153.  
  154. inline String::String( const char *aPtr )
  155.  
  156. // Summary -----------------------------------------------------------------
  157. //
  158. //      Constructor for a string object.
  159. //
  160. // Parameters
  161. //
  162. //      aPtr
  163. //
  164. //      Pointer to the characters out of which we are to construct a 
  165. //      String object.
  166. //
  167. // Functional Description
  168. //
  169. //      We assign the string's length to len, then allocate space into
  170. //      which we will store the string's characters.  You may construct
  171. //      String objects out of local character strings.
  172. //
  173. // End ---------------------------------------------------------------------
  174. {
  175.     if ( aPtr && *aPtr )
  176.     {
  177.         len = strlen( aPtr ) + 1;
  178.         theString = new char[ len ];
  179.         (void)strcpy( theString, aPtr );
  180.     }
  181.     else  // make a null string String object.
  182.     {
  183.         len = 0;
  184.         theString = 0;
  185.     }
  186. }
  187. // End Constructor //
  188.  
  189.  
  190. // Member Function //
  191.  
  192. inline String::operator const char *() const
  193.  
  194. // Summary -----------------------------------------------------------------
  195. //
  196. //      Converts a string object to a character pointer.
  197. //
  198. // Remarks
  199. //
  200. // warnings:
  201. //         You may not modifiy the returned string.
  202. //
  203. // End ---------------------------------------------------------------------
  204. {
  205.     return theString;
  206. }
  207. // End Member Function String::operator char* //
  208.  
  209.  
  210. #endif // ifndef _STRNG_H //
  211.