ACE_String_Base< CHAR > Class Template Reference

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

#include <String_Base.h>

Inheritance diagram for ACE_String_Base< CHAR >:

Inheritance graph
[legend]
Collaboration diagram for ACE_String_Base< CHAR >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_String_Base (ACE_Allocator *the_allocator=0)
 ACE_String_Base (const CHAR *s, ACE_Allocator *the_allocator=0, int release=1)
 ACE_String_Base (const CHAR *s, size_t len, ACE_Allocator *the_allocator=0, int release=1)
 ACE_String_Base (const ACE_String_Base< CHAR > &s)
 ACE_String_Base (CHAR c, ACE_Allocator *the_allocator=0)
 ACE_String_Base (size_t len, CHAR c=0, ACE_Allocator *the_allocator=0)
 ~ACE_String_Base (void)
const CHAR & operator[] (size_t slot) const
CHAR & operator[] (size_t slot)
ACE_String_Base< CHAR > & operator= (const CHAR *s)
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)
void fast_clear (void)
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)
ACE_String_Base< CHAR > & operator+= (const CHAR *s)
ACE_String_Base< CHAR > & operator+= (const CHAR c)
ACE_String_Base< CHAR > & append (const CHAR *s, size_t slen)
u_long hash (void) const
size_t length (void) const
bool is_empty (void) const
bool empty (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
bool operator== (const ACE_String_Base< CHAR > &s) const
bool operator== (const CHAR *s) const
bool operator< (const ACE_String_Base< CHAR > &s) const
bool operator> (const ACE_String_Base< CHAR > &s) const
bool operator!= (const ACE_String_Base< CHAR > &s) const
bool operator!= (const 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 ''), 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 '' terminated.

Definition at line 49 of file String_Base.h.


Constructor & Destructor Documentation

template<class CHAR>
ACE_String_Base< CHAR >::ACE_String_Base ACE_Allocator the_allocator = 0  ) 
 

Default constructor.

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

Definition at line 26 of file String_Base.cpp.

References ACE_TRACE.

00027   : allocator_ (the_allocator ? the_allocator : ACE_Allocator::instance ()),
00028     len_ (0),
00029     buf_len_ (0),
00030     rep_ (&ACE_String_Base<CHAR>::NULL_String_),
00031     release_ (0)
00032 {
00033   ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
00034 }

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

Constructor that copies s into dynamically allocated memory.

if release == 1 then a new buffer is allocated internally, and s is copied to the internal buffer. if release == 0 then the s buffer is used directly. If s == 0 then it will _not_ be used, and instead the internal buffer is set to NULL_String_.

Parameters:
s Zero terminated input string
the_allocator 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 39 of file String_Base.cpp.

References ACE_TRACE, and ACE_String_Base< CHAR >::set().

00042   : allocator_ (the_allocator ? the_allocator : ACE_Allocator::instance ()),
00043     len_ (0),
00044     buf_len_ (0),
00045     rep_ (0),
00046     release_ (0)
00047 {
00048   ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
00049   this->set (s, release);
00050 }

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

Constructor that copies len CHARs of s into dynamically allocated memory (will zero terminate the result).

if release == 1 then a new buffer is allocated internally. s is copied to the internal buffer. if release == 0 then the s buffer is used directly. If s == 0 then it will _not_ be used, and instead the internal buffer is set to NULL_String_.

Parameters:
s Non-zero terminated input string
len Length of non-zero terminated input string
the_allocator 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 69 of file String_Base.cpp.

References ACE_TRACE, and ACE_String_Base< CHAR >::set().

00073   : allocator_ (the_allocator ? the_allocator : ACE_Allocator::instance ()),
00074     len_ (0),
00075     buf_len_ (0),
00076     rep_ (0),
00077     release_ (0)
00078 {
00079   ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
00080 
00081   this->set (s, len, release);
00082 }

template<class CHAR>
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 87 of file String_Base.cpp.

References ACE_TRACE, ACE_String_Base< CHAR >::len_, ACE_String_Base< CHAR >::rep_, and ACE_String_Base< CHAR >::set().

00088   : allocator_ (s.allocator_ ? s.allocator_ : ACE_Allocator::instance ()),
00089     len_ (0),
00090     buf_len_ (0),
00091     rep_ (0),
00092     release_ (0)
00093 {
00094   ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
00095 
00096   this->set (s.rep_, s.len_, 1);
00097 }

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

