# 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 >:

[legend]
Collaboration diagram for ACE_String_Base< CHAR >:

[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
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 ACE_String_Base< CHAR > &s) const
bool | operator> (const ACE_String_Base< CHAR > &s) const
bool | 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_Allocator * | allocator_
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.

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

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

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

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

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'

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

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

| Deletes the memory...

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

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.

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

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

Clear this string. Memory is _not_ freed if <release> 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.

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.

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

| Dump the state of an object.

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.

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.

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.

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.

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.

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

Returns a hash value for this string.

Returns:
  Hash value of string

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

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:
  Integer value of result (`true` = not equal, `false` = equal).

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.

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.

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.

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:
  Integer value of result (`true` = less than, `false` = greater than or equal).

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.

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.

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:
  Integer value of result (`true` = found, `false` = not found).

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:
  Integer value of result (`true` = greater than, `false` = less than or equal).

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

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

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.

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.

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.

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.

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.

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

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

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

## Member Data Documentation

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

| Declare the dynamic allocation hooks.

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

| Pointer to a memory allocator.

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.

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

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

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.

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

| Flag that indicates if we own the memory

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

| Pointer to data.

The documentation for this class was generated from the following files:

- String_Base.h
- String_Base.cpp
- String_Base.inl