// File: bstring6.h // // Header file for buffered string. // Version 3: made comparison functions, etc. const. // Version 4: added != operator // Version 5: char * alternate constructor becomes const char * // throws exceptions // Version 6: new and delete operators #ifndef _bstring_h #define _bstring_h #include #include "errors.h" class BString { friend ostream& operator <<(ostream&, const BString&) ; public: // Constructors // BString() ; // Default constructor BString(int) ; // with initial buffer size BString(const char *s, int n=0); // with string & opt buffer size BString(const BString&) ; // Copy constructor // Destructor // ~BString() ; // Add char(s) to the end of this string // void append(char) ; void append(const char *) ; void append(const BString&) ; // Remove char(s) at the end of the string // void chop(int n=1) ; // Reduce buffer size if possible // void trim() ; void force_trim() ; // Overloaded Operators // BString& operator =(const BString&) ; // assignment BString operator +(const BString&) ; // + is concatenate char& operator [](int) ; // Synonyms for append // BString& operator +=(char c) { append(c) ; return *this ;} BString& operator +=(const char *s) { append(s) ; return *this ; } BString& operator +=(const BString& bs) { append(bs) ; return *this ; } bool operator <(const BString&) const ; // comparisons bool operator <=(const BString&) const ; bool operator ==(const BString&) const ; bool operator >=(const BString&) const ; bool operator >(const BString&) const ; bool operator !=(const BString&) const ; // Type conversion // operator char *() { return str ; } void GetLine(istream&) ; inline int length() const { return len ;} char *str ; void debug() ; // Memory Allocation // void *operator new(size_t) ; void *operator new[](size_t) ; void operator delete (void *) ; void operator delete[](void *) ; private: int len ; int bufsize ; } ; istream& operator >>(istream&, BString&) ; ostream& operator <<(ostream&, const BString&) ; #endif