Constructor that copies c into dynamically allocated memory.

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

Definition at line 53 of file String_Base.cpp.

References ACE_TRACE, and ACE_String_Base< CHAR >::set().

00055   : allocator_ (the_allocator ? the_allocator : ACE_Allocator::instance ()),
00056     len_ (0),
00057     buf_len_ (0),
00058     rep_ (0),
00059     release_ (0)
00060 {
00061   ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
00062 
00063   this->set (&c, 1, 1);
00064 }

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

Constructor that allocates a len long string.

Warning : This constructor was incorrectly documented in the past. It simply calls resize(len, c). It is probably not advisable to use the second parameter. See resize() for more information.

Parameters:
len Amount of space to reserve for the string.
c The array is filled with c's
the_allocator ACE_Allocator associated with string
Returns:
Empty ACE_String_Base with room for len CHARs

Definition at line 100 of file String_Base.cpp.

References ACE_TRACE, and ACE_String_Base< CHAR >::resize().

00101   : allocator_ (the_allocator ? the_allocator : ACE_Allocator::instance ()),
00102     len_ (0),
00103     buf_len_ (0),
00104     rep_ (0),
00105     release_ (0)
00106 {
00107   ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
00108 
00109   this->resize (len, c);
00110 }

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

Deletes the memory...

Definition at line 113 of file String_Base.cpp.

References ACE_TRACE, ACE_String_Base< CHAR >::buf_len_, ACE_Allocator::free(), and ACE_String_Base< CHAR >::release_.

00114 {
00115   ACE_TRACE ("ACE_String_Base<CHAR>::~ACE_String_Base");
00116 
00117   if (this->buf_len_ != 0 && this->release_ != 0)
00118       this->allocator_->free (this->rep_);
00119 }


Member Function Documentation

template<class CHAR>
ACE_String_Base< CHAR > & ACE_String_Base< CHAR >::append const CHAR *  s,
size_t  slen
 

Append function (copies memory).

Parameters:
s Input CHAR array to concatenate to this string.
slen The length of the array.
Returns:
The combined string (input append to the end of the old). New string is zero terminated.

Definition at line 203 of file String_Base.cpp.

References ACE_ALLOCATOR_RETURN, ace_max(), ACE_TRACE, ACE_String_Base< CHAR >::buf_len_, ACE_Allocator::free(), ACE_OS::memcpy(), and ACE_String_Base< CHAR >::release_.

Referenced by operator+(), and ACE_String_Base< CHAR >::operator+=().

00204 {
00205   ACE_TRACE ("ACE_String_Base<CHAR>::append(const CHAR*, size_t)");
00206   if (slen > 0)
00207   {
00208     // case 1. No memory allocation needed.
00209     if (this->buf_len_ >= this->len_ + slen + 1)
00210     {
00211       // Copy in data from new string.
00212       ACE_OS::memcpy (this->rep_ + this->len_, s, slen * sizeof (CHAR));
00213     }
00214     else // case 2. Memory reallocation is needed
00215     {
00216       const size_t new_buf_len =
00217         ace_max(this->len_ + slen + 1, this->buf_len_ + this->buf_len_ / 2);
00218 
00219       CHAR *t = 0;
00220 
00221       ACE_ALLOCATOR_RETURN (t,
00222         (CHAR *) this->allocator_->malloc (new_buf_len * sizeof (CHAR)), *this);
00223 
00224       // Copy memory from old string into new string.
00225       ACE_OS::memcpy (t, this->rep_, this->len_ * sizeof (CHAR));
00226 
00227       ACE_OS::memcpy (t + this->len_, s, slen * sizeof (CHAR));
00228 
00229       if (this->buf_len_ != 0 && this->release_ != 0)
00230         this->allocator_->free (this->rep_);
00231 
00232       this->release_ = 1;
00233       this->rep_ = t;
00234       this->buf_len_ = new_buf_len;
00235     }
00236 
00237     this->len_ += slen;
00238     this->rep_[this->len_] = 0;
00239   }
00240 
00241   return *this;
00242 }

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 22 of file String_Base.inl.

References ACE_TRACE, ACE_String_Base< CHAR >::len_, ACE_String_Base< CHAR >::rep_, and ACE_String_Base< CHAR >::set().

Referenced by ACE_Configuration_Heap::load_key().

