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

ACE_CString Class Reference

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

#include <SString.h>

Collaboration diagram for ACE_CString:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_CString (ACE_Allocator *alloc = 0)
 Default constructor.

 ACE_CString (const char *s, ACE_Allocator *alloc = 0, int release = 1)
 ACE_CString (const char *s, size_t len, ACE_Allocator *alloc = 0, int release = 1)
 ACE_CString (const ACE_CString &)
 Copy constructor.

 ACE_CString (const ACE_WSTRING_TYPE *s, ACE_Allocator *alloc = 0)
 Constructor that copies <s> into dynamically allocated memory. Probable loss of data. Please use with care.

 ACE_CString (char c, ACE_Allocator *alloc = 0)
 Constructor that copies <c> into dynamically allocated memory.

 ~ACE_CString (void)
 Deletes the memory...

const char& operator[] (size_t slot) const
 Return the <slot'th> character in the string (doesn't perform bounds checking).

char& operator[] (size_t slot)
 Return the <slot'th> character by reference in the string (doesn't perform bounds checking).

ACE_CString& operator= (const ACE_CString &)
 Assignment operator(does copy memory).

void set (const char *s, int release = 1)
 Copy <s> into this . Memory is _not_ allocated/freed if <release> is 0.

void set (const char *s, size_t len, int release)
 Copy <len> bytes of <s> (will NUL terminate the result). Memory is _not_ allocated/freed if <release> is 0.

void clear (int release = 0)
 Clear this string. Memory is _not_ freed is <release> is 0.

ACE_CString substring (size_t offset, ssize_t length = -1) const
ACE_CString substr (size_t offset, ssize_t length = -1) const
 Same as <substring>.

ACE_CString& operator+= (const ACE_CString &)
 Concat operator(copies memory).

u_long hash (void) const
 Returns a hash value for this string.

size_t length (void) const
 Return the length of the string.

char* rep (void) const
 Get a copy of the underlying pointer.

const char* fast_rep (void) const
const char* c_str (void) const
 Same as STL String's <c_str> and <fast_rep>.

int strstr (const ACE_CString &s) const
 Comparison operator that will match substrings. Returns the slot of the first location that matches, else -1.

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

int find (const char *s, int pos = 0) const
 Find <s> starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos.

int find (char c, int pos = 0) const
 Find <c> starting at pos. Returns the slot of the first location that matches (will be >= pos), else npos.

int rfind (char c, int pos = npos) const
 Find <c> starting at pos (counting from the end). Returns the slot of the first location that matches, else npos.

int operator== (const ACE_CString &s) const
 Equality comparison operator(must match entire string).

int operator< (const ACE_CString &s) const
 Less than comparison operator.

int operator> (const ACE_CString &s) const
 Greater than comparison operator.

int operator!= (const ACE_CString &s) const
 Inequality comparison operator.

int compare (const ACE_CString &s) const
 Performs a <strcmp>-style comparison.

void dump (void) const
 Dump the state of an object.


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Static Public Attributes

const int npos
 No position constant.


Private Attributes

ACE_Allocatorallocator_
 Pointer to a memory allocator.

size_t len_
 Length of the ACE_CString data (not counting the trailing '\0').

size_t buf_len_
 Length of the ACE_CString data buffer. Keeping track of the length allows to avoid unnecessary dynamic allocations.

char* rep_
 Pointer to data.

int release_
 Flag that indicates if we own the memory.


Static Private Attributes

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


Detailed Description

This class provides a wrapper facade for C strings.

This class uses an 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_CString is constructed from a provided buffer with the release parameter set to 0, ACE_CString is not guaranteed to be '\0' terminated.


Constructor & Destructor Documentation

ACE_INLINE ACE_CString::ACE_CString ( ACE_Allocator * alloc = 0 )
 

Default constructor.

