00001 /* 00002 * WOscLib, an object oriented OSC library. 00003 * Copyright (C) 2005 Uli Clemens Franke, Weiss Engineering LTD, Switzerland. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 * 00019 * For details see lgpl.txt 00020 * 00021 * Weiss Engineering LTD. 00022 * Florastrass 42 00023 * 8610 Uster 00024 * Switzerland 00025 * 00026 * uli.franke@weiss.ch 00027 */ 00028 00029 /** WOscUtil header file. 00030 * \file 00031 * 00032 * $Author: cls-nebadje $ ( \ref _UcfWOscLib ) 00033 * $Date: 2006-05-16 21:21:41 $ 00034 * $Revision: 1.3 $ 00035 * 00036 * Copyright (c) Weiss Engineering Ltd 00037 * 00038 */ 00039 00040 #ifndef __WOSCUTIL_H__ 00041 #define __WOSCUTIL_H__ 00042 00043 #include "WOscLib.h" 00044 00045 /** Weiss OSC library utilities. 00046 * Mostly buffer-to-type and type-to-buffer conversions, 00047 * big/little-endianess issues and 4-byte-boundary 00048 * utilities. 00049 * 00050 */ 00051 class WOSC_EXPORT WOscUtil{ 00052 public: 00053 static int GetSizeFourByteAligned(const char* string); 00054 static int GetSizeFourByteAligned(const int length); 00055 static void PadStringWithZeros(char* destString, const char* sourceString); 00056 static void PadBufferWithZeros(char* destBuffer, const char* sourceBuffer, int destLen, int srcLen); 00057 template <class TYPE> static TYPE BufferTo(const char* buffer) 00058 { 00059 #if IS_LITTLE_ENDIAN == 1 00060 TYPE tmp; 00061 for ( int i = sizeof(TYPE) - 1; i >= 0; i-- ) 00062 reinterpret_cast<char*>(&tmp)[i] = buffer[sizeof(TYPE)-1-i]; 00063 return tmp; 00064 #else 00065 return *reinterpret_cast<const TYPE*>(buffer); 00066 #endif 00067 } 00068 template <class TYPE> static void FillBufferWith(char* buffer, const TYPE& arg) 00069 { 00070 #if IS_LITTLE_ENDIAN == 1 00071 for ( int i = sizeof(TYPE)-1; i >= 0; i-- ) 00072 buffer[i] = reinterpret_cast<const char*>(&arg)[sizeof(TYPE)-1-i]; 00073 #else 00074 memcpy(buffer, &arg, sizeof(TYPE)); 00075 #endif 00076 } 00077 /** Constants used in WOscUtil 00078 * OSC-argument sizes. 00079 * 00080 * \remarks 00081 * Osc arguments are platform independent. 00082 * 00083 * @todo Change all types to int32_t and float and replace OSC_INT_SIZE 00084 * with sizeof(int32_t) and OSC_FLOAT_SIZE with sizeof(float). 00085 */ 00086 enum Constants{ 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 }; 00091 protected: 00092 00093 private: 00094 00095 }; 00096 00097 #endif // #ifndef __WOSCUTIL_H__