00023 {
00024   ACE_TRACE ("ACE_String_Base<CHAR>::assign_nocopy");
00025   this->set (s.rep_, s.len_, 0);
00026   return *this;
00027 }

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

Same as STL String's and .

Definition at line 81 of file String_Base.inl.

Referenced by ACE_Registry::Naming_Context::bind(), ACE_Registry::Naming_Context::bind_context(), ACE_Registry::Naming_Context::bind_new_context(), ACE_Get_Opt::dump(), ACE_Capabilities::getent(), ACE_Capabilities::is_entry(), ACE_Get_Opt::last_option(), ACE_Registry_Name_Space::list_name_entries(), ACE_Codeset_Registry::locale_to_registry(), ACE_Codeset_Registry::locale_to_registry_i(), ACE_Service_Type_Factory::name(), ACE_DLL_Handle::open(), ACE_Configuration_Heap::open_section(), ACE_Configuration::operator==(), ACE_Get_Opt::optstring(), ACE_Registry::Naming_Context::resolve(), ACE_Registry::Naming_Context::resolve_context(), ACE_Utils::UUID::to_string(), ACE_Registry::Naming_Context::unbind(), ACE_Registry::Naming_Context::unbind_context(), ACE_Utils::UUID::UUID(), ACE_OutputCDR::write_string(), and ACE_SizeCDR::write_string().

00082 {
00083   return this->rep_;
00084 }

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

Clear this string. Memory is _not_ freed if is 0.

Warning: This method was incorrectly documented in the past, but the current implementation has been changed to match the documented behavior.

Warning: clear(0) behaves like fast_clear() below.

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

Definition at line 274 of file String_Base.cpp.

References ACE_String_Base< CHAR >::buf_len_, ACE_String_Base< CHAR >::fast_clear(), ACE_Allocator::free(), and ACE_String_Base< CHAR >::release_.

00275 {
00276   // This can't use set(), because that would free memory if release=0
00277   if (release != 0)
00278   {
00279     if (this->buf_len_ != 0 && this->release_ != 0)
00280       this->allocator_->free (this->rep_);
00281 
00282     this->rep_ = &ACE_String_Base<CHAR>::NULL_String_;
00283   this->len_ = 0;
00284     this->buf_len_ = 0;
00285     this->release_ = 0;
00286 }
00287   else
00288   {
00289     this->fast_clear ();
00290   }
00291 }

template<class CHAR>
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 361 of file String_Base.cpp.

References ace_min(), ACE_TRACE, ACE_String_Base< CHAR >::len_, ACE_OS::memcmp(), and ACE_String_Base< CHAR >::rep_.

Referenced by ACE_String_Base< CHAR >::operator<(), and ACE_String_Base< CHAR >::operator>().

00362 {
00363   ACE_TRACE ("ACE_String_Base<CHAR>::compare");
00364 
00365   if (this->rep_ == s.rep_)
00366     return 0;
00367 
00368   // Pick smaller of the two lengths and perform the comparison.
00369   size_t smaller_length = ace_min (this->len_, s.len_);
00370 
00371   int result = ACE_OS::memcmp (this->rep_,
00372                                s.rep_,
00373                                smaller_length * sizeof (CHAR));
00374 
00375   if (!result)
00376     result = static_cast<int> (this->len_ - s.len_);
00377   return result;
00378 }

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

Dump the state of an object.

Definition at line 13 of file String_Base.inl.

References ACE_TRACE.

00014 {
00015 #if defined (ACE_HAS_DUMP)
00016   ACE_TRACE ("ACE_String_Base<CHAR>::dump");
00017 #endif /* ACE_HAS_DUMP */
00018 }

template<class CHAR>
ACE_INLINE bool ACE_String_Base< CHAR >::empty void   )  const
 

Return true if the length of the string is zero, else false. We recommend using is_empty() instead since it's more consistent with the ACE container naming conventions.

Definition at line 43 of file String_Base.inl.

References ACE_String_Base< CHAR >::is_empty().

00044 {
00045   return this->is_empty ();
00046 }

template<class CHAR>
void ACE_String_Base< CHAR >::fast_clear void   ) 
 

A more specialized version of clear(): "fast clear". fast_clear() resets the string to 0 length. If the string owns the buffer (

  • release_== 1):
    • the string buffer is not freed
    • the first character of the buffer is set to 0.
