#include <SString.h>
Collaboration diagram for ACE_SString:

Public Methods | |
| ACE_SString (ACE_Allocator *alloc=0) | |
| Default constructor. More... | |
| ACE_SString (const char *s, ACE_Allocator *alloc=0) | |
| Constructor that copies s into dynamically allocated memory. More... | |
| 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). More... | |
| ACE_SString (const ACE_SString &) | |
| Copy constructor. More... | |
| ACE_SString (char c, ACE_Allocator *alloc=0) | |
| Constructor that copies c into dynamically allocated memory. More... | |
| ~ACE_SString (void) | |
| Default destructor. More... | |
| char | operator[] (size_t slot) const |
| Return the <slot'th> character in the string (doesn't perform bounds checking). More... | |
| char & | operator[] (size_t slot) |
| Return the <slot'th> character by reference in the string (doesn't perform bounds checking). More... | |
| ACE_SString & | operator= (const ACE_SString &) |
| Assignment operator (does copy memory). More... | |
| ACE_SString | substring (size_t offset, ssize_t length=-1) const |
| ACE_SString | substr (size_t offset, ssize_t length=-1) const |
| Same as substring. More... | |
| u_long | hash (void) const |
| Returns a hash value for this string. More... | |
| size_t | length (void) const |
| Return the length of the string. More... | |
| void | rep (char *s) |
| Set the underlying pointer. Since this does not copy memory or delete existing memory use with extreme caution!!! More... | |
| const char * | rep (void) const |
| Get the underlying pointer. More... | |
| const char * | fast_rep (void) const |
| Get the underlying pointer. More... | |
| const char * | c_str (void) const |
| Same as STL String's <c_str> and <fast_rep>. More... | |
| int | strstr (const ACE_SString &s) const |
| Comparison operator that will match substrings. Returns the slot of the first location that matches, else -1. More... | |
| int | find (const ACE_SString &str, int pos=0) const |
| Find <str> starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos. More... | |
| int | find (const char *s, int pos=0) const |
| Find <s> starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos. More... | |
| int | find (char c, int pos=0) const |
| Find <c> starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos. More... | |
| int | rfind (char c, int pos=npos) const |
| Find <c> starting at pos (counting from the end). Returns the slot of the first location that matches, else npos. More... | |
| int | operator== (const ACE_SString &s) const |
| Equality comparison operator (must match entire string). More... | |
| int | operator< (const ACE_SString &s) const |
| Less than comparison operator. More... | |
| int | operator> (const ACE_SString &s) const |
| Greater than comparison operator. More... | |
| int | operator!= (const ACE_SString &s) const |
| Inequality comparison operator. More... | |
| int | compare (const ACE_SString &s) const |
| Performs a <strcmp>-style comparison. More... | |
| void | dump (void) const |
| Dump the state of an object. More... | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. More... | |
Static Public Attributes | |
| const int | npos = -1 |
| No position constant. More... | |
Private Attributes | |
| ACE_Allocator * | allocator_ |
| Pointer to a memory allocator. More... | |
| size_t | len_ |
| Length of the ACE_SString (not counting the trailing '\0'). More... | |
| char * | rep_ |
| Pointer to data. More... | |
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 117 of file SString.h.
|
|
Default constructor.
Definition at line 382 of file SString.cpp. References ACE_TRACE, allocator_, ACE_Allocator::instance, len_, ACE_Allocator::malloc, and rep_. Referenced by substring.
00383 : allocator_ (alloc), 00384 len_ (0), 00385 rep_ (0) 00386 00387 { 00388 ACE_TRACE ("ACE_SString::ACE_SString"); 00389 00390 if (this->allocator_ == 0) 00391 this->allocator_ = ACE_Allocator::instance (); 00392 00393 this->len_ = 0; 00394 this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); 00395 this->rep_[this->len_] = '\0'; 00396 } |
|
||||||||||||
|
Constructor that copies s into dynamically allocated memory.
Definition at line 415 of file SString.cpp. References ACE_TRACE, allocator_, ACE_Allocator::instance, len_, ACE_Allocator::malloc, rep_, ACE_OS_String::strcpy, and ACE_OS_String::strlen.
00417 : allocator_ (alloc) 00418 { 00419 ACE_TRACE ("ACE_SString::ACE_SString"); 00420 00421 if (this->allocator_ == 0) 00422 this->allocator_ = ACE_Allocator::instance (); 00423 00424 if (s == 0) 00425 { 00426 this->len_ = 0; 00427 this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); 00428 this->rep_[this->len_] = '\0'; 00429 } 00430 else 00431 { 00432 this->len_ = ACE_OS::strlen (s); 00433 this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); 00434 ACE_OS::strcpy (this->rep_, s); 00435 } 00436 } |
|
||||||||||||||||
|
Constructor that copies len chars of @s into dynamically allocated memory (will NUL terminate the result).
Definition at line 455 of file SString.cpp. References ACE_TRACE, allocator_, ACE_Allocator::instance, len_, ACE_Allocator::malloc, ACE_OS_String::memcpy, and rep_.
00458 : allocator_ (alloc) 00459 { 00460 ACE_TRACE ("ACE_SString::ACE_SString"); 00461 00462 if (this->allocator_ == 0) 00463 this->allocator_ = ACE_Allocator::instance (); 00464 00465 if (s == 0) 00466 { 00467 this->len_ = 0; 00468 this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); 00469 this->rep_[this->len_] = '\0'; 00470 } 00471 else 00472 { 00473 this->len_ = len; 00474 this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); 00475 ACE_OS::memcpy (this->rep_, s, len); 00476 this->rep_[len] = '\0'; // Make sure to NUL terminate this! 00477 } 00478 } |
|
|
Copy constructor.
Definition at line 364 of file SString.cpp. References ACE_TRACE, allocator_, ACE_Allocator::instance, len_, ACE_Allocator::malloc, ACE_OS_String::memcpy, and rep_.
00365 : allocator_ (s.allocator_), 00366 len_ (s.len_) 00367 { 00368 ACE_TRACE ("ACE_SString::ACE_SString"); 00369 00370 if (this->allocator_ == 0) 00371 this->allocator_ = ACE_Allocator::instance (); 00372 00373 this->rep_ = (char *) this->allocator_->malloc (s.len_ + 1); 00374 ACE_OS::memcpy ((void *) this->rep_, 00375 (const void *) s.rep_, 00376 this->len_); 00377 this->rep_[this->len_] = '\0'; 00378 } |
|
||||||||||||
|
Constructor that copies c into dynamically allocated memory.
Definition at line 438 of file SString.cpp. References ACE_TRACE, allocator_, ACE_Allocator::instance, len_, ACE_Allocator::malloc, and rep_.
00440 : allocator_ (alloc) 00441 { 00442 ACE_TRACE ("ACE_SString::ACE_SString"); 00443 00444 if (this->allocator_ == 0) 00445 this->allocator_ = ACE_Allocator::instance (); 00446 00447 this->len_ = 1; 00448 this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); 00449 this->rep_[0] = c; 00450 this->rep_[this->len_] = '\0'; 00451 } |
|
|
Default destructor.
Definition at line 54 of file SString.i.
00055 {
00056 }
|
|
|
Same as STL String's <c_str> and <fast_rep>.
Definition at line 104 of file SString.i. References ACE_TRACE, and rep_.
|
|
|
Performs a <strcmp>-style comparison.
Definition at line 154 of file SString.i. References ACE_TRACE, rep_, and ACE_OS_String::strcmp.
00155 {
00156 ACE_TRACE ("ACE_SString::compare");
00157 return ACE_OS::strcmp (this->rep_, s.rep_);
00158 }
|
|
|
Dump the state of an object.
Definition at line 357 of file SString.cpp. References ACE_TRACE.
00358 {
00359 ACE_TRACE ("ACE_SString::dump");
00360 }
|
|
|
Get the underlying pointer.
Definition at line 95 of file SString.i. References ACE_TRACE, and rep_. Referenced by operator<<.
|
|
||||||||||||
|
Find <c> starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos.
Definition at line 172 of file SString.i. References npos, rep_, ACE_OS_String::strchr, and substr.
00173 {
00174 char *substr = this->rep_ + pos;
00175 char *pointer = ACE_OS::strchr (substr, c);
00176 if (pointer == 0)
00177 return ACE_SString::npos;
00178 else
00179 return pointer - this->rep_;
00180 }
|
|
||||||||||||
|
Find <s> starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos.
Definition at line 161 of file SString.i. References npos, rep_, ACE_OS_String::strstr, and substr.
00162 {
00163 char *substr = this->rep_ + pos;
00164 char *pointer = ACE_OS::strstr (substr, s);
00165 if (pointer == 0)
00166 return ACE_SString::npos;
00167 else
00168 return pointer - this->rep_;
00169 }
|
|
||||||||||||
|
Find <str> starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos.
Definition at line 191 of file SString.i. References rep_. Referenced by strstr.
|
|
|
Returns a hash value for this string.
Definition at line 210 of file SString.i. References ACE::hash_pjw.
00211 {
00212 return ACE::hash_pjw (this->rep_);
00213 }
|
|
|
Return the length of the string.
Definition at line 216 of file SString.i. References ACE_TRACE, and len_. Referenced by substr, and substring.
|
|
|
Inequality comparison operator.
Definition at line 147 of file SString.i. References ACE_TRACE.
00148 {
00149 ACE_TRACE ("ACE_SString::operator!=");
00150 return !(*this == s);
00151 }
|
|
|
Less than comparison operator.
Definition at line 123 of file SString.i. References ACE_TRACE, rep_, and ACE_OS_String::strcmp.
|
|
|
Assignment operator (does copy memory).
Definition at line 483 of file SString.cpp. References ACE_TRACE, allocator_, ACE_Allocator::free, len_, ACE_Allocator::malloc, rep_, and ACE_OS_String::strcpy.
00484 {
00485 ACE_TRACE ("ACE_SString::operator=");
00486 // Check for identify.
00487
00488 if (this != &s)
00489 {
00490 // Only reallocate if we don't have enough space...
00491 if (this->len_ < s.len_)
00492 {
00493 this->allocator_->free (this->rep_);
00494 this->rep_ = (char *) this->allocator_->malloc (s.len_ + 1);
00495 }
00496 this->len_ = s.len_;
00497 ACE_OS::strcpy (this->rep_, s.rep_);
00498 }
00499
00500 return *this;
00501 }
|
|
|
Equality comparison operator (must match entire string).
Definition at line 113 of file SString.i. References ACE_TRACE, len_, rep_, and ACE_OS_String::strcmp.
00114 {
00115 ACE_TRACE ("ACE_SString::operator==");
00116 return this->len_ == s.len_
00117 && ACE_OS::strcmp (this->rep_, s.rep_) == 0;
00118 }
|
|
|
Greater than comparison operator.
Definition at line 135 of file SString.i. References ACE_TRACE, rep_, and ACE_OS_String::strcmp.
|
|
|
Return the <slot'th> character by reference in the string (doesn't perform bounds checking).
Definition at line 77 of file SString.i. References ACE_TRACE, and rep_.
|
|
|
Return the <slot'th> character in the string (doesn't perform bounds checking).
Definition at line 68 of file SString.i. References ACE_TRACE, and rep_.
|
|
|
Get the underlying pointer.
Definition at line 86 of file SString.i. References ACE_TRACE, and rep_.
|
|
|
Set the underlying pointer. Since this does not copy memory or delete existing memory use with extreme caution!!!
Definition at line 401 of file SString.cpp. References ACE_TRACE, len_, rep_, and ACE_OS_String::strlen.
00402 {
00403 ACE_TRACE ("ACE_SString::rep");
00404
00405 this->rep_ = s;
00406
00407 if (s == 0)
00408 this->len_ = 0;
00409 else
00410 this->len_ = ACE_OS::strlen (s);
00411 }
|
|
||||||||||||
|
Find <c> starting at pos (counting from the end). Returns the slot of the first location that matches, else npos.
Definition at line 197 of file SString.i.
00198 {
00199 if (pos == ACE_SString::npos)
00200 pos = ACE_static_cast (int, this->len_);
00201
00202 for (int i = pos - 1; i >= 0; i--)
00203 if (this->rep_[i] == c)
00204 return i;
00205
00206 return ACE_SString::npos;
00207 }
|
|
|
Comparison operator that will match substrings. Returns the slot of the first location that matches, else -1.
Definition at line 183 of file SString.i. References ACE_TRACE, find, and rep_.
|
|
||||||||||||
|
Same as substring.
Definition at line 59 of file SString.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 505 of file SString.cpp. References ACE_SString, len_, length, rep_, and ssize_t. Referenced by substr.
00507 {
00508 ACE_SString nill;
00509 size_t count = length;
00510
00511 // case 1. empty string
00512 if (len_ == 0)
00513 return nill;
00514
00515 // case 2. start pos l
00516 if (offset >= len_)
00517 return nill;
00518
00519 // get all remaining bytes
00520 if (length == -1)
00521 count = len_ - offset;
00522
00523 return ACE_SString (&rep_[offset], count, this->allocator_);
00524 }
|
|
|
Declare the dynamic allocation hooks.
|
|
|
Pointer to a memory allocator.
Definition at line 225 of file SString.h. Referenced by ACE_SString, and operator=. |
|
|
Length of the ACE_SString (not counting the trailing '\0').
Definition at line 228 of file SString.h. Referenced by ACE_SString, length, operator=, operator==, rep, and substring. |
|
|
No position constant.
Definition at line 307 of file SString.cpp. |
|
|
Pointer to data.
Definition at line 231 of file SString.h. Referenced by ACE_SString, c_str, compare, fast_rep, find, operator<, operator=, operator==, operator>, operator[], rep, rfind, strstr, and substring. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002