Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_String_Base Class Template Reference

This class provides a wrapper facade for C strings. More...

#include <String_Base.h>

Inheritance diagram for ACE_String_Base:

Inheritance graph
[legend]
Collaboration diagram for ACE_String_Base:

Collaboration graph
[legend]
List of all members.

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_Allocatorallocator_
size_t len_
size_t buf_len_
CHAR * rep_
int release_

Static Protected Attributes

CHAR NULL_String_ = '\0'

Detailed Description

template<class CHAR>
class ACE_String_Base< CHAR >

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.

Definition at line 46 of file String_Base.h.


Constructor & Destructor Documentation

template<class CHAR>
ACE_INLINE ACE_String_Base< CHAR >::ACE_String_Base ACE_Allocator   alloc = 0
 

Default constructor.

Parameters:
alloc  ACE_Allocator associated with string
Returns:
Default ACE_String_Base string.

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 }

template<class CHAR>
ACE_INLINE ACE_String_Base< CHAR >::ACE_String_Base const CHAR *    s,
ACE_Allocator   alloc = 0,
int    release = 1
 

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.

Parameters:
s  Zero terminated input string
alloc  ACE_Allocator associated with string
release  Allocator responsible(1)/not reponsible(0) for freeing memory.
Returns:
ACE_String_Base containing const CHAR *s

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 }

template<class CHAR>
ACE_INLINE ACE_String_Base< CHAR >::ACE_String_Base const CHAR *    s,
size_t    len,
ACE_Allocator   alloc = 0,
int    release = 1
 

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.

Parameters:
s  Non-zero terminated input string
len  Length of non-zero terminated input string
alloc  ACE_Allocator associated with string
release  Allocator responsible(1)/not reponsible(0) for freeing memory.
Returns:
ACE_String_Base containing const CHAR *s

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 }

template<class CHAR>
ACE_INLINE ACE_String_Base< CHAR >::ACE_String_Base const ACE_String_Base< CHAR > &    s
 

Copy constructor.

Parameters:
s  Input ACE_String_Base string to copy
Returns:
Copy of input string s

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 }

template<class CHAR>
ACE_INLINE ACE_String_Base< CHAR >::ACE_String_Base CHAR    c,
ACE_Allocator   alloc = 0
 

Constructor that copies c into dynamically allocated memory.

Parameters:
c  Single input character.
alloc  ACE_Allocator associated with string
Returns:
ACE_String_Base containing CHAR 'c'

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 }

template<class CHAR>
ACE_INLINE ACE_String_Base< CHAR >::ACE_String_Base size_t    len,
CHAR    c = 0,
ACE_Allocator   alloc = 0
 

Constructor that dynamically allocate len long of char array and initialize it to c using alloc to allocate the memory.

Parameters:
len  Length of character array 'c'
c  Input character array
alloc  ACE_Allocator associated with string
Returns:
ACE_String_Base containing character array 'c'

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 }

template<class CHAR>
ACE_INLINE ACE_String_Base< CHAR >::~ACE_String_Base void   
 

Deletes the memory...

Definition at line 103 of file String_Base.i.

References ACE_TRACE, and set.

00104 {
00105   ACE_TRACE ("ACE_String_Base<CHAR>::~ACE_String_Base");
00106 
00107   this->set (0, 0, 0);
00108 }


Member Function Documentation

template<class CHAR>
ACE_INLINE ACE_String_Base< CHAR > & ACE_String_Base< CHAR >::assign_nocopy const ACE_String_Base< CHAR > &    s
 

Assignment alternative method (does not copy memory).

Parameters:
s  Input ACE_String_Base string to assign to this object.
Returns:
Return this string.

Definition at line 131 of file String_Base.i.

References len_, rep_, and set.

00132 {
00133   this->set (s.rep_, s.len_, 0);
00134   return *this;
00135 }