If
  • release_ is 0 (this object does not own the buffer):
    • the buffer pointer is reset to the NULL_String_ and does not maintain a pointer to the caller-supplied buffer on return
    • the maximum string length is reset to 0.
Warning : Calling clear(0) or fast_clear() can have unintended side-effects if the string was constructed (or set()) with an external buffer. The string will be disassociated with the buffer and the next append() or +=() will cause a new buffer to be allocated internally.

Definition at line 329 of file String_Base.cpp.

References ACE_String_Base< CHAR >::buf_len_, and ACE_String_Base< CHAR >::release_.

Referenced by ACE_String_Base< CHAR >::clear().

00330 {
00331   this->len_ = 0;
00332   if (this->release_ != 0)
00333     {
00334       // String retains the original buffer.
00335       if (this->rep_ != &ACE_String_Base<CHAR>::NULL_String_)
00336         this->rep_[0] = 0;
00337     }
00338   else
00339     {
00340       // External buffer: string relinquishes control of it.
00341       this->buf_len_ = 0;
00342       this->rep_ = &ACE_String_Base<CHAR>::NULL_String_;
00343     }
00344 }

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 75 of file String_Base.inl.

Referenced by ACE_Configuration_Heap::add_section(), ACE_Registry_Name_Space::bind(), ACE_Ini_ImpExp::export_section(), ACE_Registry_ImpExp::export_section(), ACE_Configuration_Heap::find_value(), ACE_Configuration_Heap::get_binary_value(), ACE_Configuration_Heap::get_integer_value(), ACE::get_ip_interfaces(), ACE_Configuration_Heap::get_string_value(), ACE_Configuration_Heap::new_section(), ACE_Configuration_Heap::open_simple_section(), operator<<(), ACE_Service_Gestalt::process_commandline_directives(), ACE_Service_Gestalt::process_directives(), ACE_Registry_Name_Space::rebind(), ACE_Configuration_Heap::remove_section(), ACE_Configuration_Heap::remove_value(), ACE_Registry_Name_Space::resolve(), ACE_Configuration_Heap::set_binary_value(), ACE_Configuration_Heap::set_integer_value(), ACE_Configuration_Heap::set_string_value(), and ACE_Registry_Name_Space::unbind().

00076 {
00077   return this->rep_;
00078 }

template<class CHAR>
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 414 of file String_Base.cpp.

References ACE_OS::strnchr().

00415 {
00416   CHAR *substr = this->rep_ + pos;
00417   CHAR *pointer = ACE_OS::strnchr (substr, c, this->len_ - pos);
00418   if (pointer == 0)
00419     return ACE_String_Base<CHAR>::npos;
00420   else
00421     return pointer - this->rep_;
00422 }

template<class CHAR>
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 402 of file String_Base.cpp.

References ACE_OS::strlen(), and ACE_OS::strnstr().

00403 {
00404   CHAR *substr = this->rep_ + pos;
00405   size_t len = ACE_OS::strlen (s);
00406   CHAR *pointer = ACE_OS::strnstr (substr, s, len);
00407   if (pointer == 0)
00408     return ACE_String_Base<CHAR>::npos;
00409   else
00410     return pointer - this->rep_;
00411 }

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

Find 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 121 of file String_Base.inl.

References ACE_TRACE, and ACE_String_Base< CHAR >::rep_.

Referenced by ACE_Get_Opt::long_option_i(), ACE_Registry::make_name(), ACE_String_Base< CHAR >::strstr(), and ACE_Utils::UUID::UUID().

00122 {
00123   ACE_TRACE ("ACE_String_Base<CHAR>::find");
00124   return this->find (str.rep_, pos);
00125 }

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

Returns a hash value for this string.

Returns:
Hash value of string

Definition at line 245 of file String_Base.cpp.

References ACE::hash_pjw().

Referenced by ACE_Configuration_ExtId::hash(), and ACE_Hash< ACE_CString >::operator()().

00246 {
00247   return
00248     ACE::hash_pjw (reinterpret_cast<char *> (
00249                       const_cast<CHAR *> (this->rep_)),
00250                    this->len_ * sizeof (CHAR));
00251 }

template<class CHAR>
ACE_INLINE bool ACE_String_Base< CHAR >::is_empty void   )  const
 

Return true if the length of the string is zero, else false.

Definition at line 37 of file String_Base.inl.

Referenced by ACE_String_Base< CHAR >::empty().

