id3lib  3.8.3
utils.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: utils.h,v 1.22 2002/07/02 22:11:03 t1mpy Exp $
3 
4 // id3lib: a C++ library for creating and manipulating id3v1/v2 tags
5 // Copyright 1999, 2000 Scott Thomas Haug
6 
7 // This library is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU Library General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or (at your
10 // option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public License
18 // along with this library; if not, write to the Free Software Foundation,
19 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 
21 // The id3lib authors encourage improvements and optimisations to be sent to
22 // the id3lib coordinator. Please see the README file for details on where to
23 // send such submissions. See the AUTHORS file for a list of people who have
24 // contributed to id3lib. See the ChangeLog file for a list of changes to
25 // id3lib. These files are distributed with id3lib at
26 // http://download.sourceforge.net/id3lib/
27 
28 #ifndef _ID3LIB_UTILS_H_
29 #define _ID3LIB_UTILS_H_
30 
31 #if defined HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34 
35 #include "id3/id3lib_streams.h"
36 #include "id3/globals.h" //has <stdlib.h> "id3/sized_types.h"
37 #include "id3/id3lib_strings.h"
38 
39 namespace dami
40 {
41 #ifdef MAXPATHLEN
42 # define ID3_PATH_LENGTH (MAXPATHLEN + 1)
43 #elif defined (PATH_MAX)
44 # define ID3_PATH_LENGTH (PATH_MAX + 1)
45 #else /* !MAXPATHLEN */
46 # define ID3_PATH_LENGTH (2048 + 1)
47 #endif /* !MAXPATHLEN && !PATH_MAX */
48 
49 #ifndef min
50  template<typename T>
51  const T& min(const T& a, const T& b)
52  {
53  return (a < b) ? a : b;
54  }
55 #endif
56 
57 #ifndef max
58  template<typename T>
59  const T& max(const T& a, const T& b)
60  {
61  return (b < a) ? a : b;
62  }
63 #endif
64 
65 #ifndef mid
66  template<typename T>
67  const T& mid(const T& lo, const T& mid, const T& hi)
68  {
69  return max(lo, min(mid, hi));
70  }
71 #endif
72 
73 #ifndef abs
74  template<typename T>
75  T abs(const T& a)
76  {
77  return (a < T(0)) ? -a : a;
78  }
79 #endif
80 
81  size_t ID3_C_EXPORT renderNumber(uchar *buffer, uint32 val, size_t size = sizeof(uint32));
82  String ID3_C_EXPORT renderNumber(uint32 val, size_t size = sizeof(uint32));
83 
84  String ID3_C_EXPORT toString(uint32 val);
85  WString ID3_C_EXPORT toWString(const unicode_t[], size_t);
86 
87  size_t ID3_C_EXPORT ucslen(const unicode_t *unicode);
88  String ID3_C_EXPORT convert(String data, ID3_TextEnc, ID3_TextEnc);
89 
90  // file utils
91  size_t ID3_C_EXPORT getFileSize(fstream&);
92  size_t ID3_C_EXPORT getFileSize(ifstream&);
93  size_t ID3_C_EXPORT getFileSize(ofstream&);
94  ID3_Err ID3_C_EXPORT createFile(String, fstream&);
95  ID3_Err ID3_C_EXPORT openWritableFile(String, fstream&);
96  ID3_Err ID3_C_EXPORT openWritableFile(String, ofstream&);
97  ID3_Err ID3_C_EXPORT openReadableFile(String, fstream&);
98  ID3_Err ID3_C_EXPORT openReadableFile(String, ifstream&);
99 
100 };
101 
102 #endif /* _ID3LIB_UTILS_H_ */
103 
ID3_Err
Predefined id3lib error types.
Definition: globals.h:364
ID3_TextEnc
Enumeration of the types of text encodings: ascii or unicode.
Definition: globals.h:138
#define ID3_C_EXPORT
This file defines common macros, types, constants, and enums used throughout id3lib.
Definition: globals.h:78
unsigned char uchar
Definition: globals.h:114
uint16 unicode_t
Definition: globals.h:117
Definition: tag_impl.h:42
size_t ID3_C_EXPORT getFileSize(fstream &)
Definition: utils.cpp:256
const T & min(const T &a, const T &b)
Definition: utils.h:51
String ID3_C_EXPORT toString(uint32 val)
Definition: utils.cpp:365
String ID3_C_EXPORT convert(String data, ID3_TextEnc, ID3_TextEnc)
Definition: utils.cpp:185
T abs(const T &a)
Definition: utils.h:75
const T & mid(const T &lo, const T &mid, const T &hi)
Definition: utils.h:67
ID3_Err ID3_C_EXPORT openWritableFile(String, fstream &)
Definition: utils.cpp:295
const T & max(const T &a, const T &b)
Definition: utils.h:59
size_t ID3_C_EXPORT renderNumber(uchar *buffer, uint32 val, size_t size=sizeof(uint32))
Definition: utils.cpp:92
ID3_Err ID3_C_EXPORT createFile(String, fstream &)
Definition: utils.cpp:240
WString ID3_C_EXPORT toWString(const unicode_t[], size_t)
Definition: utils.cpp:383
size_t ID3_C_EXPORT ucslen(const unicode_t *unicode)
Definition: utils.cpp:216
ID3_Err ID3_C_EXPORT openReadableFile(String, fstream &)
Definition: utils.cpp:335