template<class CHAR>
ACE_INLINE const CHAR * ACE_String_Base< CHAR >::c_str void    const
 

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 }

template<class CHAR>
ACE_INLINE void ACE_String_Base< CHAR >::clear int    release = 0
 

Clear this string. Memory is _not_ freed if <release> is 0.

Parameters:
release  Memory is freed if 1 or not if 0.

Definition at line 157 of file String_Base.i.

References set.

00158 {
00159   this->set(0, 0, release);
00160 }

template<class CHAR>
ACE_INLINE int ACE_String_Base< CHAR >::compare const ACE_String_Base< CHAR > &    s const
 

Performs a strncmp comparison.

Parameters:
s  Input ACE_String_Base string to compare against stored string.
Returns:
Integer value of result (less than 0, 0, greater than 0) depending on how input string s is to the stored string.

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 }

template<class CHAR>
ACE_INLINE void ACE_String_Base< CHAR >::dump void    const
 

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 }

template<class CHAR>
ACE_INLINE const CHAR * ACE_String_Base< CHAR >::fast_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!

Returns:
Pointer reference to the stored string data. No guarantee is that the string is zero terminated.

Definition at line 202 of file String_Base.i.

References rep_.

00203 {
00204   return this->rep_;
00205 }

template<class CHAR>
ACE_INLINE ssize_t ACE_String_Base< CHAR >::find CHAR    c,
size_t    pos = 0
const
 

Find c starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos.

Parameters:
c  Input character to search for in stored string.
pos  Starting index position to start searching for string str.
Returns:
Index value of the first location of string str 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 }

template<class CHAR>
ACE_INLINE ssize_t ACE_String_Base< CHAR >::find const CHAR *    s,
size_t    pos = 0
const
 

Find s starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos.

Parameters:
s  non-zero input string to search for in stored string.
pos  Starting index position to start searching for string str.
Returns:
Index value of the first location of string str 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 }

template<class CHAR>
ACE_INLINE ssize_t ACE_String_Base< CHAR >::find const ACE_String_Base< CHAR > &    str,
size_t    pos = 0
const
 

Find <str> starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos.

Parameters:
str  Input ACE_String_Base string to search for in stored string.
pos  Starting index position to start searching for string str.
Returns:
Index value of the first location of string str else npos.

Definition at line 293 of file String_Base.i.

References rep_.

Referenced by strstr.

00294 {
00295   return this->find (str.rep_, pos);
00296 }

template<class CHAR>
ACE_INLINE u_long ACE_String_Base< CHAR >::hash void    const
 

Returns a hash value for this string.

Returns:
Hash value of 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 }

template<class CHAR>
ACE_INLINE size_t ACE_String_Base< CHAR >::length void    const
 

Return the length of the string.

Returns:
Length of stored string

Definition at line 150 of file String_Base.i.

References ACE_TRACE, and len_.

Referenced by ACE_String_Base, set, substr, and substring.

00151 {
00152   ACE_TRACE ("ACE_String_Base<CHAR>::length");
00153   return this->len_;
00154 }

template<class CHAR>
ACE_INLINE int ACE_String_Base< CHAR >::operator!= const ACE_String_Base< CHAR > &    s const
 

Inequality comparison operator.

Parameters:
s  Input ACE_String_Base string to compare against stored string.
Returns:
Integer value of result (1 = not equal, 0 = equal).

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 }

template<class CHAR>
ACE_String_Base< CHAR > & ACE_String_Base< CHAR >::operator+= const ACE_String_Base< CHAR > &    s
 

Concat operator (copies memory).

Parameters:
s  Input ACE_String_Base string to concatenate to another string.
Returns:
The combined string (input append to the end of the old). New string is zero terminated.

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 }

template<class CHAR>
ACE_INLINE int ACE_String_Base< CHAR >::operator< const ACE_String_Base< CHAR > &    s const
 

Less than comparison operator.