00038 {
00039   return this->len_ == 0;
00040 }

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 30 of file String_Base.inl.

References ACE_TRACE.

Referenced by ACE_Configuration_Heap::add_section(), ACE_Remote_Name_Space::bind(), ACE_Registry_Name_Space::bind(), ACE_Ini_ImpExp::export_section(), ACE_Registry_ImpExp::export_section(), ACE_DLL_Handle::get_dll_names(), ACE::get_ip_interfaces(), ACE_Capabilities::getline(), ACE_Remote_Name_Space::list_name_entries(), ACE_Remote_Name_Space::list_names(), ACE_Remote_Name_Space::list_type_entries(), ACE_Remote_Name_Space::list_types(), ACE_Remote_Name_Space::list_value_entries(), ACE_Remote_Name_Space::list_values(), ACE_Configuration_Heap::new_section(), ACE_DLL_Handle::open(), ACE_Configuration_Heap::open_simple_section(), operator+(), ACE_Remote_Name_Space::rebind(), ACE_Registry_Name_Space::rebind(), ACE_Configuration_Heap::remove_section(), ACE_Remote_Name_Space::resolve(), ACE_Configuration_Heap::set_string_value(), ACE_Local_Name_Space<, ACE_LOCK >::shared_bind_i(), ACE_Utils::UUID::to_string(), ACE_Remote_Name_Space::unbind(), ACE_Utils::UUID::UUID(), ACE_OutputCDR::write_string(), and ACE_SizeCDR::write_string().

00031 {
00032   ACE_TRACE ("ACE_String_Base<CHAR>::length");
00033   return this->len_;
00034 }

template<class CHAR>
ACE_INLINE bool ACE_String_Base< CHAR >::operator!= const CHAR *  s  )  const
 

Inequality comparison operator.

Parameters:
s Null terminated string to compare against stored string.
Returns:
true if not equal, false otherwise.

Definition at line 115 of file String_Base.inl.

00116 {
00117   return !(*this == s);
00118 }

template<class CHAR>
ACE_INLINE bool 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:
true if not equal, false otherwise.

Definition at line 108 of file String_Base.inl.

References ACE_TRACE.

00109 {
00110   ACE_TRACE ("ACE_String_Base<CHAR>::operator!=");
00111   return !(*this == s);
00112 }

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

Concat operator (copies memory).

Parameters:
c Input CHAR to concatenate to this string.
Returns:
The combined string (input append to the end of the old). New string is zero terminated.

Definition at line 509 of file String_Base.cpp.

References ACE_TRACE, and ACE_String_Base< CHAR >::append().

00510 {
00511   ACE_TRACE ("ACE_String_Base<CHAR>::operator+=(const CHAR)");
00512   const size_t slen = 1;
00513   return this->append(&c, slen);
00514 }

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

Concat operator (copies memory).

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

Definition at line 493 of file String_Base.cpp.

References ACE_String_Base< CHAR >::append(), and ACE_OS::strlen().

00494 {
00495   size_t slen = 0;
00496   if (s != 0)
00497     slen = ACE_OS::strlen (s);
00498   return this->append (s, slen);
00499 }

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 this string.
Returns:
The combined string (input append to the end of the old). New string is zero terminated.

Definition at line 502 of file String_Base.cpp.

References ACE_TRACE, ACE_String_Base< CHAR >::append(), ACE_String_Base< CHAR >::len_, and ACE_String_Base< CHAR >::rep_.

00503 {
00504   ACE_TRACE ("ACE_String_Base<CHAR>::operator+=(const ACE_String_Base<CHAR> &)");
00505   return this->append(s.rep_, s.len_);
00506 }

template<class CHAR>
ACE_INLINE bool 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:
true if less than, false otherwise.

Definition at line 89 of file String_Base.inl.

References ACE_TRACE, and ACE_String_Base< CHAR >::compare().

00090 {
00091   ACE_TRACE ("ACE_String_Base<CHAR>::operator <");
00092   return compare (s) < 0;
00093 }

template<class CHAR>
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 305 of file String_Base.cpp.

References ACE_TRACE, ACE_String_Base< CHAR >::len_, ACE_String_Base< CHAR >::rep_, and ACE_String_Base< CHAR >::set().

00306 {
00307   ACE_TRACE ("ACE_String_Base<CHAR>::operator=");
00308 
00309   // Check for identify.
00310   if (this != &s)
00311     {
00312       this->set (s.rep_, s.len_, 1);
00313     }
00314 
00315   return *this;
00316 }

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

