home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / GENMAN.ZIP / STRLOC.H < prev    next >
C/C++ Source or Header  |  1993-03-13  |  2KB  |  90 lines

  1. //------------------------------------------------------------
  2. //
  3. //            strloc.h
  4. //
  5. // Purpose:
  6. //    Defines the strloc class.
  7.  
  8. // .NAME strloc - class to manage strings
  9. // .LIBRARY Base
  10. // .HEADER base utilities
  11. // .INCLUDE base/strloc.h
  12. // .FILE strloc.cxx
  13. // .FILE strloc.h
  14.  
  15. #ifndef UTIL_STRLOC_H
  16. #define UTIL_STRLOC_H
  17.  
  18. #ifndef STRINGS_HXX
  19. #include <strings.hxx>
  20. #endif
  21.  
  22. struct strloc_data {
  23.     char *std_ptr;      // pointer to string
  24.     int   std_refcnt;   // reference count
  25. };
  26.  
  27. class strloc
  28.     {
  29. private:
  30.     strloc_data *st_com;
  31.     // Pointer to character string struct.
  32.  
  33. public:
  34.     strloc( const char *str= 0 );
  35.     strloc( strloc & );
  36.     ~strloc();
  37.     strloc & operator=( strloc & );
  38.     strloc & operator=( const char * );
  39.     void operator+=( const char * );
  40.     const char *ptr();
  41.     int len();
  42.     friend int operator==( const strloc &x, const char *s );
  43.     friend int operator==( const char *s, const strloc &x );
  44.     friend int operator==( const strloc &x, const strloc &y );
  45.     friend int operator!=( const strloc &x, const char *s );
  46.     friend int operator!=( const char *s, const strloc &x );
  47.     friend int operator!=( const strloc &x, const strloc &y );
  48.     };
  49.  
  50. // .SECTION Description
  51. // The strloc class is a class for managing strings.
  52. // It uses reference counts on copy operations.
  53.  
  54. // .SECTION See Also
  55. // strings(3)
  56.  
  57. // Description:
  58. //  Returns the pointer to the string.
  59. inline const char *strloc::ptr()
  60.     { return st_com->std_ptr; }
  61.  
  62. // Description:
  63. //  Returns the length of the string.
  64. inline int strloc::len()
  65.     { return strlen( st_com->std_ptr ); }
  66.  
  67. inline int operator==( const strloc &x, const char *s )
  68.     { return strcmp( x.st_com->std_ptr, s ) == 0; }
  69.  
  70. inline int operator==( const char *s, const strloc &x )
  71.     { return strcmp( x.st_com->std_ptr, s ) == 0; }
  72.  
  73. // Description:
  74. // Returns 1 if the two strings are equal, 0 if not.
  75. inline int operator==( const strloc &x, const strloc &y )
  76.     { return strcmp( x.st_com->std_ptr, y.st_com->std_ptr ) == 0; }
  77.  
  78. inline int operator!=( const strloc &x, const char *s )
  79.     { return strcmp( x.st_com->std_ptr, s ) != 0; }
  80.  
  81. inline int operator!=( const char *s, const strloc &x )
  82.     { return strcmp( x.st_com->std_ptr, s ) != 0; }
  83.  
  84. // Description:
  85. // Returns 1 if the two strings are not equal, 0 if equal.
  86. inline int operator!=( const strloc &x, const strloc &y )
  87.     { return strcmp( x.st_com->std_ptr, y.st_com->std_ptr ) != 0; }
  88.  
  89. #endif /* UTIL_STRLOC_H */
  90.