Parameters:
s  Input ACE_String_Base string to compare against stored string.
Returns:
Integer value of result (1 = less than, 0 = greater than or equal).

Definition at line 244 of file String_Base.i.

References ACE_TRACE, and compare.

00245 {
00246   ACE_TRACE ("ACE_String_Base<CHAR>::operator <");
00247   return compare (s) < 0;
00248 }

template<class CHAR>
ACE_INLINE ACE_String_Base< CHAR > & ACE_String_Base< CHAR >::operator= const ACE_String_Base< CHAR > &    s
 

Assignment operator (does copy memory).

Parameters:
s  Input ACE_String_Base string to assign to this object.
Returns:
Return a copy of the this string.

Definition at line 118 of file String_Base.i.

References ACE_TRACE, len_, rep_, and set.

00119 {
00120   ACE_TRACE ("ACE_String_Base<CHAR>::operator=");
00121 
00122   // Check for identify.
00123   if (this != &s)
00124     this->set (s.rep_, s.len_, 1);
00125 
00126   return *this;
00127 }

template<class CHAR>
ACE_INLINE int ACE_String_Base< CHAR >::operator== const ACE_String_Base< CHAR > &    s const
 

Equality comparison operator (must match entire string).

Parameters:
s  Input ACE_String_Base string to compare against stored string.
Returns:
Integer value of result (1 = found, 0 = not found).

Definition at line 234 of file String_Base.i.

References ACE_TRACE, and compare.

00235 {
00236   ACE_TRACE ("ACE_String_Base<CHAR>::operator==");
00237 
00238   return compare (s) == 0;
00239 }

template<class CHAR>
ACE_INLINE int ACE_String_Base< CHAR >::operator> const ACE_String_Base< CHAR > &    s const
 

Greater than comparison operator.

Parameters:
s  Input ACE_String_Base string to compare against stored string.
Returns:
Integer value of result (1 = greater than, 0 = less than or equal).

Definition at line 253 of file String_Base.i.

References ACE_TRACE, and compare.

00254 {
00255   ACE_TRACE ("ACE_String_Base<CHAR>::operator >");
00256   return compare (s) > 0;
00257 }

template<class CHAR>
ACE_INLINE CHAR & ACE_String_Base< CHAR >::operator[] size_t    slot
 

Return the <slot'th> character by reference in the string (doesn't perform bounds checking).

Parameters:
slot  Index of the desired character
Returns:
The character at index slot

Definition at line 181 of file String_Base.i.

References ACE_TRACE, and rep_.

00182 {
00183   ACE_TRACE ("ACE_String_Base<CHAR>::operator[]");
00184   return this->rep_[slot];
00185 }

template<class CHAR>
ACE_INLINE const CHAR & ACE_String_Base< CHAR >::operator[] size_t    slot const
 

Return the <slot'th> character in the string (doesn't perform bounds checking).

Parameters:
slot  Index of the desired character
Returns:
The character at index slot

Definition at line 172 of file String_Base.i.

References ACE_TRACE, and rep_.

00173 {
00174   ACE_TRACE ("ACE_String_Base<CHAR>::operator[]");
00175   return this->rep_[slot];
00176 }

template<class CHAR>
ACE_INLINE CHAR * ACE_String_Base< CHAR >::rep void    const
 

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 []

Returns:
Pointer reference to the string data. Returned string is zero terminated.

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 }

template<class CHAR>
void ACE_String_Base< CHAR >::resize size_t    len,
CHAR    c = 0
 

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.

Parameters:
len  New string size
c  New input string

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 }

template<class CHAR>
ACE_INLINE ssize_t ACE_String_Base< CHAR >::rfind CHAR    c,
ssize_t    pos = npos
const
 

Find c starting at pos (counting from the end). Returns the slot of the first location that matches, else npos.

Parameters:
c  Input character to search for in stored string.
pos  Starting index position to start searching for string str.
Returns:
Index value of the first location of string str else npos.