Assignment operator (does copy memory).

Parameters:
s Input null-terminated CHAR string to assign to this object.
Returns:
Return a copy of the this string.

Definition at line 295 of file String_Base.cpp.

References ACE_TRACE, and ACE_String_Base< CHAR >::set().

00296 {
00297   ACE_TRACE ("ACE_String_Base<CHAR>::operator=");
00298   if (s != 0)
00299     this->set (s, 1);
00300   return *this;
00301 }

template<class CHAR>
bool ACE_String_Base< CHAR >::operator== const CHAR *  s  )  const
 

Equality comparison operator (must match entire string).

Parameters:
s Null terminated string to compare against stored string.
Returns:
true if equal, false otherwise.

Definition at line 392 of file String_Base.cpp.

References ACE_OS::memcmp(), and ACE_OS::strlen().

00393 {
00394   size_t len = ACE_OS::strlen (s);
00395   return this->len_ == len &&
00396          ACE_OS::memcmp (this->rep_,
00397                          s,
00398                          len * sizeof (CHAR)) == 0;
00399 }

template<class CHAR>
bool 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:
true if equal, false otherwise.

Definition at line 383 of file String_Base.cpp.

References ACE_String_Base< CHAR >::len_, ACE_OS::memcmp(), and ACE_String_Base< CHAR >::rep_.

00384 {
00385   return this->len_ == s.len_ &&
00386          ACE_OS::memcmp (this->rep_,
00387                          s.rep_,
00388                          this->len_ * sizeof (CHAR)) == 0;
00389 }

template<class CHAR>
ACE_INLINE bool 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:
true if greater than, false otherwise.

Definition at line 98 of file String_Base.inl.

References ACE_TRACE, and ACE_String_Base< CHAR >::compare().

00099 {
00100   ACE_TRACE ("ACE_String_Base<CHAR>::operator >");
00101   return compare (s) > 0;
00102 }

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 68 of file String_Base.inl.

References ACE_TRACE.

00069 {
00070   ACE_TRACE ("ACE_String_Base<CHAR>::operator[]");
00071   return this->rep_[slot];
00072 }

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 59 of file String_Base.inl.

References ACE_TRACE.

00060 {
00061   ACE_TRACE ("ACE_String_Base<CHAR>::operator[]");
00062   return this->rep_[slot];
00063 }

template<class CHAR>
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 349 of file String_Base.cpp.

References ACE_NEW_RETURN, ACE_TRACE, and ACE_OS::strsncpy().

Referenced by ACE_Remote_Name_Space::bind(), ACE_Configuration::expand_path(), ACE_Remote_Name_Space::list_name_entries(), ACE_Remote_Name_Space::list_names(), ACE_Remote_Name_Space::list_type_entries(), ACE_Remote_Name_Space::list_types(), ACE_Remote_Name_Space::list_value_entries(), ACE_Remote_Name_Space::list_values(), ACE_Remote_Name_Space::rebind(), ACE_Remote_Name_Space::resolve(), ACE_Local_Name_Space<, ACE_LOCK >::shared_bind_i(), and ACE_Remote_Name_Space::unbind().

00350 {
00351   ACE_TRACE ("ACE_String_Base<CHAR>::rep");
00352 
00353   CHAR *new_string;
00354   ACE_NEW_RETURN (new_string, CHAR[this->len_ + 1], 0);
00355   ACE_OS::strsncpy (new_string, this->rep_, this->len_+1);
00356 
00357   return new_string;
00358 }

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 ;-)

Warning : This method was documented incorrectly in the past. The original intention was to change the length of the string to len, and to fill the whole thing with c CHARs. However, what was actually done was to set the length of the string to zero, and fill the buffer with c's. The buffer was also not null-terminated unless c happened to be zero. Rather than fix the method to work as documented, the code is left as is, but the second parameter should probably not be used.

Parameters:
len The number of CHARs to reserve
c The CHAR to use when filling the string.

Definition at line 254 of file String_Base.cpp.

References ACE_TRACE, ACE_String_Base< CHAR >::buf_len_, ACE_Allocator::free(), ACE_Allocator::malloc(), ACE_OS::memset(), and ACE_String_Base< CHAR >::release_.

Referenced by ACE_String_Base< CHAR >::ACE_String_Base(), and ACE_Registry_Name_Space::resolve().