ACE_INLINE ACE_CString::ACE_CString ( 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 is responsible for freeing this memory. Memory is _not_ allocated/freed if <release> is 0.

ACE_INLINE ACE_CString::ACE_CString ( 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 NUL terminate the result). If <release> is non-0 then the is responsible for freeing this memory. Memory is _not_ allocated/freed if <release> is 0.

ACE_INLINE ACE_CString::ACE_CString ( const ACE_CString & s )
 

Copy constructor.

ACE_CString::ACE_CString ( const ACE_WSTRING_TYPE * s,
ACE_Allocator * alloc = 0 )
 

Constructor that copies <s> into dynamically allocated memory. Probable loss of data. Please use with care.

ACE_INLINE ACE_CString::ACE_CString ( char c,
ACE_Allocator * alloc = 0 )
 

Constructor that copies <c> into dynamically allocated memory.

ACE_INLINE ACE_CString::~ACE_CString ( void )
 

Deletes the memory...


Member Function Documentation

ACE_INLINE const char * ACE_CString::c_str ( void ) const
 

Same as STL String's <c_str> and <fast_rep>.

ACE_INLINE void ACE_CString::clear ( int release = 0 )
 

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

ACE_INLINE int ACE_CString::compare ( const ACE_CString & s ) const
 

Performs a <strcmp>-style comparison.

ACE_INLINE void ACE_CString::dump ( void ) const
 

Dump the state of an object.

ACE_INLINE const char * ACE_CString::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!

ACE_INLINE int ACE_CString::find ( char c,
int pos = 0 ) const
 

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

ACE_INLINE int ACE_CString::find ( const char * s,
int pos = 0 ) const
 

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

ACE_INLINE int ACE_CString::find ( const ACE_CString & str,
int pos = 0 ) const
 

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

ACE_INLINE u_long ACE_CString::hash ( void ) const
 

Returns a hash value for this string.

ACE_INLINE size_t ACE_CString::length ( void ) const
 

Return the length of the string.

ACE_INLINE int ACE_CString::operator!= ( const ACE_CString & s ) const
 

Inequality comparison operator.

ACE_CString & ACE_CString::operator+= ( const ACE_CString & s )
 

Concat operator(copies memory).

ACE_INLINE int ACE_CString::operator< ( const ACE_CString & s ) const
 

Less than comparison operator.

ACE_INLINE ACE_CString & ACE_CString::operator= ( const ACE_CString & s )
 

Assignment operator(does copy memory).

ACE_INLINE int ACE_CString::operator== ( const ACE_CString & s ) const
 

Equality comparison operator(must match entire string).

ACE_INLINE int ACE_CString::operator> ( const ACE_CString & s ) const
 

Greater than comparison operator.

ACE_INLINE char & ACE_CString::operator[] ( size_t slot )
 

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

ACE_INLINE const char & ACE_CString::operator[] ( size_t slot ) const
 

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

ACE_INLINE char * ACE_CString::rep ( void ) const
 

Get a copy of the underlying pointer.

ACE_INLINE int ACE_CString::rfind ( char c,
int pos = npos ) const
 

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

void ACE_CString::set ( const char * s,
size_t len,
int release )
 

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

ACE_INLINE void ACE_CString::set ( const char * s,
int release = 1 )
 

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

ACE_INLINE int ACE_CString::strstr ( const ACE_CString & s ) const
 

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

ACE_INLINE ACE_CString ACE_CString::substr ( size_t offset,
ssize_t length = -1 ) const
 

Same as <substring>.

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


Member Data Documentation

ACE_CString::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

char ACE_CString::NULL_CString_ [static, private]
 

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

ACE_Allocator * ACE_CString::allocator_ [private]
 

Pointer to a memory allocator.

size_t ACE_CString::buf_len_ [private]
 

Length of the ACE_CString data buffer. Keeping track of the length allows to avoid unnecessary dynamic allocations.

size_t ACE_CString::len_ [private]
 

Length of the ACE_CString data (not counting the trailing '\0').

const int ACE_CString::npos [static]
 

No position constant.

int ACE_CString::release_ [private]
 

Flag that indicates if we own the memory.

char * ACE_CString::rep_ [private]
 

Pointer to data.


The documentation for this class was generated from the following files:
Generated at Fri Oct 5 07:01:44 2001 for ACE by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000