diff options
author | nanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-09-11 06:26:54 +0000 |
---|---|---|
committer | nanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-09-11 06:26:54 +0000 |
commit | e1a0898ecfcf3828720a979cc5a632e55c3f8e37 (patch) | |
tree | f85034bafc9aecac2a8356312991a05540f29894 | |
parent | f1f986986ead7c59003b4223c536ea6e25891f33 (diff) | |
download | ATCD-e1a0898ecfcf3828720a979cc5a632e55c3f8e37.tar.gz |
ChangeLogTag:Tue Sep 11 01:22:40 2001 Nanbor Wang <nanbor@cs.wustl.edu>
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-02a | 17 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-03a | 17 | ||||
-rw-r--r-- | ace/CDR_Stream.h | 2 | ||||
-rw-r--r-- | ace/SString.cpp | 191 | ||||
-rw-r--r-- | ace/SString.h | 190 | ||||
-rw-r--r-- | ace/SString.i | 331 | ||||
-rw-r--r-- | ace/String_Base.cpp | 183 | ||||
-rw-r--r-- | ace/String_Base.h | 233 | ||||
-rw-r--r-- | ace/String_Base.i | 353 | ||||
-rw-r--r-- | ace/ace_dll.dsp | 8 | ||||
-rw-r--r-- | ace/ace_lib.dsp | 16 |
12 files changed, 856 insertions, 702 deletions
diff --git a/ChangeLog b/ChangeLog index b83d33d9eaf..ce78d8d369c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Tue Sep 11 01:22:40 2001 Nanbor Wang <nanbor@cs.wustl.edu> + + * ace/String_Base.h: + * ace/String_Base.i: + * ace/String_Base.cpp: Abstracted out ACE_CString and ACE_WString + into a templatized String_Base. + + * ace/CDR_Stream.h: Removed forward declarating ACE_CString and + added inclusion of <SString.h>. + + * ace/SString.h: + * ace/SString.i: + * ace/SString.cpp: Changed ACE_CString to be a typedef of + ACE_String_Base<char>. + Thu Aug 9 16:56:05 2001 Balachandran Natarajan <bala@cs.wustl.edu> * ace/Hash_Map_Manager_T.i: @@ -7,7 +22,7 @@ Thu Aug 9 16:56:05 2001 Balachandran Natarajan <bala@cs.wustl.edu> to the liking of SunCC 4.2. Looks like we had to change a bunch of static cast sprayed in these two files to a C style cast as 4.2 doesnt like them. Compilers like Borland handle these - better, but not 4.2. + better, but not 4.2. Thu Aug 9 11:51:10 2001 Balachandran Natarajan <bala@cs.wustl.edu> diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a index b83d33d9eaf..ce78d8d369c 100644 --- a/ChangeLogs/ChangeLog-02a +++ b/ChangeLogs/ChangeLog-02a @@ -1,3 +1,18 @@ +Tue Sep 11 01:22:40 2001 Nanbor Wang <nanbor@cs.wustl.edu> + + * ace/String_Base.h: + * ace/String_Base.i: + * ace/String_Base.cpp: Abstracted out ACE_CString and ACE_WString + into a templatized String_Base. + + * ace/CDR_Stream.h: Removed forward declarating ACE_CString and + added inclusion of <SString.h>. + + * ace/SString.h: + * ace/SString.i: + * ace/SString.cpp: Changed ACE_CString to be a typedef of + ACE_String_Base<char>. + Thu Aug 9 16:56:05 2001 Balachandran Natarajan <bala@cs.wustl.edu> * ace/Hash_Map_Manager_T.i: @@ -7,7 +22,7 @@ Thu Aug 9 16:56:05 2001 Balachandran Natarajan <bala@cs.wustl.edu> to the liking of SunCC 4.2. Looks like we had to change a bunch of static cast sprayed in these two files to a C style cast as 4.2 doesnt like them. Compilers like Borland handle these - better, but not 4.2. + better, but not 4.2. Thu Aug 9 11:51:10 2001 Balachandran Natarajan <bala@cs.wustl.edu> diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a index b83d33d9eaf..ce78d8d369c 100644 --- a/ChangeLogs/ChangeLog-03a +++ b/ChangeLogs/ChangeLog-03a @@ -1,3 +1,18 @@ +Tue Sep 11 01:22:40 2001 Nanbor Wang <nanbor@cs.wustl.edu> + + * ace/String_Base.h: + * ace/String_Base.i: + * ace/String_Base.cpp: Abstracted out ACE_CString and ACE_WString + into a templatized String_Base. + + * ace/CDR_Stream.h: Removed forward declarating ACE_CString and + added inclusion of <SString.h>. + + * ace/SString.h: + * ace/SString.i: + * ace/SString.cpp: Changed ACE_CString to be a typedef of + ACE_String_Base<char>. + Thu Aug 9 16:56:05 2001 Balachandran Natarajan <bala@cs.wustl.edu> * ace/Hash_Map_Manager_T.i: @@ -7,7 +22,7 @@ Thu Aug 9 16:56:05 2001 Balachandran Natarajan <bala@cs.wustl.edu> to the liking of SunCC 4.2. Looks like we had to change a bunch of static cast sprayed in these two files to a C style cast as 4.2 doesnt like them. Compilers like Borland handle these - better, but not 4.2. + better, but not 4.2. Thu Aug 9 11:51:10 2001 Balachandran Natarajan <bala@cs.wustl.edu> diff --git a/ace/CDR_Stream.h b/ace/CDR_Stream.h index 31cd1e21403..ae05795c8ce 100644 --- a/ace/CDR_Stream.h +++ b/ace/CDR_Stream.h @@ -41,11 +41,11 @@ # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "ace/SString.h" #include "ace/Message_Block.h" class ACE_Char_Codeset_Translator; class ACE_WChar_Codeset_Translator; -class ACE_CString; class ACE_InputCDR; diff --git a/ace/SString.cpp b/ace/SString.cpp index c9a7d247856..adb1f044036 100644 --- a/ace/SString.cpp +++ b/ace/SString.cpp @@ -223,14 +223,6 @@ EXIT_LABEL: // ************************************************************ -ACE_ALLOC_HOOK_DEFINE(ACE_CString) - -char ACE_CString::NULL_CString_ = '\0'; -ACE_WSTRING_TYPE ACE_WString::NULL_WString_ = '\0'; -const int ACE_CString::npos = -1; -const int ACE_SString::npos = -1; -const int ACE_WString::npos = -1; - #if !defined (ACE_LACKS_IOSTREAM_TOTALLY) ostream & operator<< (ostream &os, const ACE_CString &cs) @@ -260,182 +252,9 @@ operator<< (ostream &os, const ACE_SString &ss) } #endif /* !ACE_LACKS_IOSTREAM_TOTALLY */ -// Constructor that copies <s> into dynamically allocated memory. -// Probable loss of data. Please use with care. - -ACE_CString::ACE_CString (const ACE_WSTRING_TYPE *s, - ACE_Allocator *alloc) - : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), - len_ (0), - buf_len_ (0), - rep_ (0), - release_ (0) -{ - ACE_TRACE ("ACE_CString::ACE_CString"); - - if (s == 0 || s[0] == (ACE_WSTRING_TYPE) '\0') - { - this->release_ = 0; - this->len_ = 0; - this->rep_ = &ACE_CString::NULL_CString_; - } - else - { - this->release_ = 1; - - size_t len = ACE_WString::strlen (s); - ACE_ALLOCATOR (this->rep_, - (char *) this->allocator_->malloc (len + 1)); - this->len_ = len; - this->buf_len_ = len + 1; - - // Copy the ACE_WSTRING_TYPE * string byte-by-byte into the char * - // string. - for (size_t i = 0; i < this->len_; i++) - this->rep_[i] = char (s[i]); - - this->rep_[this->len_] = '\0'; - } -} - -// this method might benefit from a little restructuring. -void -ACE_CString::set (const char *s, - size_t len, - int release) -{ - // Case 1. Going from memory to more memory - size_t new_buf_len = len + 1; - if (s != 0 && len != 0 && release && this->buf_len_ < new_buf_len) - { - char *temp; - ACE_ALLOCATOR (temp, - (char *) this->allocator_->malloc (new_buf_len)); - - if (this->release_) - this->allocator_->free (this->rep_); - - this->rep_ = temp; - this->buf_len_ = new_buf_len; - this->release_ = 1; - this->len_ = len; - ACE_OS::memcpy (this->rep_, s, len); - // NUL terminate. - this->rep_[len] = '\0'; - } - - // Case 2. No memory allocation is necessary. - else - { - // Free memory if necessary and figure out future ownership - if (!release || s == 0 || len == 0) - if (this->release_) - { - this->allocator_->free (this->rep_); - this->release_ = 0; - } - // else - stay with whatever value for release_ we have. - - // Populate data. - if (s == 0 || len == 0) - { - this->buf_len_ = 0; - this->len_ = 0; - this->rep_ = &ACE_CString::NULL_CString_; - } - else if (!release) - { - this->buf_len_ = len; - this->len_ = len; - this->rep_ = (char *) s; - } - else - { - ACE_OS::memcpy (this->rep_, s, len); - // NUL terminate. - this->rep_[len] = 0; - this->len_ = len; - } - } -} - -// Return substring. -ACE_CString -ACE_CString::substring (size_t offset, - ssize_t length) const -{ - ACE_CString nil; - size_t count = length; - - // case 1. empty string - if (this->len_ == 0) - return nil; - - // case 2. start pos past our end - if (offset >= this->len_) - return nil; - // No length == empty string. - else if (length == 0) - return nil; - // Get all remaining bytes. - else if (length == -1 || count > (this->len_ - offset)) - count = this->len_ - offset; - - return ACE_CString (&this->rep_[offset], - count, - this->allocator_); -} - -// Concat operator (does copy memory). - -ACE_CString & -ACE_CString::operator+= (const ACE_CString &s) -{ - ACE_TRACE ("ACE_CString::operator+="); - - if (s.len_ > 0) - { - size_t new_buf_len = this->len_ + s.len_ + 1; - - // case 1. No memory allocation needed. - if (this->buf_len_ >= new_buf_len) - // Copy in data from new string. - ACE_OS::memcpy (this->rep_ + this->len_, - s.rep_, - s.len_); - - // case 2. Memory reallocation is needed - else - { - char *t = 0; - - ACE_ALLOCATOR_RETURN (t, - (char *) this->allocator_->malloc (new_buf_len), - *this); - - // Copy memory from old string into new string. - ACE_OS::memcpy (t, - this->rep_, - this->len_); - - ACE_OS::memcpy (t + this->len_, - s.rep_, - s.len_); - - if (this->release_) - this->allocator_->free (this->rep_); - - this->release_ = 1; - this->rep_ = t; - this->buf_len_ = new_buf_len; - } - - this->len_ += s.len_; - this->rep_[this->len_] = '\0'; - } - - return *this; -} +ACE_WSTRING_TYPE ACE_WString::NULL_WString_ = '\0'; +const int ACE_SString::npos = -1; +const int ACE_WString::npos = -1; ACE_ALLOC_HOOK_DEFINE(ACE_SString) @@ -1052,11 +871,11 @@ ACE_WString::check_allocate (size_t len) { ACE_WSTRING_TYPE *t = (ACE_WSTRING_TYPE *) this->allocator_->malloc ((tempbuflen) * sizeof (ACE_WSTRING_TYPE)); - + ACE_OS::memcpy ((void *) t, (const void *) this->rep_, this->len_ * sizeof (ACE_WSTRING_TYPE)); - + this->allocator_->free (this->rep_); this->rep_ = t; } diff --git a/ace/SString.h b/ace/SString.h index 75e3d44f3c7..8cd0bb676e7 100644 --- a/ace/SString.h +++ b/ace/SString.h @@ -14,7 +14,7 @@ #define ACE_SSTRING_H #include "ace/pre.h" -#include "ace/ACE.h" +#include "ace/String_Base.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once @@ -30,188 +30,10 @@ typedef ACE_USHORT16 ACE_WSTRING_TYPE; #define ACE_DEFAULT_GROWSIZE 32 #endif /* ACE_DEFAULT_GROWSIZE */ -// Forward decl. -class ACE_Allocator; +typedef ACE_String_Base<char> ACE_CString; -/** - * @class ACE_CString - * - * @brief This class provides a wrapper facade for C strings. - * - * 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 class is - * optimized for efficiency, so it doesn't provide any internal - * locking. - * 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 a - * provided buffer with the release parameter set to 0, - * ACE_CString is not guaranteed to be '\0' terminated. - */ -class ACE_Export ACE_CString -{ -public: - /// No position constant - static const int npos; - - /// Default constructor. - ACE_CString (ACE_Allocator *alloc = 0); - - /** - * Constructor that copies <s> into dynamically allocated memory. - * If <release> is non-0 then the <ACE_allocator> is responsible for - * freeing this memory. Memory is _not_ allocated/freed if <release> - * is 0. - */ - ACE_CString (const char *s, - ACE_Allocator *alloc = 0, - int release = 1); - - /** - * Constructor that copies <len> chars of <s> into dynamically - * allocated memory (will NUL terminate the result). If <release> - * is non-0 then the <ACE_allocator> is responsible for freeing this - * memory. Memory is _not_ allocated/freed if <release> is 0. - */ - ACE_CString (const char *s, - size_t len, - ACE_Allocator *alloc = 0, - int release = 1); - - /// Copy constructor. - ACE_CString (const ACE_CString &); - - /// Constructor that copies <s> into dynamically allocated memory. - /// Probable loss of data. Please use with care. - ACE_CString (const ACE_WSTRING_TYPE *s, - ACE_Allocator *alloc = 0); - - /// Constructor that copies <c> into dynamically allocated memory. - ACE_CString (char c, ACE_Allocator *alloc = 0); - - /// Deletes the memory... - ~ACE_CString (void); - - /// Return the <slot'th> character in the string (doesn't perform - /// bounds checking). - const char &operator [] (size_t slot) const; - - /// Return the <slot'th> character by reference in the string - /// (doesn't perform bounds checking). - char &operator [] (size_t slot); - - /// Assignment operator (does copy memory). - ACE_CString &operator = (const ACE_CString &); - - /// Copy <s> into this <ACE_CString>. Memory is _not_ - /// allocated/freed if <release> is 0. - void set (const char *s, int release = 1); - - /// Copy <len> bytes of <s> (will NUL terminate the result). - /// Memory is _not_ allocated/freed if <release> is 0. - void set (const char *s, - size_t len, - int release); - - /** - * 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. - */ - ACE_CString substring (size_t offset, ssize_t length = -1) const; - - /// Same as <substring>. - ACE_CString substr (size_t offset, ssize_t length = -1) const; - - /// Concat operator (copies memory). - ACE_CString &operator += (const ACE_CString &); - - /// Returns a hash value for this string. - u_long hash (void) const; - - /// Return the length of the string. - size_t length (void) const; - - /// Get a copy of the underlying pointer. - char *rep (void) const; - - /** - * Get at the underlying representation directly! - * _Don't_ even think about casting the result to (char *) and modifying it, - * if it has length 0! - */ - const char *fast_rep (void) const; - - /// Same as STL String's <c_str> and <fast_rep>. - const char *c_str (void) const; - - /// Comparison operator that will match substrings. Returns the - /// slot of the first location that matches, else -1. - int strstr (const ACE_CString &s) const; - - /// Find <str> starting at pos. Returns the slot of the first - /// location that matches (will be >= pos), else npos. - int find (const ACE_CString &str, int pos = 0) const; - - /// Find <s> starting at pos. Returns the slot of the first - /// location that matches (will be >= pos), else npos. - int find (const char *s, int pos = 0) const; - - /// Find <c> starting at pos. Returns the slot of the first - /// location that matches (will be >= pos), else npos. - int find (char c, int pos = 0) const; - - /// Find <c> starting at pos (counting from the end). Returns the - /// slot of the first location that matches, else npos. - int rfind (char c, int pos = npos) const; - - /// Equality comparison operator (must match entire string). - int operator == (const ACE_CString &s) const; - - /// Less than comparison operator. - int operator < (const ACE_CString &s) const; - - /// Greater than comparison operator. - int operator > (const ACE_CString &s) const; - - /// Inequality comparison operator. - int operator != (const ACE_CString &s) const; - - /// Performs a <strcmp>-style comparison. - int compare (const ACE_CString &s) const; - - /// Dump the state of an object. - void dump (void) const; - - /// Declare the dynamic allocation hooks. - ACE_ALLOC_HOOK_DECLARE; - -private: - /// Pointer to a memory allocator. - ACE_Allocator *allocator_; - - /// Length of the ACE_CString data (not counting the trailing '\0'). - size_t len_; - - /// Length of the ACE_CString data buffer. Keeping track of the - /// length allows to avoid unnecessary dynamic allocations. - size_t buf_len_; - - /// Pointer to data. - char *rep_; - - /// Flag that indicates if we own the memory - int release_; - - /// Represents the "NULL" string to simplify the internal logic. - static char NULL_CString_; -}; - -ACE_Export ACE_INLINE ACE_CString operator + (const ACE_CString &, - const ACE_CString &); +template ACE_CString operator + (const ACE_CString &, + const ACE_CString &); #if !defined (ACE_LACKS_IOSTREAM_TOTALLY) ACE_Export ostream &operator << (ostream &, const ACE_CString &); #endif /* ! ACE_LACKS_IOSTREAM_TOTALLY */ @@ -560,9 +382,9 @@ ACE_Export ostream &operator << (ostream &, const ACE_SString &); // This allows one to use W or C String based on the Unicode // setting #if defined (ACE_USES_WCHAR) -# define ACE_TString ACE_WString +typedef ACE_WString ACE_TString; #else /* ACE_USES_WCHAR */ -# define ACE_TString ACE_CString +typedef ACE_CString ACE_TString; #endif /* ACE_USES_WCHAR */ diff --git a/ace/SString.i b/ace/SString.i index c5c42f254c5..e15015178b6 100644 --- a/ace/SString.i +++ b/ace/SString.i @@ -3,323 +3,6 @@ #include "ace/Malloc_Base.h" -// Default constructor. - -ACE_INLINE -ACE_CString::ACE_CString (ACE_Allocator *alloc) - : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), - len_ (0), - buf_len_ (0), - rep_ (&ACE_CString::NULL_CString_), - release_ (0) -{ - ACE_TRACE ("ACE_CString::ACE_CString"); -} - -// Constructor that actually copies memory. - -ACE_INLINE -ACE_CString::ACE_CString (const char *s, - ACE_Allocator *alloc, - int release) - : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), - len_ (0), - buf_len_ (0), - rep_ (0), - release_ (0) -{ - ACE_TRACE ("ACE_CString::ACE_CString"); - - size_t length; - if (s != 0) - length = ACE_OS::strlen (s); - else - length = 0; - - this->set (s, length, release); -} - -ACE_INLINE -ACE_CString::ACE_CString (char c, - ACE_Allocator *alloc) - : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), - len_ (0), - buf_len_ (0), - rep_ (0), - release_ (0) -{ - ACE_TRACE ("ACE_CString::ACE_CString"); - - this->set (&c, 1, 1); -} - -// Constructor that actually copies memory. - -ACE_INLINE -ACE_CString::ACE_CString (const char *s, - size_t len, - ACE_Allocator *alloc, - int release) - : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), - len_ (0), - buf_len_ (0), - rep_ (0), - release_ (0) -{ - ACE_TRACE ("ACE_CString::ACE_CString"); - - this->set (s, len, release); -} - -// Copy constructor. - -ACE_INLINE -ACE_CString::ACE_CString (const ACE_CString &s) - : allocator_ (s.allocator_ ? s.allocator_ : ACE_Allocator::instance ()), - len_ (0), - buf_len_ (0), - rep_ (0), - release_ (0) -{ - ACE_TRACE ("ACE_CString::ACE_CString"); - - this->set (s.rep_, s.len_, 1); -} - -ACE_INLINE -ACE_CString::~ACE_CString (void) -{ - ACE_TRACE ("ACE_CString::~ACE_CString"); - - this->set (0, 0, 0); -} - -ACE_INLINE void -ACE_CString::dump (void) const -{ - ACE_TRACE ("ACE_CString::dump"); -} - -// Assignment operator (does copy memory). - -ACE_INLINE ACE_CString & -ACE_CString::operator= (const ACE_CString &s) -{ - ACE_TRACE ("ACE_CString::operator="); - - // Check for identify. - if (this != &s) - this->set (s.rep_, s.len_, 1); - - return *this; -} - -ACE_INLINE void -ACE_CString::set (const char *s, int release) -{ - size_t length; - if (s != 0) - length = ACE_OS::strlen (s); - else - length = 0; - - this->set (s, length, release); -} - -ACE_INLINE size_t -ACE_CString::length (void) const -{ - ACE_TRACE ("ACE_CString::length"); - return this->len_; -} - -ACE_INLINE ACE_CString -ACE_CString::substr (size_t offset, - ssize_t length) const -{ - return this->substring (offset, length); -} - -// Return the <slot'th> character in the string. - -ACE_INLINE const char & -ACE_CString::operator[] (size_t slot) const -{ - ACE_TRACE ("ACE_CString::operator[]"); - return this->rep_[slot]; -} - -// Return the <slot'th> character in the string by reference. - -ACE_INLINE char & -ACE_CString::operator[] (size_t slot) -{ - ACE_TRACE ("ACE_CString::operator[]"); - return this->rep_[slot]; -} - -// Get a copy of the underlying representation. - -ACE_INLINE char * -ACE_CString::rep (void) const -{ - ACE_TRACE ("ACE_CString::rep"); - - char *new_string; - ACE_NEW_RETURN (new_string, char[this->len_ + 1], 0); - ACE_OS::strncpy (new_string, this->rep_, this->len_); - new_string[this->len_] = '\0'; - - return new_string; -} - -ACE_INLINE const char * -ACE_CString::fast_rep (void) const -{ - return this->rep_; -} - -ACE_INLINE const char * -ACE_CString::c_str (void) const -{ - return this->rep_; -} - -// Comparison operator. - -ACE_INLINE int -ACE_CString::operator== (const ACE_CString &s) const -{ - ACE_TRACE ("ACE_CString::operator=="); - - return this->len_ == s.len_ - && ACE_OS::strncmp (this->rep_, s.rep_, this->len_) == 0; -} - -// Less than comparison operator. - -ACE_INLINE int -ACE_CString::operator < (const ACE_CString &s) const -{ - ACE_TRACE ("ACE_CString::operator <"); - - return (this->rep_ && s.rep_) - ? ACE_OS::strcmp (this->rep_, s.rep_) < 0 - : ((s.rep_) ? 1 : 0 ); -} - -// Greater than comparison operator. - -ACE_INLINE int -ACE_CString::operator > (const ACE_CString &s) const -{ - ACE_TRACE ("ACE_CString::operator >"); - - return (this->rep_ && s.rep_) - ? ACE_OS::strcmp (this->rep_, s.rep_) > 0 - : ((this->rep_) ? 1 : 0 ); -} - - -// Comparison operator. - -ACE_INLINE int -ACE_CString::operator!= (const ACE_CString &s) const -{ - ACE_TRACE ("ACE_CString::operator!="); - return !(*this == s); -} - -ACE_INLINE int -ACE_CString::compare (const ACE_CString &s) const -{ - ACE_TRACE ("ACE_CString::compare"); - - // We can't just pass both strings to strcmp, since they are not - // guaranteed to be null-terminated. - - // Pick smaller of the two lengths and perform the comparison. - int smaller_length = (this->len_ < s.len_) ? this->len_ : s.len_; - int result = ACE_OS::strncmp (this->rep_, - s.rep_, - smaller_length); - - if (result != 0 || s.len_ == this->len_) - return result; - - else - // we need to differentiate based on length - if (this->len_ > s.len_) - return (this->rep_[smaller_length] - '\0'); - - else - return ('\0' - s.rep_[smaller_length]); -} - -ACE_INLINE int -ACE_CString::find (const char *s, int pos) const -{ - char *substr = this->rep_ + pos; - size_t len = ACE_OS::strlen (s); - char *pointer = ACE_OS::strnstr (substr, s, len); - if (pointer == 0) - return ACE_CString::npos; - else - return pointer - this->rep_; -} - -ACE_INLINE int -ACE_CString::find (char c, int pos) const -{ - char *substr = this->rep_ + pos; - char *pointer = ACE_OS::strnchr (substr, c, this->len_ - pos); - if (pointer == 0) - return ACE_CString::npos; - else - return pointer - this->rep_; -} - -ACE_INLINE int -ACE_CString::find (const ACE_CString &str, int pos) const -{ - return this->find (str.rep_, pos); -} - -ACE_INLINE int -ACE_CString::strstr (const ACE_CString &s) const -{ - ACE_TRACE ("ACE_CString::strstr"); - - return this->find (s.rep_); -} - -ACE_INLINE int -ACE_CString::rfind (char c, int pos) const -{ - if (pos == ACE_CString::npos) - pos = this->len_; - - for (int i = pos - 1; i >= 0; i--) - if (this->rep_[i] == c) - return i; - - return ACE_CString::npos; -} - -ACE_INLINE u_long -ACE_CString::hash (void) const -{ - return ACE::hash_pjw (this->rep_, this->len_); -} - -ACE_INLINE ACE_CString -operator+ (const ACE_CString &s, const ACE_CString &t) -{ - ACE_CString temp (s); - temp += t; - return temp; -} - ACE_INLINE ACE_SString::~ACE_SString (void) { @@ -489,6 +172,7 @@ ACE_SString::length (void) const return this->len_; } + ACE_INLINE size_t ACE_WString::length (void) const { @@ -521,11 +205,11 @@ ACE_WString::rep (void) const ACE_TRACE ("ACE_WString::rep"); ACE_WSTRING_TYPE *t; - ACE_NEW_RETURN (t, - ACE_WSTRING_TYPE[this->len_ + 1], + ACE_NEW_RETURN (t, + ACE_WSTRING_TYPE[this->len_ + 1], 0); - ACE_OS::memcpy (t, - this->rep_, + ACE_OS::memcpy (t, + this->rep_, this->len_ * sizeof (ACE_WSTRING_TYPE)); // 0 terminate @@ -694,13 +378,12 @@ ACE_WString::buffer_size(void) const ACE_INLINE u_long ACE_WString::hash (void) const { - return ACE::hash_pjw + return ACE::hash_pjw (ACE_reinterpret_cast (char *, ACE_const_cast (ACE_WSTRING_TYPE *, - this->rep_)), + this->rep_)), this->len_ * sizeof (ACE_WSTRING_TYPE)); } - ACE_INLINE ACE_Auto_String_Free::ACE_Auto_String_Free (char* p) : p_ (p) diff --git a/ace/String_Base.cpp b/ace/String_Base.cpp new file mode 100644 index 00000000000..4c4fd155919 --- /dev/null +++ b/ace/String_Base.cpp @@ -0,0 +1,183 @@ +// $Id$ + +#include "ace/Malloc.h" +#include "ace/String_Base.h" +#include "ace/Auto_Ptr.h" + +#if !defined (ACE_LACKS_IOSTREAM_TOTALLY) +# include "ace/streams.h" +#endif /* ! ACE_LACKS_IOSTREAM_TOTALLY */ + +#if !defined (__ACE_INLINE__) +#include "ace/String_Base.i" +#endif /* __ACE_INLINE__ */ + +ACE_RCSID(ace, SString, "String_Base.cpp,v 4.61 2001/03/04 00:55:30 brunsch Exp") + +ACE_ALLOC_HOOK_DEFINE(ACE_String_Base) + +template <class CHAR> +CHAR ACE_String_Base<CHAR>::NULL_String_ = '\0'; +template <class CHAR> +const int ACE_String_Base<CHAR>::npos = -1; + +// this method might benefit from a little restructuring. +template <class CHAR> void +ACE_String_Base<CHAR>::set (const CHAR *s, + size_t len, + int release) +{ + // Case 1. Going from memory to more memory + size_t new_buf_len = len + 1; + if (s != 0 && len != 0 && release && this->buf_len_ < new_buf_len) + { + CHAR *temp; + ACE_ALLOCATOR (temp, + (CHAR *) this->allocator_->malloc (new_buf_len * sizeof (CHAR))); + + if (this->release_) + this->allocator_->free (this->rep_); + + this->rep_ = temp; + this->buf_len_ = new_buf_len; + this->release_ = 1; + this->len_ = len; + ACE_OS::memcpy (this->rep_, s, len * sizeof (CHAR)); + // NUL terminate. + this->rep_[len] = '\0'; + } + + // Case 2. No memory allocation is necessary. + else + { + // Free memory if necessary and figure out future ownership + if (!release || s == 0 || len == 0) + if (this->release_) + { + this->allocator_->free (this->rep_); + this->release_ = 0; + } + // else - stay with whatever value for release_ we have. + + // Populate data. + if (s == 0 || len == 0) + { + this->buf_len_ = 0; + this->len_ = 0; + this->rep_ = &ACE_String_Base<CHAR>::NULL_String_; + } + else if (!release) + { + this->buf_len_ = len; + this->len_ = len; + this->rep_ = (CHAR *) s; + } + else + { + ACE_OS::memcpy (this->rep_, s, len * sizeof (CHAR)); + // NUL terminate. + this->rep_[len] = 0; + this->len_ = len; + } + } +} + +// Return substring. +template <class CHAR> ACE_String_Base<CHAR> +ACE_String_Base<CHAR>::substring (size_t offset, + ssize_t length) const +{ + ACE_String_Base<CHAR> nil; + size_t count = length; + + // case 1. empty string + if (this->len_ == 0) + return nil; + + // case 2. start pos past our end + if (offset >= this->len_) + return nil; + // No length == empty string. + else if (length == 0) + return nil; + // Get all remaining bytes. + else if (length == -1 || count > (this->len_ - offset)) + count = this->len_ - offset; + + return ACE_String_Base<CHAR> (&this->rep_[offset], + count, + this->allocator_); +} + +// Concat operator (does copy memory). + +template <class CHAR> ACE_String_Base<CHAR> & +ACE_String_Base<CHAR>::operator+= (const ACE_String_Base<CHAR> &s) +{ + ACE_TRACE ("ACE_String_Base<CHAR>::operator+="); + + if (s.len_ > 0) + { + size_t new_buf_len = this->len_ + s.len_ + 1; + + // case 1. No memory allocation needed. + if (this->buf_len_ >= new_buf_len) + // Copy in data from new string. + ACE_OS::memcpy (this->rep_ + this->len_, + s.rep_, + s.len_ * sizeof (CHAR)); + + // case 2. Memory reallocation is needed + else + { + CHAR *t = 0; + + ACE_ALLOCATOR_RETURN (t, + (CHAR *) this->allocator_->malloc (new_buf_len * + sizeof (CHAR)), + *this); + + // Copy memory from old string into new string. + ACE_OS::memcpy (t, + this->rep_, + this->len_ * sizeof (CHAR)); + + ACE_OS::memcpy (t + this->len_, + s.rep_, + s.len_ * sizeof (CHAR)); + + if (this->release_) + this->allocator_->free (this->rep_); + + this->release_ = 1; + this->rep_ = t; + this->buf_len_ = new_buf_len; + } + + this->len_ += s.len_; + this->rep_[this->len_] = '\0'; + } + + return *this; +} + +template <class CHAR> void +ACE_String_Base<CHAR>::resize (size_t len, CHAR c) +{ + ACE_TRACE ("ACE_String_Base<CHAR>::resize"); + + // Only reallocate if we don't have enough space... + if (this->buf_len_ <= len) + { + if (this->buf_len_ != 0) + this->allocator_->free (this->rep_); + this->rep_ = (CHAR *) + this->allocator_->malloc ((len + 1) * sizeof (CHAR)); + this->buf_len_ = len + 1; + } + + this->len_ = 0; + ACE_OS::memset (this->rep_, + c, + this->buf_len_ * sizeof (CHAR)); +} diff --git a/ace/String_Base.h b/ace/String_Base.h new file mode 100644 index 00000000000..e85a1e73ee4 --- /dev/null +++ b/ace/String_Base.h @@ -0,0 +1,233 @@ +/* -*- C++ -*- */ + +//============================================================================= +/** + * @file String_Base.h + * + * $Id$ + * + * @author Douglas C. Schmidt (schmidt@cs.wustl.edu) + */ +//============================================================================= + +#ifndef ACE_STRING_BASE_H +#define ACE_STRING_BASE_H +#include "ace/pre.h" + +#include "ace/ACE.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +// Forward decl. +class ACE_Allocator; + +/** + * @class ACE_String_Base + * + * @brief This class provides a wrapper facade for C strings. + * + * 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 class is + * optimized for efficiency, so it doesn't provide any internal + * locking. + * 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_String_Base is constructed from a + * provided buffer with the release parameter set to 0, + * ACE_String_Base is not guaranteed to be '\0' terminated. + */ +template <class CHAR> +class ACE_Export ACE_String_Base +{ +public: + /// No position constant + static const int npos; + + /// Default constructor. + ACE_String_Base (ACE_Allocator *alloc = 0); + + /** + * Constructor that copies @a s into dynamically allocated memory. + * If @a release is non-0 then the @a ACE_allocator is responsible for + * freeing this memory. Memory is _not_ allocated/freed if @a release + * is 0. + */ + ACE_String_Base (const CHAR *s, + ACE_Allocator *alloc = 0, + int release = 1); + + /** + * Constructor that copies <len> CHARs of <s> into dynamically + * allocated memory (will NUL terminate the result). If <release> + * is non-0 then the <ACE_allocator> is responsible for freeing this + * memory. Memory is _not_ allocated/freed if <release> is 0. + */ + ACE_String_Base (const CHAR *s, + size_t len, + ACE_Allocator *alloc = 0, + int release = 1); + + /// Copy constructor. + ACE_String_Base (const ACE_String_Base<CHAR> &); + + /// Constructor that copies @a c into dynamically allocated memory. + ACE_String_Base (CHAR c, ACE_Allocator *alloc = 0); + + /// Constructor that dynamically allocate @a len long of char array + /// and initialize it to @a c using @a alloc to allocate the memory. + ACE_String_Base (size_t len, CHAR c = 0, ACE_Allocator *alloc = 0); + + /// Deletes the memory... + ~ACE_String_Base (void); + + /// Return the <slot'th> character in the string (doesn't perform + /// bounds checking). + const CHAR &operator [] (size_t slot) const; + + /// Return the <slot'th> character by reference in the string + /// (doesn't perform bounds checking). + CHAR &operator [] (size_t slot); + + /// Assignment operator (does copy memory). + ACE_String_Base &operator = (const ACE_String_Base<CHAR> &); + + /// Copy @a s into this @a ACE_String_Base. Memory is _not_ + /// allocated/freed if @a release is 0. + void set (const CHAR *s, int release = 1); + + /// Copy @a len bytes of @a s (will NUL terminate the result). + /// Memory is _not_ allocated/freed if @a release is 0. + void set (const CHAR *s, + size_t len, + int release); + + /** + * 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. + */ + ACE_String_Base<CHAR> substring (size_t offset, ssize_t length = -1) const; + + /// Same as <substring>. + ACE_String_Base<CHAR> substr (size_t offset, ssize_t length = -1) const; + + /// Concat operator (copies memory). + ACE_String_Base<CHAR> &operator += (const ACE_String_Base<CHAR> &); + + /// Returns a hash value for this string. + u_long hash (void) const; + + /// Return the length of the string. + size_t length (void) const; + + /// Get a copy of the underlying pointer. + CHAR *rep (void) const; + + /** + * Get at the underlying representation directly! + * _Don't_ even think about casting the result to (char *) and modifying it, + * if it has length 0! + */ + const CHAR *fast_rep (void) const; + + /// Same as STL String's <c_str> and <fast_rep>. + const CHAR *c_str (void) const; + + /// Comparison operator that will match substrings. Returns the + /// slot of the first location that matches, else -1. + int strstr (const ACE_String_Base<CHAR> &s) const; + + /// Find <str> starting at pos. Returns the slot of the first + /// location that matches (will be >= pos), else npos. + int find (const ACE_String_Base<CHAR> &str, int pos = 0) const; + + /// Find <s> starting at pos. Returns the slot of the first + /// location that matches (will be >= pos), else npos. + int find (const CHAR *s, int pos = 0) const; + + /// Find <c> starting at pos. Returns the slot of the first + /// location that matches (will be >= pos), else npos. + int find (CHAR c, int pos = 0) const; + + /// Find <c> starting at pos (counting from the end). Returns the + /// slot of the first location that matches, else npos. + int rfind (CHAR c, int pos = npos) const; + + /// Equality comparison operator (must match entire string). + int operator == (const ACE_String_Base<CHAR> &s) const; + + /// Less than comparison operator. + int operator < (const ACE_String_Base<CHAR> &s) const; + + /// Greater than comparison operator. + int operator > (const ACE_String_Base<CHAR> &s) const; + + /// Inequality comparison operator. + int operator != (const ACE_String_Base<CHAR> &s) const; + + /// Performs a <strcmp>-style comparison. + int compare (const ACE_String_Base<CHAR> &s) const; + + /// Dump the state of an object. + void dump (void) const; + + /** + * 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 zero'd + * out after this operation. + */ + void resize (size_t len, CHAR c = 0); + + /// Declare the dynamic allocation hooks. + ACE_ALLOC_HOOK_DECLARE; + +protected: + /// Pointer to a memory allocator. + ACE_Allocator *allocator_; + + /// Length of the ACE_String_Base data (not counting the trailing '\0'). + size_t len_; + + /// Length of the ACE_String_Base data buffer. Keeping track of the + /// length allows to avoid unnecessary dynamic allocations. + size_t buf_len_; + + /// Pointer to data. + CHAR *rep_; + + /// Flag that indicates if we own the memory + int release_; + + /// Represents the "NULL" string to simplify the internal logic. + static CHAR NULL_String_; +}; + +template <class CHAR> ACE_INLINE +ACE_String_Base<CHAR> operator + (const ACE_String_Base<CHAR> &, + const ACE_String_Base<CHAR> &); +template <class CHAR> ACE_INLINE +ACE_String_Base<CHAR> operator + (const ACE_String_Base<CHAR> &, + const CHAR *); +template <class CHAR> ACE_INLINE +ACE_String_Base<CHAR> operator + (const CHAR* , + const ACE_String_Base<CHAR> &); +#if defined (__ACE_INLINE__) +#include "ace/String_Base.i" +#endif /* __ACE_INLINE__ */ + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "ace/String_Base.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("String_Base.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include "ace/post.h" +#endif /* ACE_STRING_BASE_H */ diff --git a/ace/String_Base.i b/ace/String_Base.i new file mode 100644 index 00000000000..ed63518f126 --- /dev/null +++ b/ace/String_Base.i @@ -0,0 +1,353 @@ +/* -*- C++ -*- */ +// $Id$ + +#include "ace/Malloc_Base.h" + +// Default constructor. + +template <class CHAR> ACE_INLINE +ACE_String_Base<CHAR>::ACE_String_Base (ACE_Allocator *alloc) + : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), + len_ (0), + buf_len_ (0), + rep_ (&ACE_String_Base<CHAR>::NULL_String_), + release_ (0) +{ + ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base"); +} + +// Constructor that actually copies memory. + +template <class CHAR> ACE_INLINE +ACE_String_Base<CHAR>::ACE_String_Base (const CHAR *s, + ACE_Allocator *alloc, + int release) + : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), + len_ (0), + buf_len_ (0), + rep_ (0), + release_ (0) +{ + ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base"); + + size_t length; + if (s != 0) + length = ACE_OS::strlen (s); + else + length = 0; + + this->set (s, length, release); +} + +template <class CHAR> ACE_INLINE +ACE_String_Base<CHAR>::ACE_String_Base (CHAR c, + ACE_Allocator *alloc) + : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), + len_ (0), + buf_len_ (0), + rep_ (0), + release_ (0) +{ + ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base"); + + this->set (&c, 1, 1); +} + +// Constructor that actually copies memory. + +template <class CHAR> ACE_INLINE +ACE_String_Base<CHAR>::ACE_String_Base (const CHAR *s, + size_t len, + ACE_Allocator *alloc, + int release) + : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), + len_ (0), + buf_len_ (0), + rep_ (0), + release_ (0) +{ + ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base"); + + this->set (s, len, release); +} + +// Copy constructor. + +template <class CHAR> ACE_INLINE +ACE_String_Base<CHAR>::ACE_String_Base (const ACE_String_Base<CHAR> &s) + : allocator_ (s.allocator_ ? s.allocator_ : ACE_Allocator::instance ()), + len_ (0), + buf_len_ (0), + rep_ (0), + release_ (0) +{ + ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base"); + + this->set (s.rep_, s.len_, 1); +} + +template <class CHAR> ACE_INLINE +ACE_String_Base<CHAR>::ACE_String_Base (size_t len, CHAR c, ACE_Allocator *alloc) + : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), + len_ (0), + buf_len_ (0), + rep_ (0), + release_ (0) +{ + ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base"); + + this->resize (len, c); +} + +template <class CHAR> ACE_INLINE +ACE_String_Base<CHAR>::~ACE_String_Base (void) +{ + ACE_TRACE ("ACE_String_Base<CHAR>::~ACE_String_Base"); + + this->set (0, 0, 0); +} + +template <class CHAR> ACE_INLINE void +ACE_String_Base<CHAR>::dump (void) const +{ + ACE_TRACE ("ACE_String_Base<CHAR>::dump"); +} + +// Assignment operator (does copy memory). + +template <class CHAR> ACE_INLINE ACE_String_Base<CHAR> & +ACE_String_Base<CHAR>::operator= (const ACE_String_Base<CHAR> &s) +{ + ACE_TRACE ("ACE_String_Base<CHAR>::operator="); + + // Check for identify. + if (this != &s) + this->set (s.rep_, s.len_, 1); + + return *this; +} + +template <class CHAR> ACE_INLINE void +ACE_String_Base<CHAR>::set (const CHAR *s, int release) +{ + size_t length; + if (s != 0) + length = ACE_OS::strlen (s); + else + length = 0; + + this->set (s, length, release); +} + +template <class CHAR> ACE_INLINE size_t +ACE_String_Base<CHAR>::length (void) const +{ + ACE_TRACE ("ACE_String_Base<CHAR>::length"); + return this->len_; +} + +template <class CHAR> ACE_INLINE ACE_String_Base<CHAR> +ACE_String_Base<CHAR>::substr (size_t offset, + ssize_t length) const +{ + return this->substring (offset, length); +} + +// Return the <slot'th> character in the string. + +template <class CHAR> ACE_INLINE const CHAR & +ACE_String_Base<CHAR>::operator[] (size_t slot) const +{ + ACE_TRACE ("ACE_String_Base<CHAR>::operator[]"); + return this->rep_[slot]; +} + +// Return the <slot'th> character in the string by reference. + +template <class CHAR> ACE_INLINE CHAR & +ACE_String_Base<CHAR>::operator[] (size_t slot) +{ + ACE_TRACE ("ACE_String_Base<CHAR>::operator[]"); + return this->rep_[slot]; +} + +// Get a copy of the underlying representation. + +template <class CHAR> ACE_INLINE CHAR * +ACE_String_Base<CHAR>::rep (void) const +{ + ACE_TRACE ("ACE_String_Base<CHAR>::rep"); + + CHAR *new_string; + ACE_NEW_RETURN (new_string, CHAR[this->len_ + 1], 0); + ACE_OS::strncpy (new_string, this->rep_, this->len_); + new_string[this->len_] = '\0'; + + return new_string; +} + +template <class CHAR> ACE_INLINE const CHAR * +ACE_String_Base<CHAR>::fast_rep (void) const +{ + return this->rep_; +} + +template <class CHAR> ACE_INLINE const CHAR * +ACE_String_Base<CHAR>::c_str (void) const +{ + return this->rep_; +} + +// Comparison operator. + +template <class CHAR> ACE_INLINE int +ACE_String_Base<CHAR>::operator== (const ACE_String_Base<CHAR> &s) const +{ + ACE_TRACE ("ACE_String_Base<CHAR>::operator=="); + + return this->len_ == s.len_ + && ACE_OS::strncmp (this->rep_, s.rep_, this->len_) == 0; +} + +// Less than comparison operator. + +template <class CHAR> ACE_INLINE int +ACE_String_Base<CHAR>::operator < (const ACE_String_Base<CHAR> &s) const +{ + ACE_TRACE ("ACE_String_Base<CHAR>::operator <"); + + return (this->rep_ && s.rep_) + ? ACE_OS::strcmp (this->rep_, s.rep_) < 0 + : ((s.rep_) ? 1 : 0 ); +} + +// Greater than comparison operator. + +template <class CHAR> ACE_INLINE int +ACE_String_Base<CHAR>::operator > (const ACE_String_Base &s) const +{ + ACE_TRACE ("ACE_String_Base<CHAR>::operator >"); + + return (this->rep_ && s.rep_) + ? ACE_OS::strcmp (this->rep_, s.rep_) > 0 + : ((this->rep_) ? 1 : 0 ); +} + + +// Comparison operator. + +template <class CHAR> ACE_INLINE int +ACE_String_Base<CHAR>::operator!= (const ACE_String_Base<CHAR> &s) const +{ + ACE_TRACE ("ACE_String_Base<CHAR>::operator!="); + return !(*this == s); +} + +template <class CHAR> ACE_INLINE int +ACE_String_Base<CHAR>::compare (const ACE_String_Base<CHAR> &s) const +{ + ACE_TRACE ("ACE_String_Base<CHAR>::compare"); + + // We can't just pass both strings to strcmp, since they are not + // guaranteed to be null-terminated. + + // Pick smaller of the two lengths and perform the comparison. + int smaller_length = (this->len_ < s.len_) ? this->len_ : s.len_; + int result = ACE_OS::strncmp (this->rep_, + s.rep_, + smaller_length); + + if (result != 0 || s.len_ == this->len_) + return result; + + else + // we need to differentiate based on length + if (this->len_ > s.len_) + return (this->rep_[smaller_length] - '\0'); + + else + return ('\0' - s.rep_[smaller_length]); +} + +template <class CHAR> ACE_INLINE int +ACE_String_Base<CHAR>::find (const CHAR *s, int pos) const +{ + CHAR *substr = this->rep_ + pos; + size_t len = ACE_OS::strlen (s); + CHAR *pointer = ACE_OS::strnstr (substr, s, len); + if (pointer == 0) + return ACE_String_Base<CHAR>::npos; + else + return pointer - this->rep_; +} + +template <class CHAR> ACE_INLINE int +ACE_String_Base<CHAR>::find (CHAR c, int pos) const +{ + CHAR *substr = this->rep_ + pos; + CHAR *pointer = ACE_OS::strnchr (substr, c, this->len_ - pos); + if (pointer == 0) + return ACE_String_Base<CHAR>::npos; + else + return pointer - this->rep_; +} + +template <class CHAR> ACE_INLINE int +ACE_String_Base<CHAR>::find (const ACE_String_Base<CHAR> &str, int pos) const +{ + return this->find (str.rep_, pos); +} + +template <class CHAR> ACE_INLINE int +ACE_String_Base<CHAR>::strstr (const ACE_String_Base<CHAR> &s) const +{ + ACE_TRACE ("ACE_String_Base<CHAR>::strstr"); + + return this->find (s.rep_); +} + +template <class CHAR> ACE_INLINE int +ACE_String_Base<CHAR>::rfind (CHAR c, int pos) const +{ + if (pos == ACE_String_Base<CHAR>::npos) + pos = this->len_; + + for (int i = pos - 1; i >= 0; i--) + if (this->rep_[i] == c) + return i; + + return ACE_String_Base<CHAR>::npos; +} + +template <class CHAR> ACE_INLINE u_long +ACE_String_Base<CHAR>::hash (void) const +{ + return ACE::hash_pjw ( + (ACE_reinterpret_cast (char *, ACE_const_cast (CHAR *, + this->rep_))), + this->len_ * sizeof (CHAR)); +} + +template <class CHAR> ACE_INLINE ACE_String_Base<CHAR> +operator+ (const ACE_String_Base<CHAR> &s, const ACE_String_Base<CHAR> &t) +{ + ACE_String_Base<CHAR> temp (s); + temp += t; + return temp; +} + +template <class CHAR> ACE_INLINE ACE_String_Base<CHAR> +operator+ (const CHAR *s, const ACE_String_Base<CHAR> &t) +{ + ACE_String_Base<CHAR> temp (s); + temp += t; + return temp; +} + +template <class CHAR> ACE_INLINE ACE_String_Base<CHAR> +operator+ (const ACE_String_Base<CHAR> &s, const CHAR *t) +{ + ACE_String_Base<CHAR> temp (s); + temp += t; + return temp; +} diff --git a/ace/ace_dll.dsp b/ace/ace_dll.dsp index 8d0a5ce5c8f..f3312bed1d4 100644 --- a/ace/ace_dll.dsp +++ b/ace/ace_dll.dsp @@ -1910,6 +1910,10 @@ SOURCE=.\streams.h # End Source File
# Begin Source File
+SOURCE=.\String_Base.h
+# End Source File
+# Begin Source File
+
SOURCE=.\SV_Message.h
# End Source File
# Begin Source File
@@ -2826,6 +2830,10 @@ SOURCE=.\Stream_Modules.i # End Source File
# Begin Source File
+SOURCE=.\String_Base.i
+# End Source File
+# Begin Source File
+
SOURCE=.\SV_Message.i
# End Source File
# Begin Source File
diff --git a/ace/ace_lib.dsp b/ace/ace_lib.dsp index 46ade6d9bba..e1f4dbf311b 100644 --- a/ace/ace_lib.dsp +++ b/ace/ace_lib.dsp @@ -42,8 +42,8 @@ RSC=rc.exe # PROP Output_Dir ""
# PROP Intermediate_Dir ".\LIB\Release"
# PROP Target_Dir ""
-MTL=midl.exe
LINK32=link.exe -lib
+MTL=midl.exe
# ADD BASE CPP /nologo /MD /W3 /GX /O1 /I "../" /D ACE_HAS_DLL=0 /D "ACE_NO_INLINE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /FD /c
# SUBTRACT BASE CPP /YX
# ADD CPP /nologo /MT /W3 /GX /O1 /I "../" /I "../PACE" /D ACE_OS_HAS_DLL=0 /D ACE_HAS_DLL=0 /D "ACE_NO_INLINE" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /FD /c
@@ -69,8 +69,8 @@ LIB32=link.exe -lib # PROP Output_Dir ""
# PROP Intermediate_Dir ".\LIB\Debug"
# PROP Target_Dir ""
-MTL=midl.exe
LINK32=link.exe -lib
+MTL=midl.exe
# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /Gy /I "../" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D ACE_HAS_DLL=0 /FD /c
# SUBTRACT BASE CPP /YX
# ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /Gy /I "../" /I "../PACE" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D ACE_HAS_DLL=0 /D ACE_OS_HAS_DLL=0 /FD /c
@@ -96,8 +96,8 @@ LIB32=link.exe -lib # PROP Output_Dir ""
# PROP Intermediate_Dir ".\LIB\Release"
# PROP Target_Dir ""
-MTL=midl.exe
LINK32=link.exe -lib
+MTL=midl.exe
# ADD BASE CPP /nologo /G5 /MT /W3 /GX /O1 /I "../" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D ACE_HAS_DLL=0 /D "ACE_NO_INLINE" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O1 /I "../" /I "../PACE" /D "_WINDOWS" /D "NDEBUG" /D "ACE_AS_STATIC_LIBS" /D "WIN32" /FD /c
# SUBTRACT CPP /YX
@@ -122,8 +122,8 @@ LIB32=link.exe -lib # PROP Output_Dir ""
# PROP Intermediate_Dir ".\LIB\Debug"
# PROP Target_Dir ""
-MTL=midl.exe
LINK32=link.exe -lib
+MTL=midl.exe
# ADD BASE CPP /nologo /G5 /MTd /W3 /Gm /GX /Zi /Od /Gy /I "../" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D ACE_HAS_DLL=0 /D "ACE_NO_INLINE" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /Gy /I "../" /I "../PACE" /D "_WINDOWS" /D "_DEBUG" /D "ACE_AS_STATIC_LIBS" /D "WIN32" /FD /c
# SUBTRACT CPP /YX
@@ -1905,6 +1905,10 @@ SOURCE=.\streams.h # End Source File
# Begin Source File
+SOURCE=.\String_Base.h
+# End Source File
+# Begin Source File
+
SOURCE=.\SV_Message.h
# End Source File
# Begin Source File
@@ -2829,6 +2833,10 @@ SOURCE=.\Stream_Modules.i # End Source File
# Begin Source File
+SOURCE=.\String_Base.i
+# End Source File
+# Begin Source File
+
SOURCE=.\SV_Message.i
# End Source File
# Begin Source File
|