00255 {
00256   ACE_TRACE ("ACE_String_Base<CHAR>::resize");
00257 
00258   // Only reallocate if we don't have enough space...
00259   if (this->buf_len_ <= len)
00260     {
00261     if (this->buf_len_ != 0 && this->release_ != 0)
00262         this->allocator_->free (this->rep_);
00263 
00264     this->rep_ = static_cast<CHAR*>(
00265       this->allocator_->malloc ((len + 1) * sizeof (CHAR)));
00266       this->buf_len_ = len + 1;
00267       this->release_ = 1;
00268     }
00269   this->len_ = 0;
00270   ACE_OS::memset (this->rep_, c, this->buf_len_ * sizeof (CHAR));
00271 }

template<class CHAR>
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 425 of file String_Base.cpp.

References ssize_t.

Referenced by ACE_DLL_Handle::get_dll_names().

00426 {
00427   if (pos == npos || pos > static_cast<ssize_t> (this->len_))
00428     pos = static_cast<ssize_t> (this->len_);
00429 
00430   for (ssize_t i = pos - 1; i >= 0; i--)
00431     if (this->rep_[i] == c)
00432       return i;
00433 
00434   return ACE_String_Base<CHAR>::npos;
00435 }

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).

If release == 1 then a new buffer is allocated internally if the existing one is not big enough to hold s. If the existing buffer is big enough, then it will be used. This means that set(*, *, 1) is illegal when the string is constructed with a non-owned const char*. (e.g. ACE_String_Base("test", 0, 0))

If release == 0 then the s buffer is used directly, and any existing buffer is destroyed. If s == 0 then it will _not_ be used, and instead the internal buffer is set to NULL_String_.

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 123 of file String_Base.cpp.

References ACE_ALLOCATOR, ACE_String_Base< CHAR >::buf_len_, ACE_Allocator::free(), ACE_OS::memcpy(), and ACE_String_Base< CHAR >::release_.

00124 {
00125   // Case 1. Going from memory to more memory
00126   size_t new_buf_len = len + 1;
00127   if (s != 0 && len != 0 && release && this->buf_len_ < new_buf_len)
00128     {
00129       CHAR *temp;
00130       ACE_ALLOCATOR (temp,
00131                      (CHAR *) this->allocator_->malloc (new_buf_len * sizeof (CHAR)));
00132 
00133     if (this->buf_len_ != 0 && this->release_ != 0)
00134         this->allocator_->free (this->rep_);
00135 
00136       this->rep_ = temp;
00137       this->buf_len_ = new_buf_len;
00138       this->release_ = 1;
00139       this->len_ = len;
00140       ACE_OS::memcpy (this->rep_, s, len * sizeof (CHAR));
00141     this->rep_[len] = 0;
00142     }
00143   else // Case 2. No memory allocation is necessary.
00144     {
00145       // Free memory if necessary and figure out future ownership
00146     if (release == 0 || s == 0 || len == 0)
00147         {
00148       if (this->buf_len_ != 0 && this->release_ != 0)
00149             {
00150               this->allocator_->free (this->rep_);
00151               this->release_ = 0;
00152             }
00153         }
00154       // Populate data.
00155       if (s == 0 || len == 0)
00156         {
00157           this->buf_len_ = 0;
00158           this->len_ = 0;
00159           this->rep_ = &ACE_String_Base<CHAR>::NULL_String_;
00160       this->release_ = 0;
00161         }
00162     else if (release == 0) // Note: No guarantee that rep_ is null terminated.
00163         {
00164           this->buf_len_ = len;
00165           this->len_ = len;
00166           this->rep_ = const_cast <CHAR *> (s);
00167       this->release_ = 0;
00168         }
00169       else
00170         {
00171           ACE_OS::memcpy (this->rep_, s, len * sizeof (CHAR));
00172           this->rep_[len] = 0;
00173           this->len_ = len;
00174         }
00175     }
00176 }

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

Copy s into this ACE_String_Base.

If release == 1 then a new buffer is allocated internally if the existing one is not big enough to hold s. If the existing buffer is big enough, then it will be used. This means that set(*, 1) can be illegal when the string is constructed with a const char*. (e.g. ACE_String_Base("test", 0, 0)).

if release == 0 then the s buffer is used directly, and any existing buffer is destroyed. If s == 0 then it will _not_ be used, and instead the internal buffer is set to NULL_String_.

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

