id3lib 3.8.3

include/id3/utils.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: utils.h,v 1.22 2002/07/02 22:11:03 t1mpy Exp $
00003 
00004 // id3lib: a C++ library for creating and manipulating id3v1/v2 tags
00005 // Copyright 1999, 2000  Scott Thomas Haug
00006 
00007 // This library is free software; you can redistribute it and/or modify it
00008 // under the terms of the GNU Library General Public License as published by
00009 // the Free Software Foundation; either version 2 of the License, or (at your
00010 // option) any later version.
00011 //
00012 // This library is distributed in the hope that it will be useful, but WITHOUT
00013 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00015 // License for more details.
00016 //
00017 // You should have received a copy of the GNU Library General Public License
00018 // along with this library; if not, write to the Free Software Foundation,
00019 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020 
00021 // The id3lib authors encourage improvements and optimisations to be sent to
00022 // the id3lib coordinator.  Please see the README file for details on where to
00023 // send such submissions.  See the AUTHORS file for a list of people who have
00024 // contributed to id3lib.  See the ChangeLog file for a list of changes to
00025 // id3lib.  These files are distributed with id3lib at
00026 // http://download.sourceforge.net/id3lib/
00027 
00028 #ifndef _ID3LIB_UTILS_H_
00029 #define _ID3LIB_UTILS_H_
00030 
00031 #if defined HAVE_CONFIG_H
00032 #include <config.h>
00033 #endif
00034 
00035 #include "id3/id3lib_streams.h"
00036 #include "id3/globals.h" //has <stdlib.h> "id3/sized_types.h"
00037 #include "id3/id3lib_strings.h"
00038 
00039 namespace dami
00040 {
00041 #ifdef  MAXPATHLEN
00042 #  define ID3_PATH_LENGTH   (MAXPATHLEN + 1)
00043 #elif   defined (PATH_MAX)
00044 #  define ID3_PATH_LENGTH   (PATH_MAX + 1)
00045 #else   /* !MAXPATHLEN */
00046 #  define ID3_PATH_LENGTH   (2048 + 1)
00047 #endif  /* !MAXPATHLEN && !PATH_MAX */
00048 
00049 #ifndef min
00050   template<typename T>
00051   const T& min(const T& a, const T& b)
00052   {
00053     return (a < b) ? a : b;
00054   }
00055 #endif
00056 
00057 #ifndef max
00058   template<typename T>
00059   const T& max(const T& a, const T& b)
00060   {
00061     return (b < a) ? a : b;
00062   }
00063 #endif
00064 
00065 #ifndef mid
00066   template<typename T>
00067   const T& mid(const T& lo, const T& mid, const T& hi)
00068   {
00069     return max(lo, min(mid, hi));
00070   }
00071 #endif
00072 
00073 #ifndef abs
00074   template<typename T>
00075   T abs(const T& a)
00076   {
00077     return (a < T(0)) ? -a : a;
00078   }
00079 #endif
00080 
00081   size_t ID3_C_EXPORT renderNumber(uchar *buffer, uint32 val, size_t size = sizeof(uint32));
00082   String ID3_C_EXPORT renderNumber(uint32 val, size_t size = sizeof(uint32));
00083 
00084   String ID3_C_EXPORT toString(uint32 val);
00085   WString ID3_C_EXPORT toWString(const unicode_t[], size_t);
00086   
00087   size_t ID3_C_EXPORT ucslen(const unicode_t *unicode);
00088   String ID3_C_EXPORT convert(String data, ID3_TextEnc, ID3_TextEnc);
00089 
00090   // file utils
00091   size_t ID3_C_EXPORT getFileSize(fstream&);
00092   size_t ID3_C_EXPORT getFileSize(ifstream&);
00093   size_t ID3_C_EXPORT getFileSize(ofstream&);
00094   ID3_Err ID3_C_EXPORT createFile(String, fstream&);
00095   ID3_Err ID3_C_EXPORT openWritableFile(String, fstream&);
00096   ID3_Err ID3_C_EXPORT openWritableFile(String, ofstream&);
00097   ID3_Err ID3_C_EXPORT openReadableFile(String, fstream&);
00098   ID3_Err ID3_C_EXPORT openReadableFile(String, ifstream&);
00099 
00100 };
00101   
00102 #endif /* _ID3LIB_UTILS_H_ */
00103