WOscString Class Reference

#include <WOscString.h>

List of all members.

Public Member Functions

 WOscString (const char *string="")
 WOscString (const WOscString &rhs)
 ~WOscString ()
WOscStringoperator= (const char rhs)
WOscStringoperator= (const char *rhs)
WOscStringoperator= (const WOscString &rhs)
WOscString operator+ (const WOscString &rhs)
WOscStringoperator+= (const char rhs)
WOscStringoperator+= (const char *rhs)
WOscStringoperator+= (const WOscString &rhs)
bool operator== (const WOscString &rhs) const
bool operator!= (const WOscString &rhs) const
bool operator== (const char *str) const
bool operator!= (const char *str) const
 operator const char * () const
int GetSize ()
void GetBuffer (char *buffer, int bufferLen)
const char * GetBuffer () const

Detailed Description

Wrapping of OSC specific strings (4-byte aligned). OSC-strings must be 4-byte aligned. The interface of this class guarantees the 4-byte-alignment.

Remarks:
None.
Examples:

WOscClient.cpp, WOscServer.cpp, and WOscStreamingClient.cpp.

Definition at line 52 of file WOscString.h.


Constructor & Destructor Documentation

WOscString::WOscString ( const char *  string = ""  ) 

Constructs an OSC-String from a string. Aligns it internally to a 4-byte boundary.

Parameters:
string Initializing string.

Definition at line 50 of file WOscString.cpp.

References WOscUtil::GetSizeFourByteAligned(), and WOscUtil::PadStringWithZeros().

00050                                         {
00051     /* get four byte aligned size */
00052     m_bufferLen = WOscUtil::GetSizeFourByteAligned(string);
00053     /* allocate mem */
00054     m_buffer = new char[m_bufferLen];
00055     /* copy and pad */
00056     WOscUtil::PadStringWithZeros(m_buffer, string);
00057 }

WOscString::WOscString ( const WOscString rhs  ) 

Copy constructor. Allocates new memory and copies the aligned string from the referenced object.

Parameters:
rhs Reference of an OSC-string object.

Definition at line 67 of file WOscString.cpp.

00067                                            {
00068     /*  allocate */
00069     m_buffer = new char[m_bufferLen = rhs.m_bufferLen];
00070     /* copy */
00071     memcpy(m_buffer,rhs.m_buffer,m_bufferLen); 
00072 }

WOscString::~WOscString (  ) 

Destructor. Frees the memory required by the internal buffer (if not empty).

Definition at line 77 of file WOscString.cpp.

00078 {
00079     delete [] m_buffer;
00080 }


Member Function Documentation

const char * WOscString::GetBuffer (  )  const

Returns a pointer to an internal OSC-string-buffer. Please See remarks for safety issues.

Returns:
Pointer to the internal OSC-string buffer.
Remarks:
The pointer remains valid until the modification of this WOscString-object. The next time the object is destination of an operation (check operators) or the object will be deleted, this pointer possibly gets invalid. If you are not sure about that issue, please use the other getBuffer()- function, which copies the string.
See also:
WOscString::getBuffer(char* buffer, int bufferLen)

Definition at line 313 of file WOscString.cpp.

00314 {
00315     return m_buffer;
00316 }

void WOscString::GetBuffer ( char *  buffer,
int  bufferLen 
)

Fills the buffer with the internal (padded) OSC-string representation. The user must supply a buffer of apropriate size.

Parameters:
buffer Caller supplied destination buffer.
bufferLen Length of the supplied buffer.
Exceptions:
WOscException When caller supplied buffer too small.
Remarks:
This interface makes sure that the buffer remains valid when modifying the WOscString-object afterwards. (contrary to WOscString::getBuffer() )
See also:
WOscString::getBuffer()
Examples:
WOscClient.cpp, WOscServer.cpp, WOscStreamingClient.cpp, and WOscStreamingServer.cpp.

Definition at line 287 of file WOscString.cpp.

References ERR_OSC_STR_BUFF_TOO_SMALL.

Referenced by WOscContainer::DispatchMessage(), and WOscMessage::WOscMessage().

00288 {
00289     if ( bufferLen < m_bufferLen )
00290         throw WOscException(ERR_OSC_STR_BUFF_TOO_SMALL, __FILE__, __LINE__);
00291 
00292     for ( int i = 0; i < bufferLen; i++ )
00293         buffer[i] = m_buffer[i];
00294 }

int WOscString::GetSize (  ) 

Returns the size of the zero-padded OSC-string. Can be used to allocate memory for instance.

Returns:
Size of the internal buffer.
Remarks:
Remains valid until the content of the WOscString-object is changed. See

Definition at line 262 of file WOscString.cpp.

Referenced by WOscMessage::WOscMessage().

00262                        {
00263     return m_bufferLen;
00264 }

WOscString::operator const char * (  )  const

Typecast operator for convenience.

Definition at line 354 of file WOscString.cpp.

00355 {
00356     return m_buffer;
00357 }

WOscString WOscString::operator+ ( const WOscString rhs  ) 

OSC-String concatenation without assignment. Appends the right hand object to the left-hand object but does not save it in the left-hand object. The zeros from the left hand object are removed and the resulting OSC-string is padded to a multiple of 4.

Parameters:
rhs Reference to an object to append.
Returns:
The concatenated object.
Remarks:
Since the operator does not assign, the return value can not be a reference, because its an local and automatic variable.

Definition at line 163 of file WOscString.cpp.

