#include <String_Base.h>
Inheritance diagram for ACE_String_Base:


Public Methods | |
| ACE_String_Base (ACE_Allocator *alloc=0) | |
| ACE_String_Base (const CHAR *s, ACE_Allocator *alloc=0, int release=1) | |
| ACE_String_Base (const CHAR *s, size_t len, ACE_Allocator *alloc=0, int release=1) | |
| ACE_String_Base (const ACE_String_Base< CHAR > &s) | |
| ACE_String_Base (CHAR c, ACE_Allocator *alloc=0) | |
| ACE_String_Base (size_t len, CHAR c=0, ACE_Allocator *alloc=0) | |
| ~ACE_String_Base (void) | |
| const CHAR & | operator[] (size_t slot) const |
| CHAR & | operator[] (size_t slot) |
| ACE_String_Base< CHAR > & | operator= (const ACE_String_Base< CHAR > &s) |
| ACE_String_Base< CHAR > & | assign_nocopy (const ACE_String_Base< CHAR > &s) |
| void | set (const CHAR *s, int release=1) |
| void | set (const CHAR *s, size_t len, int release) |
| void | clear (int release=0) |
| ACE_String_Base< CHAR > | substring (size_t offset, ssize_t length=-1) const |
| ACE_String_Base< CHAR > | substr (size_t offset, ssize_t length=-1) const |
| ACE_String_Base< CHAR > & | operator+= (const ACE_String_Base< CHAR > &s) |
| u_long | hash (void) const |
| size_t | length (void) const |
| CHAR * | rep (void) const |
| const CHAR * | fast_rep (void) const |
| const CHAR * | c_str (void) const |
| ssize_t | strstr (const ACE_String_Base< CHAR > &s) const |
| ssize_t | find (const ACE_String_Base< CHAR > &str, size_t pos=0) const |
| ssize_t | find (const CHAR *s, size_t pos=0) const |
| ssize_t | find (CHAR c, size_t pos=0) const |
| ssize_t | rfind (CHAR c, ssize_t pos=npos) const |
| int | operator== (const ACE_String_Base< CHAR > &s) const |
| int | operator< (const ACE_String_Base< CHAR > &s) const |
| int | operator> (const ACE_String_Base< CHAR > &s) const |
| int | operator!= (const ACE_String_Base< CHAR > &s) const |
| int | compare (const ACE_String_Base< CHAR > &s) const |
| void | dump (void) const |
| void | resize (size_t len, CHAR c=0) |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
Protected Attributes | |
| ACE_Allocator * | allocator_ |
| size_t | len_ |
| size_t | buf_len_ |
| CHAR * | rep_ |
| int | release_ |
Static Protected Attributes | |
| CHAR | NULL_String_ = '\0' |
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.
Definition at line 46 of file String_Base.h.
|
||||||||||
|
Default constructor.
Definition at line 9 of file String_Base.i. References ACE_TRACE.
00010 : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), 00011 len_ (0), 00012 buf_len_ (0), 00013 rep_ (&ACE_String_Base<CHAR>::NULL_String_), 00014 release_ (0) 00015 { 00016 ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base"); 00017 } |
|
||||||||||||||||||||
|
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.
Definition at line 22 of file String_Base.i. References ACE_TRACE, length, set, and ACE_OS_String::strlen.
00025 : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), 00026 len_ (0), 00027 buf_len_ (0), 00028 rep_ (0), 00029 release_ (0) 00030 { 00031 ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base"); 00032 00033 size_t length; 00034 if (s != 0) 00035 length = ACE_OS::strlen (s); 00036 else 00037 length = 0; 00038 00039 this->set (s, length, release); 00040 } |
|
||||||||||||||||||||||||
|
Constructor that copies len CHARs of s into dynamically allocated memory (will zero 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.
Definition at line 59 of file String_Base.i. References ACE_TRACE, and set.
00063 : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), 00064 len_ (0), 00065 buf_len_ (0), 00066 rep_ (0), 00067 release_ (0) 00068 { 00069 ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base"); 00070 00071 this->set (s, len, release); 00072 } |
|
||||||||||
|
Copy constructor.
Definition at line 77 of file String_Base.i. References ACE_TRACE, and set.
00078 : allocator_ (s.allocator_ ? s.allocator_ : ACE_Allocator::instance ()), 00079 len_ (0), 00080 buf_len_ (0), 00081 rep_ (0), 00082 release_ (0) 00083 { 00084 ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base"); 00085 00086 this->set (s.rep_, s.len_, 1); 00087 } |
|
||||||||||||||||
|
Constructor that copies c into dynamically allocated memory.
Definition at line 43 of file String_Base.i. References ACE_TRACE, and set.
00045 : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), 00046 len_ (0), 00047 buf_len_ (0), 00048 rep_ (0), 00049 release_ (0) 00050 { 00051 ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base"); 00052 00053 this->set (&c, 1, 1); 00054 } |
|
||||||||||||||||||||
|
Constructor that dynamically allocate len long of char array and initialize it to c using alloc to allocate the memory.
Definition at line 90 of file String_Base.i. References ACE_TRACE, and resize.
00091 : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), 00092 len_ (0), 00093 buf_len_ (0), 00094 rep_ (0), 00095 release_ (0) 00096 { 00097 ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base"); 00098 00099 this->resize (len, c); 00100 } |
|
||||||||||
|
Deletes the memory... Definition at line 103 of file String_Base.i. References ACE_TRACE, and set.
|
|
||||||||||
|
Assignment alternative method (does not copy memory).
Definition at line 131 of file String_Base.i. References len_, rep_, and set.
|
|
||||||||||
|
Same as STL String's <c_str> and <fast_rep>. Definition at line 208 of file String_Base.i. References rep_.
00209 {
00210 return this->rep_;
00211 }
|
|
||||||||||
|
Clear this string. Memory is _not_ freed if <release> is 0.
Definition at line 157 of file String_Base.i. References set.
00158 {
00159 this->set(0, 0, release);
00160 }
|
|
||||||||||
|
Performs a strncmp comparison.
Definition at line 214 of file String_Base.i. References ace_min, ACE_TRACE, len_, ACE_OS_String::memcmp, and rep_. Referenced by operator<, operator==, and operator>.
00215 {
00216 ACE_TRACE ("ACE_String_Base<CHAR>::compare");
00217
00218 // Pick smaller of the two lengths and perform the comparison.
00219 size_t smaller_length = ace_min (this->len_, s.len_);
00220
00221 int result = ACE_OS::memcmp (this->rep_,
00222 s.rep_,
00223 smaller_length * sizeof (CHAR));
00224
00225 if (!result)
00226 result = ACE_static_cast (int, (this->len_ - s.len_));
00227 return result;
00228 }
|
|
||||||||||
|
Dump the state of an object. Definition at line 111 of file String_Base.i. References ACE_TRACE.
00112 {
00113 ACE_TRACE ("ACE_String_Base<CHAR>::dump");
00114 }
|
|
||||||||||
|
Get at the underlying representation directly! _Don't_ even think about casting the result to (char *) and modifying it, if it has length 0!
Definition at line 202 of file String_Base.i. References rep_.
00203 {
00204 return this->rep_;
00205 }
|
|
||||||||||||||||
|
Find c starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos.
Definition at line 282 of file String_Base.i. References rep_, ACE_OS_String::strnchr, and substr.
00283 {
00284 CHAR *substr = this->rep_ + pos;
00285 CHAR *pointer = ACE_OS::strnchr (substr, c, this->len_ - pos);
00286 if (pointer == 0)
00287 return ACE_String_Base<CHAR>::npos;
00288 else
00289 return pointer - this->rep_;
00290 }
|
|
||||||||||||||||
|
Find s starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos.
Definition at line 270 of file String_Base.i. References rep_, ACE_OS_String::strlen, ACE_OS_String::strnstr, and substr.
00271 {
00272 CHAR *substr = this->rep_ + pos;
00273 size_t len = ACE_OS::strlen (s);
00274 CHAR *pointer = ACE_OS::strnstr (substr, s, len);
00275 if (pointer == 0)
00276 return ACE_String_Base<CHAR>::npos;
00277 else
00278 return pointer - this->rep_;
00279 }
|
|
||||||||||||||||
|
Find <str> starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos.
Definition at line 293 of file String_Base.i. References rep_. Referenced by strstr.
|
|
||||||||||
|
Returns a hash value for this string.
Definition at line 320 of file String_Base.i. References ACE::hash_pjw.
00321 {
00322 return ACE::hash_pjw ((ACE_reinterpret_cast (char *,
00323 ACE_const_cast (CHAR *,
00324 this->rep_))),
00325 this->len_ * sizeof (CHAR));
00326 }
|
|
||||||||||
|
Return the length of the string.
Definition at line 150 of file String_Base.i. References ACE_TRACE, and len_. Referenced by ACE_String_Base, set, substr, and substring.
|
|
||||||||||
|
Inequality comparison operator.
Definition at line 263 of file String_Base.i. References ACE_TRACE.
00264 {
00265 ACE_TRACE ("ACE_String_Base<CHAR>::operator!=");
00266 return !(*this == s);
00267 }
|
|
||||||||||
|
Concat operator (copies memory).
Definition at line 115 of file String_Base.cpp. References ACE_ALLOCATOR_RETURN, ACE_TRACE, allocator_, buf_len_, ACE_Allocator::free, len_, ACE_OS_String::memcpy, release_, and rep_.
00116 {
00117 ACE_TRACE ("ACE_String_Base<CHAR>::operator+=");
00118
00119 if (s.len_ > 0)
00120 {
00121 size_t new_buf_len = this->len_ + s.len_ + 1;
00122
00123 // case 1. No memory allocation needed.
00124 if (this->buf_len_ >= new_buf_len)
00125 // Copy in data from new string.
00126 ACE_OS::memcpy (this->rep_ + this->len_,
00127 s.rep_,
00128 s.len_ * sizeof (CHAR));
00129 // case 2. Memory reallocation is needed
00130 else
00131 {
00132 CHAR *t = 0;
00133
00134 ACE_ALLOCATOR_RETURN (t,
00135 (CHAR *) this->allocator_->malloc (new_buf_len *
00136 sizeof (CHAR)),
00137 *this);
00138
00139 // Copy memory from old string into new string.
00140 ACE_OS::memcpy (t,
00141 this->rep_,
00142 this->len_ * sizeof (CHAR));
00143
00144 ACE_OS::memcpy (t + this->len_,
00145 s.rep_,
00146 s.len_ * sizeof (CHAR));
00147
00148 if (this->release_)
00149 this->allocator_->free (this->rep_);
00150
00151 this->release_ = 1;
00152 this->rep_ = t;
00153 this->buf_len_ = new_buf_len;
00154 }
00155
00156 this->len_ += s.len_;
00157 this->rep_[this->len_] = '\0';
00158 }
00159
00160 return *this;
00161 }
|
|
||||||||||
|
Less than comparison operator.
Definition at line 244 of file String_Base.i. References ACE_TRACE, and compare.
|
|
||||||||||
|
Assignment operator (does copy memory).
Definition at line 118 of file String_Base.i. References ACE_TRACE, len_, rep_, and set.
|
|
||||||||||
|
Equality comparison operator (must match entire string).
Definition at line 234 of file String_Base.i. References ACE_TRACE, and compare.
|
|
||||||||||
|
Greater than comparison operator.
Definition at line 253 of file String_Base.i. References ACE_TRACE, and compare.
|
|
||||||||||
|
Return the <slot'th> character by reference in the string (doesn't perform bounds checking).
Definition at line 181 of file String_Base.i. References ACE_TRACE, and rep_.
|
|
||||||||||
|
Return the <slot'th> character in the string (doesn't perform bounds checking).
Definition at line 172 of file String_Base.i. References ACE_TRACE, and rep_.
|
|
||||||||||
|
Get a copy of the underlying representation. This method allocates memory for a copy of the string and returns a pointer to the new area. The caller is responsible for freeing the memory when finished; use delete []
Definition at line 190 of file String_Base.i. References ACE_NEW_RETURN, ACE_TRACE, and ACE_OS_String::strsncpy.
00191 {
00192 ACE_TRACE ("ACE_String_Base<CHAR>::rep");
00193
00194 CHAR *new_string;
00195 ACE_NEW_RETURN (new_string, CHAR[this->len_ + 1], 0);
00196 ACE_OS::strsncpy (new_string, this->rep_, this->len_+1);
00197
00198 return new_string;
00199 }
|
|
||||||||||||||||
|
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.
Definition at line 164 of file String_Base.cpp. References ACE_TRACE, allocator_, buf_len_, ACE_Allocator::free, len_, ACE_Allocator::malloc, ACE_OS_String::memset, and rep_. Referenced by ACE_String_Base.
00165 {
00166 ACE_TRACE ("ACE_String_Base<CHAR>::resize");
00167
00168 // Only reallocate if we don't have enough space...
00169 if (this->buf_len_ <= len)
00170 {
00171 if (this->buf_len_ != 0)
00172 this->allocator_->free (this->rep_);
00173
00174 this->rep_ = (CHAR *)
00175 this->allocator_->malloc ((len + 1) * sizeof (CHAR));
00176 this->buf_len_ = len + 1;
00177 }
00178
00179 this->len_ = 0;
00180 ACE_OS::memset (this->rep_,
00181 c,
00182 this->buf_len_ * sizeof (CHAR));
00183 }
|
|
||||||||||||||||
|
Find c starting at pos (counting from the end). Returns the slot of the first location that matches, else npos.
Definition at line 307 of file String_Base.i. References ACE_String_Base_Const::npos, rep_, and ssize_t.
|
|
||||||||||||||||||||
|
Copy len bytes of s (will zero terminate the result). Memory is _not_ allocated/freed if release is 0.
Definition at line 24 of file String_Base.cpp. References ACE_ALLOCATOR, allocator_, buf_len_, ACE_Allocator::free, len_, ACE_OS_String::memcpy, release_, and rep_.
00027 {
00028 // Case 1. Going from memory to more memory
00029 size_t new_buf_len = len + 1;
00030 if (s != 0 && len != 0 && release && this->buf_len_ < new_buf_len)
00031 {
00032 CHAR *temp;
00033 ACE_ALLOCATOR (temp,
00034 (CHAR *) this->allocator_->malloc (new_buf_len * sizeof (CHAR)));
00035
00036 if (this->release_)
00037 this->allocator_->free (this->rep_);
00038
00039 this->rep_ = temp;
00040 this->buf_len_ = new_buf_len;
00041 this->release_ = 1;
00042 this->len_ = len;
00043 ACE_OS::memcpy (this->rep_, s, len * sizeof (CHAR));
00044 // NUL terminate.
00045 this->rep_[len] = '\0';
00046 }
00047
00048 // Case 2. No memory allocation is necessary.
00049 else
00050 {
00051 // Free memory if necessary and figure out future ownership
00052 if (!release || s == 0 || len == 0)
00053 {
00054 if (this->release_)
00055 {
00056 this->allocator_->free (this->rep_);
00057 this->release_ = 0;
00058 }
00059 }
00060 // else - stay with whatever value for release_ we have.
00061
00062 // Populate data.
00063 if (s == 0 || len == 0)
00064 {
00065 this->buf_len_ = 0;
00066 this->len_ = 0;
00067 this->rep_ = &ACE_String_Base<CHAR>::NULL_String_;
00068 }
00069 else if (!release)
00070 {
00071 this->buf_len_ = len;
00072 this->len_ = len;
00073 this->rep_ = (CHAR *) s;
00074 }
00075 else
00076 {
00077 ACE_OS::memcpy (this->rep_, s, len * sizeof (CHAR));
00078 // NUL terminate.
00079 this->rep_[len] = 0;
00080 this->len_ = len;
00081 }
00082 }
00083 }
|
|
||||||||||||||||
|
Copy s into this ACE_String_Base. Memory is _not_ allocated/freed if release is 0.
Definition at line 138 of file String_Base.i. References length, and ACE_OS_String::strlen. Referenced by ACE_String_Base, assign_nocopy, clear, operator=, and ~ACE_String_Base.
|
|
||||||||||
|
Comparison operator that will match substrings. Returns the slot of the first location that matches, else -1.
Definition at line 299 of file String_Base.i. References ACE_TRACE, find, and rep_.
|
|
||||||||||||||||
|
Same as <substring>.
Definition at line 163 of file String_Base.i. References length, ssize_t, and substring. Referenced by find.
|
|
||||||||||||||||
|
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.
Definition at line 87 of file String_Base.cpp. References allocator_, len_, length, rep_, and ssize_t. Referenced by substr.
00089 {
00090 ACE_String_Base<CHAR> nill;
00091 size_t count = length;
00092
00093 // case 1. empty string
00094 if (this->len_ == 0)
00095 return nill;
00096
00097 // case 2. start pos past our end
00098 if (offset >= this->len_)
00099 return nill;
00100 // No length == empty string.
00101 else if (length == 0)
00102 return nill;
00103 // Get all remaining bytes.
00104 else if (length == -1 || count > (this->len_ - offset))
00105 count = this->len_ - offset;
00106
00107 return ACE_String_Base<CHAR> (&this->rep_[offset],
00108 count,
00109 this->allocator_);
00110 }
|
|
|||||
|
Declare the dynamic allocation hooks. Definition at line 373 of file String_Base.h. |
|
|||||
|
Pointer to a memory allocator. Definition at line 379 of file String_Base.h. Referenced by operator+=, resize, set, and substring. |
|
|||||
|
Length of the ACE_String_Base data buffer. Keeping track of the length allows to avoid unnecessary dynamic allocations. Definition at line 390 of file String_Base.h. Referenced by operator+=, resize, and set. |
|
|||||
|
Length of the ACE_String_Base data (not counting the trailing '\0'). Definition at line 384 of file String_Base.h. Referenced by assign_nocopy, compare, length, operator+=, operator=, resize, set, and substring. |
|
|||||
|
Represents the "NULL" string to simplify the internal logic. Definition at line 20 of file String_Base.cpp. |
|
|||||
|
Flag that indicates if we own the memory Definition at line 400 of file String_Base.h. Referenced by operator+=, and set. |
|
|||||
|
Pointer to data. Definition at line 395 of file String_Base.h. Referenced by assign_nocopy, c_str, compare, fast_rep, find, operator+=, operator=, operator[], resize, rfind, set, strstr, and substring. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002