home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume10 / genman.awk / strloc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-16  |  2.1 KB  |  81 lines

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