#include <WOscString.h>
Public Member Functions | |
WOscString (const char *string="") | |
WOscString (const WOscString &rhs) | |
~WOscString () | |
WOscString & | operator= (const char rhs) |
WOscString & | operator= (const char *rhs) |
WOscString & | operator= (const WOscString &rhs) |
WOscString | operator+ (const WOscString &rhs) |
WOscString & | operator+= (const char rhs) |
WOscString & | operator+= (const char *rhs) |
WOscString & | operator+= (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 |
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.
WOscClient.cpp, WOscServer.cpp, and WOscStreamingClient.cpp.
Definition at line 52 of file WOscString.h.
WOscString::WOscString | ( | const char * | string = "" |
) |
Constructs an OSC-String from a string. Aligns it internally to a 4-byte boundary.
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.
rhs | Reference of an OSC-string object. |
Definition at line 67 of file WOscString.cpp.
WOscString::~WOscString | ( | ) |
Destructor. Frees the memory required by the internal buffer (if not empty).
Definition at line 77 of file WOscString.cpp.
const char * WOscString::GetBuffer | ( | ) | const |
Returns a pointer to an internal OSC-string-buffer. Please See remarks for safety issues.
Definition at line 313 of file WOscString.cpp.
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.
buffer | Caller supplied destination buffer. | |
bufferLen | Length of the supplied buffer. |
WOscException | When caller supplied buffer too small. |
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.
Definition at line 262 of file WOscString.cpp.
Referenced by WOscMessage::WOscMessage().
WOscString::operator const char * | ( | ) | const |
Typecast operator for convenience.
Definition at line 354 of file WOscString.cpp.
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.
rhs | Reference to an object to append. |
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.
rhs | Reference to an object to append. |
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.
rhs | String to be appended to the left hand 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.
rhs | Character to be appended to the left hand object. |
Definition at line 186 of file WOscString.cpp.
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.
rhs | Reference of the source object. |
Definition at line 135 of file WOscString.cpp.
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.
rhs | Reference of the source string. |
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.
rhs | Char beeing assigned to the current OSC string. |
Definition at line 92 of file WOscString.cpp.
bool WOscString::operator== | ( | const WOscString & | rhs | ) | const |
Comparison operator. Compares the right-hand OSC string reference with the current OSC object.
rhs | Reference of an OSC string object. |
Definition at line 330 of file WOscString.cpp.