WOscUtil Class Reference

#include <WOscUtil.h>

List of all members.

Public Types

enum  Constants { OSC_INT_SIZE = 4, OSC_FLOAT_SIZE = 4 }

Static Public Member Functions

static int GetSizeFourByteAligned (const char *string)
static int GetSizeFourByteAligned (const int length)
static void PadStringWithZeros (char *destString, const char *sourceString)
static void PadBufferWithZeros (char *destBuffer, const char *sourceBuffer, int destLen, int srcLen)
template<class TYPE >
static TYPE BufferTo (const char *buffer)
template<class TYPE >
static void FillBufferWith (char *buffer, const TYPE &arg)

Detailed Description

Weiss OSC library utilities. Mostly buffer-to-type and type-to-buffer conversions, big/little-endianess issues and 4-byte-boundary utilities.

Definition at line 51 of file WOscUtil.h.


Member Enumeration Documentation

Constants used in WOscUtil OSC-argument sizes.

Remarks:
Osc arguments are platform independent.
Todo:
Change all types to int32_t and float and replace OSC_INT_SIZE with sizeof(int32_t) and OSC_FLOAT_SIZE with sizeof(float).
Enumerator:
OSC_INT_SIZE 

OSC-argument integer size.

OSC_FLOAT_SIZE 

OSC-argument float size (Changed from 8 to 4, pointed out by Damian Stewart) .

Definition at line 86 of file WOscUtil.h.

00086                   {
00087         OSC_INT_SIZE    = 4,    /**< OSC-argument integer size. */
00088         OSC_FLOAT_SIZE  = 4,    /**< OSC-argument float size (Changed from 8 to 4,
00089                                  * pointed out by Damian Stewart) . */
00090     };


Member Function Documentation

int WOscUtil::GetSizeFourByteAligned ( const int  length  )  [static]

Rounds up the given integer to the next multiple of 4. Similar to getSizeFourByteAligned(const char* string).

Parameters:
length Integer which sould be rounded up to the next multiple of 4.
Returns:
The rounded integer.
See also:
getSizeFourByteAligned(const char* string)

Definition at line 77 of file WOscUtil.cpp.

00078 {
00079     return length + ( 4 - length % 4 ) % 4;
00080 }

int WOscUtil::GetSizeFourByteAligned ( const char *  string  )  [static]

Get length of string and round up to the next multiple of 4. Gets the size of the string passed as parameter and rounds it up to the next multiple of four.

Parameters:
string String which size should be rounded.
Returns:
Rounded size of the string.
See also:
WOscUtil::getSizeFourByteAligned(const int length)

Definition at line 57 of file WOscUtil.cpp.

Referenced by WOscString::operator+=(), WOscString::operator=(), PadStringWithZeros(), WOscBlob::WOscBlob(), and WOscString::WOscString().

00058 {
00059     int length = (int)strlen(string) + 1;
00060     return length + ( 4 - length % 4 ) % 4;
00061 }

void WOscUtil::PadBufferWithZeros ( char *  destBuffer,
const char *  sourceBuffer,
int  destLen,
int  srcLen 
) [static]

Copies the source buffer to the destination buffer and pads the difference with zeros. The destination buffer must be large enough, i.e. destLen >= srcLen.

Works for every buffer, assumed destLen >= srcLen. If destLen is smaller than srcLen only srcLen data is copied and nothing padded.

Parameters:
destBuffer Destination string buffer (length must be the rounded-up length of the source string), which receives the padded string.
sourceBuffer Source buffer.
destLen Size of the destination-buffer.
srcLen Size of the source-buffer.
See also:
padStringWithZeros(char* destString, const char* sourceString)

Definition at line 138 of file WOscUtil.cpp.

00140 {
00141     if ( destLen <= srcLen )
00142         memcpy(destBuffer, sourceBuffer, destLen);
00143     else {
00144         memcpy(destBuffer, sourceBuffer, srcLen);
00145         memset(destBuffer+srcLen, 0, destLen-srcLen);
00146     }
00147 }

void WOscUtil::PadStringWithZeros ( char *  destString,
const char *  sourceString 
) [static]

Copies the source string to the destination string and pads it with zeros to the next multiple of four, the destination buffer must be large enough.

Parameters:
destString Destination string buffer (length must be the rounded-up length of the source string), which receives the padded string.
sourceString The string which should be padded.
Remarks:
Works only with strings!!!
See also:
For determination of the destination string-buffer-length: getSizeFourByteAligned(const char* string)

Definition at line 102 of file WOscUtil.cpp.

References GetSizeFourByteAligned().

Referenced by WOscString::operator=(), and WOscString::WOscString().

00103 {
00104     int length = (int)strlen(sourceString) + 1;
00105     int osclength = GetSizeFourByteAligned(sourceString);
00106 
00107     strcpy(destString, sourceString);
00108 
00109     for ( int i = length; i < osclength; i++ )
00110         destString[i] = '\0';
00111 }


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