Definition at line 319 of file String_Base.cpp.

References ACE_OS::strlen().

Referenced by ACE_String_Base< CHAR >::ACE_String_Base(), ACE_String_Base< CHAR >::assign_nocopy(), ACE_Capabilities::getline(), ACE_String_Base< CHAR >::operator=(), ACE_Codeset_Registry::registry_to_locale(), and ACE_Codeset_Registry::registry_to_locale_i().

00320 {
00321   size_t length = 0;
00322   if (s != 0)
00323     length = ACE_OS::strlen (s);
00324 
00325   this->set (s, length, release);
00326 }

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 128 of file String_Base.inl.

References ACE_TRACE, ACE_String_Base< CHAR >::find(), and ACE_String_Base< CHAR >::rep_.

Referenced by ACE_DLL_Handle::open().

00129 {
00130   ACE_TRACE ("ACE_String_Base<CHAR>::strstr");
00131   return this->find (s.rep_);
00132 }

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

Same as .

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 49 of file String_Base.inl.

References ACE_TRACE, ssize_t, and ACE_String_Base< CHAR >::substring().

Referenced by ACE_DLL_Handle::get_dll_names(), ACE_Registry::make_name(), and ACE_Utils::UUID::UUID().

00051 {
00052   ACE_TRACE ("ACE_String_Base<CHAR>::substr");
00053   return this->substring (offset, length);
00054 }

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 180 of file String_Base.cpp.

References ssize_t.

Referenced by ACE::get_ip_interfaces(), and ACE_String_Base< CHAR >::substr().

00181 {
00182   ACE_String_Base<CHAR> nill;
00183   size_t count = length;
00184 
00185   // case 1. empty string
00186   if (this->len_ == 0)
00187     return nill;
00188 
00189   // case 2. start pos past our end
00190   if (offset >= this->len_)
00191     return nill;
00192   // No length == empty string.
00193   else if (length == 0)
00194     return nill;
00195   // Get all remaining bytes.
00196   else if (length == -1 || count > (this->len_ - offset))
00197     count = this->len_ - offset;
00198 
00199   return ACE_String_Base<CHAR> (&this->rep_[offset], count, this->allocator_);
00200 }


Member Data Documentation

template<class CHAR>
ACE_String_Base< CHAR >::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 499 of file String_Base.h.

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

Pointer to a memory allocator.

Definition at line 505 of file String_Base.h.

template<class CHAR>
size_t ACE_String_Base< CHAR >::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 516 of file String_Base.h.

Referenced by ACE_String_Base< CHAR >::append(), ACE_String_Base< CHAR >::clear(), ACE_String_Base< CHAR >::fast_clear(), ACE_String_Base< CHAR >::resize(), ACE_String_Base< CHAR >::set(), and ACE_String_Base< CHAR >::~ACE_String_Base().

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

Length of the ACE_String_Base data (not counting the trailing '').

Definition at line 510 of file String_Base.h.

Referenced by ACE_String_Base< CHAR >::ACE_String_Base(), ACE_String_Base< CHAR >::assign_nocopy(), ACE_String_Base< CHAR >::compare(), ACE_String_Base< CHAR >::operator+=(), ACE_String_Base< CHAR >::operator=(), and ACE_String_Base< CHAR >::operator==().

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

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

Definition at line 21 of file String_Base.cpp.

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

Flag that indicates if we own the memory

Definition at line 526 of file String_Base.h.

Referenced by ACE_String_Base< CHAR >::append(), ACE_String_Base< CHAR >::clear(), ACE_String_Base< CHAR >::fast_clear(), ACE_String_Base< CHAR >::resize(), ACE_String_Base< CHAR >::set(), and ACE_String_Base< CHAR >::~ACE_String_Base().

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

Pointer to data.

Definition at line 521 of file String_Base.h.

Referenced by ACE_String_Base< CHAR >::ACE_String_Base(), ACE_String_Base< CHAR >::assign_nocopy(), ACE_String_Base< CHAR >::compare(), ACE_String_Base< CHAR >::find(), ACE_String_Base< CHAR >::operator+=(), ACE_String_Base< CHAR >::operator=(), ACE_String_Base< CHAR >::operator==(), and ACE_String_Base< CHAR >::strstr().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:30:26 2006 for ACE by doxygen 1.3.6