00163                                                       {
00164     WOscString retVal;
00165     if ( m_buffer ){
00166         retVal += *this;
00167         retVal += rhs;
00168     }else{
00169         retVal = rhs;
00170     }
00171     return retVal;
00172 }

WOscString & WOscString::operator+= ( const WOscString rhs  ) 

OSC-String concatenation with assignment. Appends the right hand object to the left-hand object and saves it in the left-hand object. The zeros from the left hand object are removed and the resulting OSC-string is padded to a multiple of 4.

Parameters:
rhs Reference to an object to append.
Returns:
The a reference to the concatenated object.

Definition at line 220 of file WOscString.cpp.

References WOscUtil::GetSizeFourByteAligned().

00220                                                         {
00221 
00222     if ( m_buffer ){
00223 
00224         /* get length of both strings */
00225         int lenLhs = (int)strlen(m_buffer);
00226         int lenRhs = (int)strlen(rhs.m_buffer);
00227 
00228         /* get the size of the combined string aligned to four. */
00229         int newLen = WOscUtil::GetSizeFourByteAligned(lenRhs + lenLhs + 1);
00230 
00231         /* allocate memory */
00232         char* newBuf = new char[newLen];
00233 
00234         /* copy left and right hand side */
00235         memcpy(newBuf, m_buffer, lenLhs); 
00236         memcpy(newBuf+lenLhs, rhs.m_buffer, lenRhs);
00237 
00238         /* pad rest with zeros */
00239         for ( int i = lenLhs + lenRhs; i < newLen; i++ )
00240             newBuf[i] = '\0';
00241 
00242         delete [] m_buffer;     // delete old buffer
00243         m_buffer = newBuf;      // set new string buffer as buffer
00244         m_bufferLen = newLen;   // set length
00245 
00246     }else{
00247         /* if empty, just assign */
00248         *this = rhs;
00249     }
00250     return *this;
00251 }

WOscString & WOscString::operator+= ( const char *  rhs  ) 

String to OSC-String concatenation with assignment. Formats and appends the right hand string to the left-hand object and saves it in the left-hand object. The zeros from the left hand object are removed and the resulting OSC-string is padded to a multiple of 4.

Parameters:
rhs String to be appended to the left hand object.
Returns:
The reference to the concatenated object.

Definition at line 203 of file WOscString.cpp.

00203                                                   {
00204     WOscString tmp(rhs);
00205     return *this += tmp;
00206 }

WOscString & WOscString::operator+= ( const char  rhs  ) 

Character to OSC-String concatenation with assignment. Appends the right hand char to the left-hand object and saves it in the left-hand object. The zeros from the left hand object are removed and the resulting OSC-string is padded to a multiple of 4.

Parameters:
rhs Character to be appended to the left hand object.
Returns:
The reference to the concatenated object.

Definition at line 186 of file WOscString.cpp.

00186                                                  {
00187     char str[] = {rhs,'\0'};
00188     return *this += str;
00189 }

WOscString & WOscString::operator= ( const WOscString rhs  ) 

Assignment operator. Copies the right-hand object-reference into the left-hand object. Frees the old memory and allocates new.

Parameters:
rhs Reference of the source object.
Returns:
Reference of the destination object.

Definition at line 135 of file WOscString.cpp.

00135                                                        {
00136     if ( m_buffer )
00137         delete [] m_buffer;
00138 
00139     m_buffer = new char[m_bufferLen = rhs.m_bufferLen];
00140     memcpy(m_buffer,rhs.m_buffer,m_bufferLen);
00141 
00142     return *this;
00143 }

WOscString & WOscString::operator= ( const char *  rhs  ) 

String to OSC-String assignment operator. Formats (padding) the right-hand string and copies it into the left-hand object. Frees the old memory and allocates new.

Parameters:
rhs Reference of the source string.
Returns:
Reference of the destination object.

Definition at line 111 of file WOscString.cpp.

References WOscUtil::GetSizeFourByteAligned(), and WOscUtil::PadStringWithZeros().

00111                                                  {
00112     delete [] m_buffer;
00113 
00114     /* get four byte aligned size */
00115     m_bufferLen = WOscUtil::GetSizeFourByteAligned(rhs);
00116     /* allocate mem */
00117     m_buffer = new char[m_bufferLen];
00118     /* copy and pad */
00119     WOscUtil::PadStringWithZeros(m_buffer, rhs);
00120     
00121     return *this;
00122 }

WOscString & WOscString::operator= ( const char  rhs  ) 

OSC string char assignment operator. Assigns the right-hand char to the OSC string object.

Parameters:
rhs Char beeing assigned to the current OSC string.
Returns:
Reference of the current OSC string object.

Definition at line 92 of file WOscString.cpp.

00092                                                 {
00093     if ( m_buffer ){
00094         delete [] m_buffer;
00095         m_buffer = NULL;
00096     }
00097     return *this += rhs;
00098 }

bool WOscString::operator== ( const WOscString rhs  )  const

Comparison operator. Compares the right-hand OSC string reference with the current OSC object.

Parameters:
rhs Reference of an OSC string object.
Returns:
True when equal, false when not equal.

Definition at line 330 of file WOscString.cpp.

00331 {
00332     return (strcmp(m_buffer, rhs.m_buffer) == 0);
00333 }


The documentation for this class was generated from the following files:
Generated on Sat Oct 23 03:05:59 2010 for WOscLib by  doxygen 1.6.3