NString Class Reference

Inheritance diagram for NString:

StringImp


Public Methods

 NString (const char *in=NULL)
 NString (const NString &str)
 ~NString ()
 operator const char * () const
NString & operator= (const char *str)
NString & operator= (const NString &str)
oa::oaUInt4 length () const

Detailed Description

This is a Narrow String class with a reference counted buffer. When a second NString instance is instantiated from the first one, the pointer to the buffer is copied, and the reference count (for the buffer) is incremented. It is decremented when the NString no longer holds that buffer (such as in the assignment operaor and the destructor). The NString that brings the reference count to zero then frees the memory. This allows for an efficient way of passing strings without having to worry about lifetime and managing the memory for the buffer.


Constructor & Destructor Documentation

NString::NString const char *    in = NULL [explicit]
 

This constructor creates a new NString from a raw character array pointer. It allocates a new buffer, sets the reference count to one, and stores that pointer in it's internal pointer.

Parameters:
in The string with which to initialize this instance of the NString.

NString::NString const NString &    str
 

This copy constructor copies the pointer to the buffer of str to the internal pointer of this NString, then increments the buffer's reference count.

Parameters:
str Another NString to initialize this one from

NString::~NString  
 

This is the destructor for the NString. It decrements the reference count for the buffer, and if it reaches zero, it frees the buffer memory.


Member Function Documentation

uint32 NString::length   const
 

This function returns the length of the character string controlled by this NString.

NString::operator const char *   const [inline]
 

This operator returns a pointer to the internal character array. This pointer is not guarenteed to be valid for the long term; it can be deleted if the NString is destroyed, or if a destructive operation is made to the NString (e.g. an assignment operation).

NString & NString::operator= const NString &    str
 

This is the copy constructor for the NString. It will release its internal buffer and free the memory if the buffer reference goes to zero. It wil then increment the reference count of the buffer in "str", and set the internal buffer pointer to that buffer. Note that the string is not copied in this process. This makes the copy construction operation of the NString very efficient.

Parameters:
str A reference to another NString to assign to this NString

NString & NString::operator= const char *    str
 

This operator is used to assign a new string value into the NString. It will release its internal buffer and free the memory if the buffer reference goes to zero. It will then allocate a new buffer, set the reference count to one, and copy the string in "str" into this new buffer.

Parameters:
str A NULL terminated string to assign to the NString.


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

Return to top of page