id3lib 3.8.3

include/id3/id3lib_strings.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: id3lib_strings.h,v 1.4 2003/03/02 13:56:21 t1mpy Exp $
00003 
00004 // id3lib: a software library for creating and manipulating id3v1/v2 tags
00005 // Copyright 1999, 2000  Scott Thomas Haug
00006 // Copyright 2002 Thijmen Klok (thijmen@id3lib.org)
00007 
00008 // This library is free software; you can redistribute it and/or modify it
00009 // under the terms of the GNU Library General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or (at your
00011 // option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful, but WITHOUT
00014 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00016 // License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public License
00019 // along with this library; if not, write to the Free Software Foundation,
00020 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021 
00022 // The id3lib authors encourage improvements and optimisations to be sent to
00023 // the id3lib coordinator.  Please see the README file for details on where to
00024 // send such submissions.  See the AUTHORS file for a list of people who have
00025 // contributed to id3lib.  See the ChangeLog file for a list of changes to
00026 // id3lib.  These files are distributed with id3lib at
00027 // http://download.sourceforge.net/id3lib/
00028 
00029 #ifndef _ID3LIB_STRINGS_H_
00030 #define _ID3LIB_STRINGS_H_
00031 
00032 #include <string>
00033 #include "string.h"
00034 
00035 #if (defined(__GNUC__) && (__GNUC__ >= 3) || (defined(_MSC_VER) && _MSC_VER > 1000))
00036 namespace std
00037 {
00038   template<>
00039     struct char_traits<unsigned char>
00040     {
00041       typedef unsigned char char_type;
00042       // Unsigned as wint_t in unsigned.
00043       typedef unsigned long     int_type;
00044       typedef streampos         pos_type;
00045       typedef streamoff         off_type;
00046       typedef mbstate_t         state_type;
00047 
00048       static void
00049       assign(char_type& __c1, const char_type& __c2)
00050       { __c1 = __c2; }
00051 
00052       static bool
00053       eq(const char_type& __c1, const char_type& __c2)
00054       { return __c1 == __c2; }
00055 
00056       static bool
00057       lt(const char_type& __c1, const char_type& __c2)
00058       { return __c1 < __c2; }
00059 
00060       static int
00061       compare(const char_type* __s1, const char_type* __s2, size_t __n)
00062       {
00063         for (size_t __i = 0; __i < __n; ++__i)
00064           if (!eq(__s1[__i], __s2[__i]))
00065             return lt(__s1[__i], __s2[__i]) ? -1 : 1;
00066         return 0;
00067       }
00068 
00069       static size_t
00070       length(const char_type* __s)
00071       {
00072         const char_type* __p = __s;
00073           while (__p)
00074             ++__p;
00075         return (__p - __s);
00076       }
00077 
00078       static const char_type*
00079       find(const char_type* __s, size_t __n, const char_type& __a)
00080       {
00081         for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p)
00082           if (*__p == __a) return __p;
00083         return 0;
00084       }
00085 
00086       static char_type*
00087       move(char_type* __s1, const char_type* __s2, size_t __n)
00088       { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }
00089 
00090       static char_type*
00091       copy(char_type* __s1, const char_type* __s2, size_t __n)
00092       { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }
00093 
00094       static char_type*
00095       assign(char_type* __s, size_t __n, char_type __a)
00096       {
00097         for (char_type* __p = __s; __p < __s + __n; ++__p)
00098           assign(*__p, __a);
00099         return __s;
00100       }
00101 
00102       static char_type
00103       to_char_type(const int_type& __c)
00104       { return char_type(); }
00105 
00106       static int_type
00107       to_int_type(const char_type& __c) { return int_type(); }
00108 
00109       static bool
00110       eq_int_type(const int_type& __c1, const int_type& __c2)
00111       { return __c1 == __c2; }
00112 
00113       static int_type
00114       eof() { return static_cast<int_type>(-1); }
00115 
00116       static int_type
00117       not_eof(const int_type& __c)
00118       { return eq_int_type(__c, eof()) ? int_type(0) : __c; }
00119     };
00120 
00121 #ifndef _GLIBCPP_USE_WCHAR_T
00122 #if (defined(ID3_NEED_WCHAR_TEMPLATE))
00123    template<>
00124      struct char_traits<wchar_t>
00125      {
00126        typedef wchar_t          char_type;
00127        typedef wint_t           int_type;
00128        typedef streamoff        off_type;
00129        typedef streampos        pos_type;
00130        typedef mbstate_t        state_type;
00131        
00132        static void 
00133        assign(char_type& __c1, const char_type& __c2)
00134        { __c1 = __c2; }
00135  
00136        static bool 
00137        eq(const char_type& __c1, const char_type& __c2)
00138        { return __c1 == __c2; }
00139  
00140        static bool 
00141        lt(const char_type& __c1, const char_type& __c2)
00142        { return __c1 < __c2; }
00143  
00144        static int 
00145        compare(const char_type* __s1, const char_type* __s2, size_t __n)
00146        { return wmemcmp(__s1, __s2, __n); }
00147  
00148        static size_t
00149        length(const char_type* __s)
00150        { return wcslen(__s); }
00151  
00152        static const char_type* 
00153        find(const char_type* __s, size_t __n, const char_type& __a)
00154        { return wmemchr(__s, __a, __n); }
00155  
00156        static char_type* 
00157        move(char_type* __s1, const char_type* __s2, int_type __n)
00158        { return wmemmove(__s1, __s2, __n); }
00159  
00160        static char_type* 
00161        copy(char_type* __s1, const char_type* __s2, size_t __n)
00162        { return wmemcpy(__s1, __s2, __n); }
00163  
00164        static char_type* 
00165        assign(char_type* __s, size_t __n, char_type __a)
00166        { return wmemset(__s, __a, __n); }
00167  
00168        static char_type 
00169        to_char_type(const int_type& __c) { return char_type(__c); }
00170  
00171        static int_type 
00172        to_int_type(const char_type& __c) { return int_type(__c); }
00173  
00174        static bool 
00175        eq_int_type(const int_type& __c1, const int_type& __c2)
00176        { return __c1 == __c2; }
00177  
00178        static state_type 
00179        _S_get_state(const pos_type& __pos) { return __pos.state(); }
00180  
00181        static int_type 
00182        eof() { return static_cast<int_type>(WEOF); }
00183  
00184        static int_type 
00185        _S_eos() { return char_type(); }
00186  
00187        static int_type 
00188        not_eof(const int_type& __c)
00189        { return eq_int_type(__c, eof()) ? 0 : __c; }
00190    };
00191 #endif
00192 #endif
00193 } // namespace std
00194 #endif
00195 
00196 namespace dami
00197 {
00198   typedef std::basic_string<char>           String;
00199   typedef std::basic_string<unsigned char> BString;
00200   typedef std::basic_string<wchar_t>       WString;
00201 };
00202 
00203 #endif /* _ID3LIB_STRINGS_H_ */
00204