A very Simple String ACE_SString class. This is not a general-purpose string class, and you should probably consider using ACE_CString is you don't understand why this class exists... More...
#include <SString.h>
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 c_str() and fast_rep(). | |
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 strcmp()-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 | |
static 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 '\0'). | |
char * | rep_ |
Pointer to data. |
A very Simple String ACE_SString class. This is not a general-purpose string class, and you should probably consider using ACE_CString is you don't understand why this class exists...
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 133 of file SString.h.
ACE_SString::ACE_SString | ( | ACE_Allocator * | alloc = 0 |
) |
Default constructor.
Definition at line 191 of file SString.cpp.
: allocator_ (alloc), len_ (0), rep_ (0) { ACE_TRACE ("ACE_SString::ACE_SString"); if (this->allocator_ == 0) this->allocator_ = ACE_Allocator::instance (); this->len_ = 0; this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); this->rep_[this->len_] = '\0'; }
ACE_SString::ACE_SString | ( | const char * | s, | |
ACE_Allocator * | alloc = 0 | |||
) |
Constructor that copies s into dynamically allocated memory.
Definition at line 224 of file SString.cpp.
: allocator_ (alloc) { ACE_TRACE ("ACE_SString::ACE_SString"); if (this->allocator_ == 0) this->allocator_ = ACE_Allocator::instance (); if (s == 0) { this->len_ = 0; this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); this->rep_[this->len_] = '\0'; } else { this->len_ = ACE_OS::strlen (s); this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); ACE_OS::strcpy (this->rep_, s); } }
ACE_SString::ACE_SString | ( | const char * | s, | |
size_type | len, | |||
ACE_Allocator * | alloc = 0 | |||
) |
Constructor that copies len chars of s into dynamically allocated memory (will NUL terminate the result).
Definition at line 264 of file SString.cpp.
: allocator_ (alloc) { ACE_TRACE ("ACE_SString::ACE_SString"); if (this->allocator_ == 0) this->allocator_ = ACE_Allocator::instance (); if (s == 0) { this->len_ = 0; this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); this->rep_[this->len_] = '\0'; } else { this->len_ = len; this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); ACE_OS::memcpy (this->rep_, s, len); this->rep_[len] = '\0'; // Make sure to NUL terminate this! } }
ACE_SString::ACE_SString | ( | const ACE_SString & | s | ) |
Copy constructor.
Definition at line 173 of file SString.cpp.
: allocator_ (s.allocator_), len_ (s.len_) { ACE_TRACE ("ACE_SString::ACE_SString"); if (this->allocator_ == 0) this->allocator_ = ACE_Allocator::instance (); this->rep_ = (char *) this->allocator_->malloc (s.len_ + 1); ACE_OS::memcpy ((void *) this->rep_, (const void *) s.rep_, this->len_); this->rep_[this->len_] = '\0'; }
ACE_SString::ACE_SString | ( | char | c, | |
ACE_Allocator * | alloc = 0 | |||
) |
Constructor that copies c into dynamically allocated memory.
Definition at line 247 of file SString.cpp.
: allocator_ (alloc) { ACE_TRACE ("ACE_SString::ACE_SString"); if (this->allocator_ == 0) this->allocator_ = ACE_Allocator::instance (); this->len_ = 1; this->rep_ = (char *) this->allocator_->malloc (this->len_ + 1); this->rep_[0] = c; this->rep_[this->len_] = '\0'; }
ACE_SString::~ACE_SString | ( | void | ) |
const char * ACE_SString::c_str | ( | void | ) | const |
Same as STL String's c_str() and fast_rep().
Definition at line 116 of file SString.inl.
int ACE_SString::compare | ( | const ACE_SString & | s | ) | const |
Performs a strcmp()-style comparison.
Definition at line 166 of file SString.inl.
{ ACE_TRACE ("ACE_SString::compare"); return ACE_OS::strcmp (this->rep_, s.rep_); }
void ACE_SString::dump | ( | void | ) | const |
Dump the state of an object.
Definition at line 164 of file SString.cpp.
{ #if defined (ACE_HAS_DUMP) ACE_TRACE ("ACE_SString::dump"); #endif /* ACE_HAS_DUMP */ }
const char * ACE_SString::fast_rep | ( | void | ) | const |
Get the underlying pointer.
Definition at line 107 of file SString.inl.
ACE_SString::size_type ACE_SString::find | ( | const ACE_SString & | str, | |
size_type | pos = 0 | |||
) | const |
Find str 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.
ACE_SString::size_type ACE_SString::find | ( | const char * | s, | |
size_type | pos = 0 | |||
) | const |
Find <s> 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.
{ char *substr = this->rep_ + pos; char *pointer = ACE_OS::strstr (substr, s); if (pointer == 0) return ACE_SString::npos; else return pointer - this->rep_; }
ACE_SString::size_type ACE_SString::find | ( | char | c, | |
size_type | pos = 0 | |||
) | const |
Find c 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.
{ char *substr = this->rep_ + pos; char *pointer = ACE_OS::strchr (substr, c); if (pointer == 0) return ACE_SString::npos; else return pointer - this->rep_; }
u_long ACE_SString::hash | ( | void | ) | const |
Returns a hash value for this string.
Definition at line 224 of file SString.inl.
{ return ACE::hash_pjw (this->rep_); }
ACE_SString::size_type ACE_SString::length | ( | void | ) | const |
Return the length of the string.
Definition at line 230 of file SString.inl.
bool ACE_SString::operator!= | ( | const ACE_SString & | s | ) | const |
Inequality comparison operator.
Definition at line 159 of file SString.inl.
{ ACE_TRACE ("ACE_SString::operator!="); return !(*this == s); }
bool ACE_SString::operator< | ( | const ACE_SString & | s | ) | const |
Less than comparison operator.
Definition at line 135 of file SString.inl.
ACE_SString & ACE_SString::operator= | ( | const ACE_SString & | s | ) |
Assignment operator (does copy memory).
Definition at line 292 of file SString.cpp.
{ ACE_TRACE ("ACE_SString::operator="); // Check for identify. if (this != &s) { // Only reallocate if we don't have enough space... if (this->len_ < s.len_) { this->allocator_->free (this->rep_); this->rep_ = (char *) this->allocator_->malloc (s.len_ + 1); } this->len_ = s.len_; ACE_OS::strcpy (this->rep_, s.rep_); } return *this; }
bool ACE_SString::operator== | ( | const ACE_SString & | s | ) | const |
Equality comparison operator (must match entire string).
Definition at line 125 of file SString.inl.
bool ACE_SString::operator> | ( | const ACE_SString & | s | ) | const |
Greater than comparison operator.
Definition at line 147 of file SString.inl.
char & ACE_SString::operator[] | ( | size_type | slot | ) |
Return the <slot'th> character by reference in the string (doesn't perform bounds checking).
Definition at line 89 of file SString.inl.
char ACE_SString::operator[] | ( | size_type | slot | ) | const |
Return the <slot'th> character in the string (doesn't perform bounds checking).
Definition at line 80 of file SString.inl.
const char * ACE_SString::rep | ( | void | ) | const |
Get the underlying pointer.
Definition at line 98 of file SString.inl.
void ACE_SString::rep | ( | char * | s | ) |
Set the underlying pointer. Since this does not copy memory or delete existing memory use with extreme caution!!!
Definition at line 210 of file SString.cpp.
{ ACE_TRACE ("ACE_SString::rep"); this->rep_ = s; if (s == 0) this->len_ = 0; else this->len_ = ACE_OS::strlen (s); }
ACE_SString::size_type ACE_SString::rfind | ( | char | c, | |
size_type | pos = npos | |||
) | const |
Find c 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.
{ if (pos == ACE_SString::npos) pos = this->len_; // Do not change to prefix operator! Proper operation of this loop // depends on postfix decrement behavior. for (size_type i = pos; i-- != 0; ) if (this->rep_[i] == c) return i; return ACE_SString::npos; }
ACE_SString::size_type ACE_SString::strstr | ( | const ACE_SString & | s | ) | const |
Comparison operator that will match substrings. Returns the slot of the first location that matches, else npos
.
Definition at line 195 of file SString.inl.
ACE_SString ACE_SString::substr | ( | size_type | offset, | |
size_type | length = npos | |||
) | const |
Same as substring.
Definition at line 71 of file SString.inl.
ACE_SString ACE_SString::substring | ( | size_type | offset, | |
size_type | length = npos | |||
) | const |
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 314 of file SString.cpp.
{ size_t count = length; // case 1. empty string if (len_ == 0) return ACE_SString (); // case 2. start pos l if (offset >= len_) return ACE_SString (); // get all remaining bytes if (length == npos || count > (this->len_ - offset)) count = len_ - offset; return ACE_SString (&rep_[offset], count, this->allocator_); }
ACE_Allocator* ACE_SString::allocator_ [private] |
size_type ACE_SString::len_ [private] |
Length of the ACE_SString (not counting the trailing '\0').
ACE_SString::size_type const ACE_SString::npos [static] |
No position constant.
char* ACE_SString::rep_ [private] |