#include <SString.h>
Collaboration diagram for ACE_SString:
Public Types | |
typedef ACE_Allocator::size_type | size_type |
Public Member Functions | |
ACE_SString (ACE_Allocator *alloc=0) | |
Default constructor. | |
ACE_SString (const char *s, ACE_Allocator *alloc=0) | |
Constructor that copies s into dynamically allocated memory. | |
ACE_SString (const char *s, size_type len, ACE_Allocator *alloc=0) | |
ACE_SString (const ACE_SString &) | |
Copy constructor. | |
ACE_SString (char c, ACE_Allocator *alloc=0) | |
Constructor that copies c into dynamically allocated memory. | |
~ACE_SString (void) | |
Default destructor. | |
char | operator[] (size_type slot) const |
char & | operator[] (size_type slot) |
ACE_SString & | operator= (const ACE_SString &) |
Assignment operator (does copy memory). | |
ACE_SString | substring (size_type offset, size_type length=npos) const |
ACE_SString | substr (size_type offset, size_type length=npos) const |
Same as substring. | |
u_long | hash (void) const |
Returns a hash value for this string. | |
size_type | length (void) const |
Return the length of the string. | |
void | rep (char *s) |
const char * | rep (void) const |
Get the underlying pointer. | |
const char * | fast_rep (void) const |
Get the underlying pointer. | |
const char * | c_str (void) const |
Same as STL String's and . | |
size_type | strstr (const ACE_SString &s) const |
size_type | find (const ACE_SString &str, size_type pos=0) const |
size_type | find (const char *s, size_type pos=0) const |
size_type | find (char c, size_type pos=0) const |
size_type | rfind (char c, size_type pos=npos) const |
bool | operator== (const ACE_SString &s) const |
Equality comparison operator (must match entire string). | |
bool | operator< (const ACE_SString &s) const |
Less than comparison operator. | |
bool | operator> (const ACE_SString &s) const |
Greater than comparison operator. | |
bool | operator!= (const ACE_SString &s) const |
Inequality comparison operator. | |
int | compare (const ACE_SString &s) const |
Performs a -style comparison. | |
void | dump (void) const |
Dump the state of an object. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Static Public Attributes | |
const size_type | npos |
No position constant. | |
Private Attributes | |
ACE_Allocator * | allocator_ |
Pointer to a memory allocator. | |
size_type | len_ |
Length of the ACE_SString (not counting the trailing ''). | |
char * | rep_ |
Pointer to data. |
This class is optimized for efficiency, so it doesn't provide any internal locking. CAUTION: 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.
Definition at line 127 of file SString.h.
|
|
|
Default constructor.
Definition at line 194 of file SString.cpp. References ACE_TRACE, ACE_Allocator::instance(), and ACE_Allocator::malloc(). Referenced by substring().
00195 : allocator_ (alloc), 00196 len_ (0), 00197 rep_ (0) 00198 00199 { 00200 ACE_TRACE ("ACE_SString::ACE_SString"); 00201 00202 if (this->allocator_ == 0) 00203 this->allocator_ = ACE_Allocator::instance (); 00204 00205 this->len_ = 0; 00206 this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); 00207 this->rep_[this->len_] = '\0'; 00208 } |
|
Constructor that copies s into dynamically allocated memory.
Definition at line 227 of file SString.cpp. References ACE_TRACE, ACE_Allocator::instance(), ACE_Allocator::malloc(), ACE_OS::strcpy(), and ACE_OS::strlen().
00229 : allocator_ (alloc) 00230 { 00231 ACE_TRACE ("ACE_SString::ACE_SString"); 00232 00233 if (this->allocator_ == 0) 00234 this->allocator_ = ACE_Allocator::instance (); 00235 00236 if (s == 0) 00237 { 00238 this->len_ = 0; 00239 this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); 00240 this->rep_[this->len_] = '\0'; 00241 } 00242 else 00243 { 00244 this->len_ = ACE_OS::strlen (s); 00245 this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); 00246 ACE_OS::strcpy (this->rep_, s); 00247 } 00248 } |
|
Constructor that copies len chars of into dynamically allocated memory (will NUL terminate the result). Definition at line 267 of file SString.cpp. References ACE_TRACE, ACE_Allocator::instance(), ACE_Allocator::malloc(), ACE_OS::memcpy(), and ACE_Array_Base< T >::size_type.
00270 : allocator_ (alloc) 00271 { 00272 ACE_TRACE ("ACE_SString::ACE_SString"); 00273 00274 if (this->allocator_ == 0) 00275 this->allocator_ = ACE_Allocator::instance (); 00276 00277 if (s == 0) 00278 { 00279 this->len_ = 0; 00280 this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); 00281 this->rep_[this->len_] = '\0'; 00282 } 00283 else 00284 { 00285 this->len_ = len; 00286 this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); 00287 ACE_OS::memcpy (this->rep_, s, len); 00288 this->rep_[len] = '\0'; // Make sure to NUL terminate this! 00289 } 00290 } |
|
Copy constructor.
Definition at line 176 of file SString.cpp. References ACE_TRACE, ACE_Allocator::instance(), len_, ACE_Allocator::malloc(), ACE_OS::memcpy(), and rep_.
00177 : allocator_ (s.allocator_), 00178 len_ (s.len_) 00179 { 00180 ACE_TRACE ("ACE_SString::ACE_SString"); 00181 00182 if (this->allocator_ == 0) 00183 this->allocator_ = ACE_Allocator::instance (); 00184 00185 this->rep_ = (char *) this->allocator_->malloc (s.len_ + 1); 00186 ACE_OS::memcpy ((void *) this->rep_, 00187 (const void *) s.rep_, 00188 this->len_); 00189 this->rep_[this->len_] = '\0'; 00190 } |
|
Constructor that copies c into dynamically allocated memory.
Definition at line 250 of file SString.cpp. References ACE_TRACE, ACE_Allocator::instance(), and ACE_Allocator::malloc().
00252 : allocator_ (alloc) 00253 { 00254 ACE_TRACE ("ACE_SString::ACE_SString"); 00255 00256 if (this->allocator_ == 0) 00257 this->allocator_ = ACE_Allocator::instance (); 00258 00259 this->len_ = 1; 00260 this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); 00261 this->rep_[0] = c; 00262 this->rep_[this->len_] = '\0'; 00263 } |
|
Default destructor.
Definition at line 66 of file SString.inl.
00067 { 00068 } |
|
Same as STL String's and .
Definition at line 116 of file SString.inl. References ACE_TRACE.
|
|
Performs a -style comparison.
Definition at line 166 of file SString.inl. References ACE_TRACE, rep_, and ACE_OS::strcmp().
00167 { 00168 ACE_TRACE ("ACE_SString::compare"); 00169 return ACE_OS::strcmp (this->rep_, s.rep_); 00170 } |
|
Dump the state of an object.
Definition at line 167 of file SString.cpp. References ACE_TRACE.
00168 { 00169 #if defined (ACE_HAS_DUMP) 00170 ACE_TRACE ("ACE_SString::dump"); 00171 #endif /* ACE_HAS_DUMP */ 00172 } |
|
Get the underlying pointer.
Definition at line 107 of file SString.inl. References ACE_TRACE. Referenced by operator<<().
|
|
Find starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos. Definition at line 184 of file SString.inl. References npos, ACE_Array_Base< T >::size_type, ACE_OS::strchr(), and substr().
00185 { 00186 char *substr = this->rep_ + pos; 00187 char *pointer = ACE_OS::strchr (substr, c); 00188 if (pointer == 0) 00189 return ACE_SString::npos; 00190 else 00191 return pointer - this->rep_; 00192 } |
|
Find starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos. Definition at line 173 of file SString.inl. References npos, ACE_Array_Base< T >::size_type, ACE_OS::strstr(), and substr().
00174 { 00175 char *substr = this->rep_ + pos; 00176 char *pointer = ACE_OS::strstr (substr, s); 00177 if (pointer == 0) 00178 return ACE_SString::npos; 00179 else 00180 return pointer - this->rep_; 00181 } |
|
Find starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos. Definition at line 203 of file SString.inl. References rep_, and ACE_Array_Base< T >::size_type. Referenced by strstr().
|
|
Returns a hash value for this string.
Definition at line 224 of file SString.inl. References ACE::hash_pjw().
00225 { 00226 return ACE::hash_pjw (this->rep_); 00227 } |
|
Return the length of the string.
Definition at line 230 of file SString.inl. References ACE_TRACE.
|
|
Inequality comparison operator.
Definition at line 159 of file SString.inl. References ACE_TRACE.
00160 { 00161 ACE_TRACE ("ACE_SString::operator!="); 00162 return !(*this == s); 00163 } |
|
Less than comparison operator.
Definition at line 135 of file SString.inl. References ACE_TRACE, rep_, and ACE_OS::strcmp().
|
|
Assignment operator (does copy memory).
Definition at line 295 of file SString.cpp. References ACE_TRACE, ACE_Allocator::free(), len_, ACE_Allocator::malloc(), rep_, and ACE_OS::strcpy().
00296 { 00297 ACE_TRACE ("ACE_SString::operator="); 00298 // Check for identify. 00299 00300 if (this != &s) 00301 { 00302 // Only reallocate if we don't have enough space... 00303 if (this->len_ < s.len_) 00304 { 00305 this->allocator_->free (this->rep_); 00306 this->rep_ = (char *) this->allocator_->malloc (s.len_ + 1); 00307 } 00308 this->len_ = s.len_; 00309 ACE_OS::strcpy (this->rep_, s.rep_); 00310 } 00311 00312 return *this; 00313 } |
|
Equality comparison operator (must match entire string).
Definition at line 125 of file SString.inl. References ACE_TRACE, len_, rep_, and ACE_OS::strcmp().
00126 { 00127 ACE_TRACE ("ACE_SString::operator=="); 00128 return this->len_ == s.len_ 00129 && ACE_OS::strcmp (this->rep_, s.rep_) == 0; 00130 } |
|
Greater than comparison operator.
Definition at line 147 of file SString.inl. References ACE_TRACE, rep_, and ACE_OS::strcmp().
|
|
Return the <slot'th> character by reference in the string (doesn't perform bounds checking). Definition at line 89 of file SString.inl. References ACE_TRACE, and ACE_Array_Base< T >::size_type.
|
|
Return the <slot'th> character in the string (doesn't perform bounds checking). Definition at line 80 of file SString.inl. References ACE_TRACE, and ACE_Array_Base< T >::size_type.
|
|
Get the underlying pointer.
Definition at line 98 of file SString.inl. References ACE_TRACE.
|
|
Set the underlying pointer. Since this does not copy memory or delete existing memory use with extreme caution!!! Definition at line 213 of file SString.cpp. References ACE_TRACE, and ACE_OS::strlen().
00214 { 00215 ACE_TRACE ("ACE_SString::rep"); 00216 00217 this->rep_ = s; 00218 00219 if (s == 0) 00220 this->len_ = 0; 00221 else 00222 this->len_ = ACE_OS::strlen (s); 00223 } |
|
Find starting at pos (counting from the end). Returns the slot of the first location that matches, else npos. Definition at line 209 of file SString.inl. References npos, and ACE_Array_Base< T >::size_type.
00210 { 00211 if (pos == ACE_SString::npos) 00212 pos = this->len_; 00213 00214 // Do not change to prefix operator! Proper operation of this loop 00215 // depends on postfix decrement behavior. 00216 for (size_type i = pos; i-- != 0; ) 00217 if (this->rep_[i] == c) 00218 return i; 00219 00220 return ACE_SString::npos; 00221 } |
|
Comparison operator that will match substrings. Returns the slot of the first location that matches, else Definition at line 195 of file SString.inl. References ACE_TRACE, find(), and rep_.
|
|
Same as substring.
Definition at line 71 of file SString.inl. References ACE_Array_Base< T >::size_type, and substring(). Referenced by find().
00073 { 00074 return this->substring (offset, length); 00075 } |
|
Return a substring given an offset and length, if length == npos use rest of str return empty substring if offset or offset/length are invalid Definition at line 317 of file SString.cpp. References ACE_SString(), npos, and ACE_Array_Base< T >::size_type. Referenced by substr().
00319 { 00320 size_t count = length; 00321 00322 // case 1. empty string 00323 if (len_ == 0) 00324 return ACE_SString (); 00325 00326 // case 2. start pos l 00327 if (offset >= len_) 00328 return ACE_SString (); 00329 00330 // get all remaining bytes 00331 if (length == npos || count > (this->len_ - offset)) 00332 count = len_ - offset; 00333 00334 return ACE_SString (&rep_[offset], count, this->allocator_); 00335 } |
|
Declare the dynamic allocation hooks.
|
|
Pointer to a memory allocator.
|
|
Length of the ACE_SString (not counting the trailing '').
Definition at line 241 of file SString.h. Referenced by ACE_SString(), operator=(), and operator==(). |
|
Initial value: No position constant.
Definition at line 161 of file SString.cpp. Referenced by find(), rfind(), and substring(). |
|
Pointer to data.
Definition at line 244 of file SString.h. Referenced by ACE_SString(), compare(), find(), operator<(), operator=(), operator==(), operator>(), and strstr(). |