home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c017 / 2.ddi / GCSTRING.ZIP / GCSTRING.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-25  |  3.0 KB  |  106 lines

  1. /**************************************************************************
  2. These C++ classes are copyright 1989, 1990, 1991 by William Herrera.
  3. I hereby release this source code for free distrubution and use.
  4. If you modify it and distribute it, please indicate any changes you
  5. make as your own and the code as copyrighted above.
  6. **************************************************************************/
  7.  
  8. // file gcstring.hpp
  9. // this class demonstrates the use of the gcobject and PointerHeap classes
  10. // to implement a fast executing string class.
  11.  
  12. #if !defined(GCSTRING_HPP)
  13. #define GCSTRING_HPP
  14.  
  15. #include <fstream.h>
  16.  
  17. #include "gcobject.hpp"
  18. #include "pointerh.hpp"
  19.  
  20.  
  21. class gcstring
  22. {
  23. public:
  24.     // intialize buffer.
  25.     static void Initialize(unsigned int bufsize=10000, 
  26.         int maxstrings = 4000, int gc_interval=10000);
  27.  
  28.      // constructors
  29.     gcstring();    // gcstring s; default constructor
  30.     gcstring(const char *);    // gcstring s("Hello");
  31.     gcstring(const gcstring &);      // copy-initializer
  32.     gcstring(const char * p1, const char * p2);
  33.  
  34.      // destructor
  35.     ~gcstring();
  36.  
  37.     // assignment
  38.     gcstring & operator =(const gcstring &); // gcstring s = gcstring st;
  39.     gcstring & operator =(const char *); // gcstring s = char * s;
  40.  
  41.     // reference a char (can potentially be an lvalue and modify string!)
  42.     const char & operator [](const int i); // reference a char in string.
  43.  
  44.     // functions and operators ...
  45.     int length();                            // length of string
  46.     gcstring operator +(const gcstring & st);   // concatenate strings
  47.  
  48.     // this returns a raw pointer to internal representation.
  49.     // the only protection is that it's const.
  50.     operator const char * () const;
  51.  
  52.     int operator ==(const gcstring & s) const;
  53.     int operator !=(const gcstring & s) const;
  54.     int compare(const gcstring & s) const;
  55.     int compare(const char * p) const;
  56.  
  57.     gcstring uppercase();    // return string changed to uppercase
  58.     gcstring lowercase();    // ... or lowercase
  59.  
  60.  
  61.     friend gcstring operator +(char * p, gcstring & g);
  62.     friend gcstring operator +(gcstring & g, char * p);
  63.     friend istream & operator >>(istream & ist, gcstring & s);
  64.     friend ostream & operator <<(ostream & ost, const gcstring & s);
  65.  
  66. protected:
  67.     char * GetPtr() const;
  68.  
  69. private:
  70.     data_record ** str;        // pointer to data record in gcobject memory.
  71.     static gcobject * gc;    // static gcobject allocation buffer.
  72.     static PointerHeap * po;    // static pointer allocation heap.
  73. };
  74.  
  75. inline gcstring::operator const char * () const
  76.     return (char *)((*str)->data); 
  77. }
  78.  
  79. inline int gcstring::operator ==(const gcstring & s) const 
  80.     return !compare(s); 
  81. }
  82.  
  83. inline int gcstring::operator !=(const gcstring & s) const 
  84.     return compare(s); 
  85. }
  86.  
  87. inline char * gcstring::GetPtr() const 
  88.     return (char *)((*str)->data); 
  89. }
  90.  
  91. gcstring operator +(char * p, gcstring & g);    // concatenate
  92.  
  93. gcstring operator +(gcstring & g, char * p);    // concatenate
  94.  
  95. istream & operator >>(istream & ist, gcstring & s);
  96. ostream & operator <<(ostream & ost, const gcstring & s);
  97.  
  98.  
  99. #endif
  100.  
  101. // end of file gcstring.hpp
  102.