diff options
Diffstat (limited to 'ace/SString.h')
-rw-r--r-- | ace/SString.h | 301 |
1 files changed, 136 insertions, 165 deletions
diff --git a/ace/SString.h b/ace/SString.h index b7fe755c629..3b2246091b6 100644 --- a/ace/SString.h +++ b/ace/SString.h @@ -29,21 +29,20 @@ class ACE_Allocator; class ACE_Export ACE_CString { // = TITLE - // This class provides a wrapper facade for C strings. + // A simple C String <ACE_CString> class. // // = DESCRIPTION - // This class uses an <ACE_Allocator> to allocate memory. The - // user can make this a persistant class by providing an - // ACE_Allocator with a persistable memory pool. NOTE: if an - // instance of this class is constructed from or assigned an empty - // string (with first element of '\0'), then it is _not_ allocated - // new space. Instead, its internal representation is set equal - // to a global empty string. CAUTION: in cases when ACE_CString - // is constructed from provided buffer with release parameter set - // to 0, ACE_CString is not guaranteed to be '\0' terminated. // This is a place holder until all compilers implement the - // ANSI/ISO C++ standard String class. - + // ANSI/ISO C++ standard String class. This class uses + // an ACE_Allocator to allocate memory. The user can make this a + // persistant class by providing an ACE_Allocator with a + // persistable memory pool. NOTE: if an instance of this class is + // constructed from or assigned an empty string (with first + // element of '\0'), then it is _not_ allocated new space. + // Instead, its internal representation is set equal to a global + // empty string. CAUTION: in cases when ACE_CString is + // constructed from provided buffer with release parameter set to 0, ACE_CString + // is not guaranteed to be '\0' terminated. public: static const int npos; // No position constant @@ -193,130 +192,117 @@ ACE_Export ACE_INLINE ACE_CString operator + (const ACE_CString &, const ACE_CSt ACE_Export ostream &operator << (ostream &, const ACE_CString &); #endif /* ! ACE_LACKS_IOSTREAM_TOTALLY */ -class ACE_Export ACE_WString +class ACE_Export ACE_SString { // = TITLE - // This class provides a wrapper facade for C wide strings. + // A very Simple String <ACE_SString> class. This is not a + // general-purpose string class, and you should probably consider + // using <ACE_CString> is you don't understand why this class + // exists... // - // = DESCRIPTION - // This class uses an <ACE_Allocator> to allocate memory. The - // user can make this a persistant class by providing an - // <ACE_Allocator> with a persistable memory pool. This is a - // place holder until all compilers implement the ANSI/ISO C++ - // standard String class. + // = DESCRIPTION + // This class is only intended for use with applications that + // understand how it works. In particular, its destructor does + // not deallocate its memory when it is destroyed... We need this + // class since the <ACE_Map_Manager> requires an object that + // supports the operator == and operator !=. This class uses an + // <ACE_Allocator> to allocate memory. The user can make this a + // persistant class by providing an <ACE_Allocator> with a + // persistable memory pool. public: static const int npos; // No position constant - ACE_WString (ACE_Allocator *alloc = 0); + ACE_SString (ACE_Allocator *alloc = 0); // Default constructor. - ACE_WString (const char *s, - ACE_Allocator *alloc = 0); - // Constructor that copies <s> into dynamically allocated memory. - - ACE_WString (const ACE_USHORT16 *s, - ACE_Allocator *alloc = 0); + ACE_SString (const char *s, ACE_Allocator *alloc = 0); // Constructor that copies <s> into dynamically allocated memory. - ACE_WString (const ACE_USHORT16 *s, - size_t len, - ACE_Allocator *alloc = 0); - // Constructor that copies <len> ACE_USHORT16's of <s> into dynamically + ACE_SString (const char *s, size_t len, ACE_Allocator *alloc = 0); + // Constructor that copies <len> chars of <s> into dynamically // allocated memory (will NUL terminate the result). - ACE_WString (size_t len, ACE_Allocator *alloc = 0); - // Constructor that dynamically allocates memory for <len> + 1 - // ACE_USHORT16 characters. The newly created memory is set memset to 0. - - ACE_WString (const ACE_WString &s); + ACE_SString (const ACE_SString &); // Copy constructor. - ACE_WString (ACE_USHORT16 c, ACE_Allocator *alloc = 0); + ACE_SString (char c, ACE_Allocator *alloc = 0); // Constructor that copies <c> into dynamically allocated memory. - ~ACE_WString (void); - // Deletes the memory... + ~ACE_SString (void); + // Default dtor. - ACE_USHORT16 operator [] (size_t index) const; + char operator [] (size_t index) const; // Return the <index'th> character in the string (doesn't perform // bounds checking). - ACE_USHORT16 &operator [] (size_t index); + char &operator [] (size_t index); // Return the <index'th> character by reference in the string // (doesn't perform bounds checking). - ACE_WString &operator = (const ACE_WString &); + ACE_SString &operator = (const ACE_SString &); // Assignment operator (does copy memory). - void set (const ACE_USHORT16 *s); - // Copy <s> - - void set (const ACE_USHORT16 *s, size_t len); - // Copy <len> bytes of <s> (will NUL terminate the result) - - ACE_WString substring (size_t offset, ssize_t length = -1) const; + ACE_SString substring (size_t offset, ssize_t length = -1) const; // Return a substring given an offset and length, if length == -1 // use rest of str return empty substring if offset or offset/length - // are invalid. + // are invalid - ACE_WString substr (size_t offset, ssize_t length = -1) const; + ACE_SString substr (size_t offset, ssize_t length = -1) const; // Same as substring - ACE_WString &operator += (const ACE_WString &); - // Concat operator (does copy memory). - u_long hash (void) const; // Returns a hash value for this string. size_t length (void) const; // Return the length of the string. - ACE_USHORT16 *rep (void) const; - // Gets a copy of the underlying pointer. + void rep (char *s); + // Set the underlying pointer. Since this does not copy memory or + // delete existing memory use with extreme caution!!! - char *char_rep (void) const; - // Transform into a copy of the ASCII character representation. + const char *rep (void) const; + // Get the underlying pointer. - const ACE_USHORT16 *fast_rep (void) const; - // Get at the underlying representation directly! + const char *fast_rep (void) const; + // Get the underlying pointer. - const ACE_USHORT16 *c_str (void) const; + const char *c_str (void) const; // Same as STL String's <c_str> and <fast_rep>. - int strstr (const ACE_WString &s) const; + int strstr (const ACE_SString &s) const; // Comparison operator that will match substrings. Returns the // index of the first location that matches, else -1. - int find (const ACE_WString &str, int pos = 0) const; + int find (const ACE_SString &str, int pos = 0) const; // Find <str> starting at pos. Returns the index of the first // location that matches, else npos. - int find (const ACE_USHORT16 *s, int pos = 0) const; + int find (const char *s, int pos = 0) const; // Find <s> starting at pos. Returns the index of the first // location that matches, else npos. - int find (ACE_USHORT16 c, int pos = 0) const; + int find (char c, int pos = 0) const; // Find <c> starting at pos. Returns the index of the first // location that matches, else npos. - int rfind (ACE_USHORT16 c, int pos = npos) const; + int rfind (char c, int pos = npos) const; // Find <c> starting at pos (counting from the end). Returns the // index of the first location that matches, else npos. - int operator == (const ACE_WString &s) const; + int operator == (const ACE_SString &s) const; // Equality comparison operator (must match entire string). - int operator < (const ACE_WString &s) const; + int operator < (const ACE_SString &s) const; // Less than comparison operator. - int operator > (const ACE_WString &s) const; + int operator > (const ACE_SString &s) const; // Greater than comparison operator. - int operator != (const ACE_WString &s) const; + int operator != (const ACE_SString &s) const; // Inequality comparison operator. - int compare (const ACE_WString &s) const; + int compare (const ACE_SString &s) const; // Performs a <strcmp>-style comparison. void dump (void) const; @@ -325,145 +311,145 @@ public: ACE_ALLOC_HOOK_DECLARE; // Declare the dynamic allocation hooks. - static size_t strlen (const ACE_USHORT16 *); - // Computes the length of a "0" terminated ACE_USHORT16 *. - - static const ACE_USHORT16 *strstr (const ACE_USHORT16 *s1, const ACE_USHORT16 *s2); - // Traditional style strstr - - void resize (size_t len); - // This method is designed for high-performance. Please use with - // care ;-) If the current size of the string is less than <len>, - // the string is resized to the new length. The data is is zero'd - // out after this operation. - private: ACE_Allocator *allocator_; // Pointer to a memory allocator. size_t len_; - // Length of the ACE_WString. + // Length of the ACE_SString (not counting the trailing '\0'). - ACE_USHORT16 *rep_; + char *rep_; // Pointer to data. }; -ACE_Export ACE_INLINE ACE_WString operator + (const ACE_WString &, const ACE_WString &); #if !defined (ACE_LACKS_IOSTREAM_TOTALLY) -ACE_Export ostream &operator << (ostream &, const ACE_WString &); +ACE_Export ostream &operator << (ostream &, const ACE_SString &); #endif /* ! ACE_LACKS_IOSTREAM_TOTALLY */ -class ACE_Export ACE_SString +class ACE_Export ACE_WString { // = TITLE - // A very Simple String <ACE_SString> class. This is not a - // general-purpose string class, and you should probably consider - // using <ACE_CString> is you don't understand why this class - // exists... + // A persistent wide string class. // // = DESCRIPTION - // This class is only intended for use with applications that - // understand how it works. In particular, its destructor does - // not deallocate its memory when it is destroyed... We need this - // class since the <ACE_Map_Manager> requires an object that - // supports the operator == and operator !=. This class uses an - // <ACE_Allocator> to allocate memory. The user can make this a - // persistant class by providing an <ACE_Allocator> with a - // persistable memory pool. + // We need to use this class since the <ACE_Map_Manager> requires + // an object that supports the operator == and operator !=. This + // class uses an <ACE_Allocator> to allocate memory. The user can + // make this a persistant class by providing an <ACE_Allocator> + // with a persistable memory pool public: static const int npos; // No position constant - ACE_SString (ACE_Allocator *alloc = 0); + ACE_WString (ACE_Allocator *alloc = 0); // Default constructor. - ACE_SString (const char *s, ACE_Allocator *alloc = 0); + ACE_WString (const char *s, + ACE_Allocator *alloc = 0); // Constructor that copies <s> into dynamically allocated memory. - ACE_SString (const char *s, size_t len, ACE_Allocator *alloc = 0); - // Constructor that copies <len> chars of <s> into dynamically + ACE_WString (const ACE_USHORT16 *s, + ACE_Allocator *alloc = 0); + // Constructor that copies <s> into dynamically allocated memory. + + ACE_WString (const ACE_USHORT16 *s, + size_t len, + ACE_Allocator *alloc = 0); + // Constructor that copies <len> ACE_USHORT16's of <s> into dynamically // allocated memory (will NUL terminate the result). - ACE_SString (const ACE_SString &); + ACE_WString (size_t len, ACE_Allocator *alloc = 0); + // Constructor that dynamically allocates memory for <len> + 1 + // ACE_USHORT16 characters. The newly created memory is set memset to 0. + + ACE_WString (const ACE_WString &s); // Copy constructor. - ACE_SString (char c, ACE_Allocator *alloc = 0); + ACE_WString (ACE_USHORT16 c, ACE_Allocator *alloc = 0); // Constructor that copies <c> into dynamically allocated memory. - ~ACE_SString (void); - // Default dtor. + ~ACE_WString (void); + // Deletes the memory... - char operator [] (size_t index) const; + ACE_USHORT16 operator [] (size_t index) const; // Return the <index'th> character in the string (doesn't perform // bounds checking). - char &operator [] (size_t index); + ACE_USHORT16 &operator [] (size_t index); // Return the <index'th> character by reference in the string // (doesn't perform bounds checking). - ACE_SString &operator = (const ACE_SString &); + ACE_WString &operator = (const ACE_WString &); // Assignment operator (does copy memory). - ACE_SString substring (size_t offset, ssize_t length = -1) const; + void set (const ACE_USHORT16 *s); + // Copy <s> + + void set (const ACE_USHORT16 *s, size_t len); + // Copy <len> bytes of <s> (will NUL terminate the result) + + ACE_WString substring (size_t offset, ssize_t length = -1) const; // Return a substring given an offset and length, if length == -1 // use rest of str return empty substring if offset or offset/length - // are invalid + // are invalid. - ACE_SString substr (size_t offset, ssize_t length = -1) const; + ACE_WString substr (size_t offset, ssize_t length = -1) const; // Same as substring + ACE_WString &operator += (const ACE_WString &); + // Concat operator (does copy memory). + u_long hash (void) const; // Returns a hash value for this string. size_t length (void) const; // Return the length of the string. - void rep (char *s); - // Set the underlying pointer. Since this does not copy memory or - // delete existing memory use with extreme caution!!! + ACE_USHORT16 *rep (void) const; + // Gets a copy of the underlying pointer. - const char *rep (void) const; - // Get the underlying pointer. + char *char_rep (void) const; + // Transform into a copy of the ASCII character representation. - const char *fast_rep (void) const; - // Get the underlying pointer. + const ACE_USHORT16 *fast_rep (void) const; + // Get at the underlying representation directly! - const char *c_str (void) const; + const ACE_USHORT16 *c_str (void) const; // Same as STL String's <c_str> and <fast_rep>. - int strstr (const ACE_SString &s) const; + int strstr (const ACE_WString &s) const; // Comparison operator that will match substrings. Returns the // index of the first location that matches, else -1. - int find (const ACE_SString &str, int pos = 0) const; + int find (const ACE_WString &str, int pos = 0) const; // Find <str> starting at pos. Returns the index of the first // location that matches, else npos. - int find (const char *s, int pos = 0) const; + int find (const ACE_USHORT16 *s, int pos = 0) const; // Find <s> starting at pos. Returns the index of the first // location that matches, else npos. - int find (char c, int pos = 0) const; + int find (ACE_USHORT16 c, int pos = 0) const; // Find <c> starting at pos. Returns the index of the first // location that matches, else npos. - int rfind (char c, int pos = npos) const; + int rfind (ACE_USHORT16 c, int pos = npos) const; // Find <c> starting at pos (counting from the end). Returns the // index of the first location that matches, else npos. - int operator == (const ACE_SString &s) const; + int operator == (const ACE_WString &s) const; // Equality comparison operator (must match entire string). - int operator < (const ACE_SString &s) const; + int operator < (const ACE_WString &s) const; // Less than comparison operator. - int operator > (const ACE_SString &s) const; + int operator > (const ACE_WString &s) const; // Greater than comparison operator. - int operator != (const ACE_SString &s) const; + int operator != (const ACE_WString &s) const; // Inequality comparison operator. - int compare (const ACE_SString &s) const; + int compare (const ACE_WString &s) const; // Performs a <strcmp>-style comparison. void dump (void) const; @@ -472,21 +458,36 @@ public: ACE_ALLOC_HOOK_DECLARE; // Declare the dynamic allocation hooks. + static size_t strlen (const ACE_USHORT16 *); + // Computes the length of a "0" terminated ACE_USHORT16 *. + + static const ACE_USHORT16 *strstr (const ACE_USHORT16 *s1, const ACE_USHORT16 *s2); + // Traditional style strstr + + void resize (size_t len); + // This method is designed for high-performance. Please use with + // care ;-) If the current size of the string is less than <len>, + // the string is resized to the new length. The data is is zero'd + // out after this operation. + private: ACE_Allocator *allocator_; // Pointer to a memory allocator. size_t len_; - // Length of the ACE_SString (not counting the trailing '\0'). + // Length of the ACE_WString. - char *rep_; + ACE_USHORT16 *rep_; // Pointer to data. }; +ACE_Export ACE_INLINE ACE_WString operator + (const ACE_WString &, const ACE_WString &); #if !defined (ACE_LACKS_IOSTREAM_TOTALLY) -ACE_Export ostream &operator << (ostream &, const ACE_SString &); +ACE_Export ostream &operator << (ostream &, const ACE_WString &); #endif /* ! ACE_LACKS_IOSTREAM_TOTALLY */ +// ************************************************************ + class ACE_Export ACE_Tokenizer { // = TITLE @@ -588,36 +589,6 @@ private: // Pointer to the next free space in delimiters_. }; -// **************************************************************** - -class ACE_Auto_String_Free -{ - // = TITLE - // Simple class to automatically de-allocate strings - // - // = DESCRIPTION - // Keeps a pointer to a string and deallocates it (using - // ACE_OS::free()) on its destructor. - // If you need to delete using "delete[]" the - // ACE_Auto_Array_Ptr<char*> is your choice. - // The class plays the same role as auto_ptr<> - // -public: - /* explicit */ ACE_Auto_String_Free (char* p = 0); - ACE_Auto_String_Free (ACE_Auto_String_Free &rhs); - ACE_Auto_String_Free& operator= (ACE_Auto_String_Free &rhs); - ~ACE_Auto_String_Free (void); - - char* operator* () const; - char operator[] (int i) const; - char* get (void) const; - char* release (void); - void reset (char* p = 0); - -private: - char* p_; -}; - #if defined (__ACE_INLINE__) #include "ace/SString.i" #endif /* __ACE_INLINE__ */ |