Definition at line 307 of file String_Base.i.

References ACE_String_Base_Const::npos, rep_, and ssize_t.

00308 {
00309   if (pos == npos || pos > ACE_static_cast (ssize_t, this->len_))
00310     pos = ACE_static_cast (ssize_t, this->len_);
00311 
00312   for (ssize_t i = pos - 1; i >= 0; i--)
00313     if (this->rep_[i] == c)
00314       return i;
00315 
00316   return ACE_String_Base<CHAR>::npos;
00317 }

template<class CHAR>
void ACE_String_Base< CHAR >::set const CHAR *    s,
size_t    len,
int    release
 

Copy len bytes of s (will zero terminate the result). Memory is _not_ allocated/freed if release is 0.

Parameters:
s  Non-zero terminated input string
len  Length of input string 's'
release  Allocator responsible(1)/not reponsible(0) for freeing memory.

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 }

template<class CHAR>
ACE_INLINE void ACE_String_Base< CHAR >::set const CHAR *    s,
int    release = 1
 

Copy s into this ACE_String_Base. Memory is _not_ allocated/freed if release is 0.

Parameters:
s  Null terminated input string
release  Allocator responsible(1)/not reponsible(0) for freeing memory.

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.

00139 {
00140   size_t length;
00141   if (s != 0)
00142     length = ACE_OS::strlen (s);
00143   else
00144     length = 0;
00145 
00146   this->set (s, length, release);
00147 }

template<class CHAR>
ACE_INLINE ssize_t ACE_String_Base< CHAR >::strstr const ACE_String_Base< CHAR > &    s const
 

Comparison operator that will match substrings. Returns the slot of the first location that matches, else -1.

Parameters:
s  Input ACE_String_Base string
Returns:
Integer index value of the first location of string s or -1 (not found).

Definition at line 299 of file String_Base.i.

References ACE_TRACE, find, and rep_.

00300 {
00301   ACE_TRACE ("ACE_String_Base<CHAR>::strstr");
00302 
00303   return this->find (s.rep_);
00304 }

template<class CHAR>
ACE_INLINE ACE_String_Base< CHAR > ACE_String_Base< CHAR >::substr size_t    offset,
ssize_t    length = -1
const
 

Same as <substring>.

Parameters:
offset  Index of first desired character of the substring.
length  How many characters to return starting at the offset.
Returns:
The string containing the desired substring

Definition at line 163 of file String_Base.i.

References length, ssize_t, and substring.

Referenced by find.

00165 {
00166   return this->substring (offset, length);
00167 }

template<class CHAR>
ACE_String_Base< CHAR > ACE_String_Base< CHAR >::substring size_t    offset,
ssize_t    length = -1
const
 

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.

Parameters:
offset  Index of first desired character of the substring.
length  How many characters to return starting at the offset.
Returns:
The string containing the desired substring

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 }


Member Data Documentation

template<class CHAR>
ACE_String_Base::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 373 of file String_Base.h.

template<class CHAR>
ACE_Allocator* ACE_String_Base::allocator_ [protected]
 

Pointer to a memory allocator.

Definition at line 379 of file String_Base.h.

Referenced by operator+=, resize, set, and substring.

template<class CHAR>
size_t ACE_String_Base::buf_len_ [protected]
 

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.

template<class CHAR>
size_t ACE_String_Base::len_ [protected]
 

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.

template<class CHAR>
CHAR ACE_String_Base< CHAR >::NULL_String_ = '\0' [static, protected]
 

Represents the "NULL" string to simplify the internal logic.

Definition at line 20 of file String_Base.cpp.

template<class CHAR>
int ACE_String_Base::release_ [protected]
 

Flag that indicates if we own the memory

Definition at line 400 of file String_Base.h.

Referenced by operator+=, and set.

template<class CHAR>
CHAR* ACE_String_Base::rep_ [protected]
 

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.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:57:01 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002