home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 8.img / CLASSINC.ZIP / STRNG.H < prev   
Encoding:
C/C++ Source or Header  |  1990-05-04  |  4.8 KB  |  220 lines

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