1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
/*------------------------------------------------------------------------------
Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : Util.h
Version : $Revision$
Author : $Author$
Location : $HeadURL$
Copyright notice:
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
------------------------------------------------------------------------------*/
#ifndef UTIL_H
#define UTIL_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Exception.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Widely used utilities.
* This class can not be instantiated, but contains useful (?) static
* functions.
*
* Typical usage:
*
* <pre>
* #include "Util.h"
*
* char * str = Util::strDup( otherStr);
* </pre>
*
* @author $Author$
* @version $Revision$
*/
class Util
{
private:
/**
* Helper table for base64 encoding.
*/
static char base64Table[];
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
Util ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Copy constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
Util ( const Util & e ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Destructor. Always throws an Exception.
*
* @exception Exception
*/
inline
~Util ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Assignment operator. Always throws an Exception.
*
* @param u the object to assign to this one.
* @exception Exception
*/
inline Util &
operator= ( const Util & u ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
public:
/**
* Determine a C string's length.
*
* @param str a zero-terminated C string.
* @return length of str
* @exception Exception
*/
static unsigned int
strLen ( const char * str ) throw ( Exception );
/**
* Copy a C string into another.
*
* @param dest place for the copy. Storage size must be at least
* Util::strLen(src) + 1 long.
* @param src the string to copy.
* @exception Exception
*/
static void
strCpy ( char * dest,
const char * src ) throw ( Exception );
/**
* Concatenate a string to another's end.
*
* @param dest the string to concatenate to.
* Storage size of dest must be at least
* Util::strLen(dest) + Util::strLen(src) + 1 long.
* @param src the string to concatenate.
* @exception Exception
*/
static void
strCat ( char * dest,
const char * src ) throw ( Exception );
/**
* Duplicate a string by allocating space with new[].
* The returned string must be freed with delete[].
*
* @param str the string to duplicate.
* @exception Exception
*/
static char *
strDup ( const char * str ) throw ( Exception );
/**
* Determine whether two string are equal.
*
* @param str1 one of the strings.
* @param str2 the other string.
* @param len check the first most len characters. if 0, check
* the whole string
* @return true if the two strings are equal, false othersize.
* @exception Exception
*/
static bool
strEq ( const char * str1,
const char * str2,
unsigned int len = 0 ) throw ( Exception );
/**
* Convert a string to long.
*
* @param str the string to convert.
* @return the value of str as a long int
* @exception Exception
*/
static long int
strToL ( const char * str) throw ( Exception );
/**
* Convert a string to double.
*
* @param str the string to convert.
* @return the value of str as a double
* @exception Exception
*/
static double
strToD ( const char * str ) throw ( Exception );
/**
* Add current date to a file name, before the file extension (if any)
*
* @param str the string to convert (file name).
* @return the new string with the date appended before
* extension of the file name. the string has to be
* deleted with delete[] after it is not needed
* @exception Exception
*/
static char *
fileAddDate ( const char * str,
const char * format = "[%m-%d-%Y-%H-%M-%S]" )
throw ( Exception );
/**
* Convert a string into base64 encoding.
* base64 is described in RFC 2045, section 6.8
* The returned string must be freed with delete[].
*
* @param str the string to convert.
* @return the supplied string in base64 encoding.
* @exception Exception
*/
static char *
base64Encode ( const char * str ) throw ( Exception );
/**
* Convert an unsigned char buffer holding 8 or 16 bit PCM values
* with channels interleaved to a short int buffer, still
* with channels interleaved.
*
* @param bitsPerSample the number of bits per sample in the input
* @param pcmBuffer the input buffer
* @param lenPcmBuffer the number of samples total in pcmBuffer
* (e.g. if 2 channel input, this is twice the
* number of sound samples)
* @param outBuffer the output buffer, must be big enough
* @param isBigEndian true if the input is big endian, false otherwise
*/
static void
conv ( unsigned int bitsPerSample,
unsigned char * pcmBuffer,
unsigned int lenPcmBuffer,
short int * outBuffer,
bool isBigEndian = true ) throw ( Exception );
/**
* Convert a short buffer holding PCM values with channels interleaved
* to one or more float buffers, one for each channel
*
* @param shortBuffer the input buffer
* @param lenShortBuffer total length of the input buffer
* @param floatBuffers an array of float buffers, each
* (lenShortBuffer / channels) long
* @param channels number of channels to separate the input to
*/
static void
conv ( short int * shortBuffer,
unsigned int lenShortBuffer,
float ** floatBuffers,
unsigned int channels ) throw ( Exception );
/**
* Convert a char buffer holding 8 bit PCM values to a short buffer
*
* @param pcmBuffer buffer holding 8 bit PCM audio values,
* channels are interleaved
* @param lenPcmBuffer length of pcmBuffer
* @param leftBuffer put the left channel here (must be big enough)
* @param rightBuffer put the right channel here (not touched if mono,
* must be big enough)
* @param channels number of channels (1 = mono, 2 = stereo)
*/
static void
conv8 ( unsigned char * pcmBuffer,
unsigned int lenPcmBuffer,
short int * leftBuffer,
short int * rightBuffer,
unsigned int channels ) throw ( Exception );
/**
* Convert a char buffer holding 16 bit PCM values to a short buffer
*
* @param pcmBuffer buffer holding 16 bit PCM audio values,
* channels are interleaved
* @param lenPcmBuffer length of pcmBuffer
* @param leftBuffer put the left channel here (must be big enough)
* @param rightBuffer put the right channel here (not touched if mono,
* must be big enough)
* @param channels number of channels (1 = mono, 2 = stereo)
* @param isBigEndian true if input is big endian, false otherwise
*/
static void
conv16 ( unsigned char * pcmBuffer,
unsigned int lenPcmBuffer,
short int * leftBuffer,
short int * rightBuffer,
unsigned int channels,
bool isBigEndian ) throw ( Exception );
/**
* Make a thread sleep for specified amount of time.
* Only the thread which this is called in will sleep.
* The SIGUSR1 signal will be blocked during the sleep.
*
* @param sec the number of seconds to sleep.
* @param nsec the number of nano-seconds to sleep.
*/
static void
sleep( long sec,
long nsec);
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* UTIL_H */
|