taglib.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     copyright            : (C) 2002 - 2008 by Scott Wheeler
00003     email                : wheeler@kde.org
00004  ***************************************************************************/
00005 
00006 /***************************************************************************
00007  *   This library is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU Lesser General Public License version   *
00009  *   2.1 as published by the Free Software Foundation.                     *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful, but   *
00012  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the Free Software   *
00018  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA         *
00019  *   02110-1301  USA                                                       *
00020  *                                                                         *
00021  *   Alternatively, this file is available under the Mozilla Public        *
00022  *   License Version 1.1.  You may obtain a copy of the License at         *
00023  *   http://www.mozilla.org/MPL/                                           *
00024  ***************************************************************************/
00025 
00026 #ifndef TAGLIB_H
00027 #define TAGLIB_H
00028 
00029 #define TAGLIB_MAJOR_VERSION 1
00030 #define TAGLIB_MINOR_VERSION 7
00031 #define TAGLIB_PATCH_VERSION 0
00032 
00033 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 1))
00034 #define TAGLIB_IGNORE_MISSING_DESTRUCTOR _Pragma("GCC diagnostic ignored \"-Wnon-virtual-dtor\"")
00035 #else
00036 #define TAGLIB_IGNORE_MISSING_DESTRUCTOR
00037 #endif
00038 
00039 #if (defined(_MSC_VER) && _MSC_VER >= 1600)
00040 #define TAGLIB_CONSTRUCT_BITSET(x) static_cast<unsigned long long>(x)
00041 #else
00042 #define TAGLIB_CONSTRUCT_BITSET(x) static_cast<unsigned long>(x)
00043 #endif
00044 
00045 #include <string>
00046 
00047 #ifdef __APPLE__
00048 #  include <libkern/OSAtomic.h>
00049 #  define TAGLIB_ATOMIC_MAC
00050 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
00051 #  define NOMINMAX
00052 #  include <windows.h>
00053 #  define TAGLIB_ATOMIC_WIN
00054 #elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 401)    \
00055       && (defined(__i386__) || defined(__i486__) || defined(__i586__) || \
00056           defined(__i686__) || defined(__x86_64) || defined(__ia64)) \
00057       && !defined(__INTEL_COMPILER)
00058 #  define TAGLIB_ATOMIC_GCC
00059 #elif defined(__ia64) && defined(__INTEL_COMPILER)
00060 #  include <ia64intrin.h>
00061 #  define TAGLIB_ATOMIC_GCC
00062 #endif
00063 
00065 
00074 namespace TagLib {
00075 
00076   class String;
00077 
00078   typedef wchar_t wchar;
00079   typedef unsigned char  uchar;
00080   typedef unsigned short ushort;
00081   typedef unsigned int   uint;
00082   typedef unsigned long  ulong;
00083 
00088   typedef std::basic_string<wchar> wstring;
00089 
00090 #ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class.
00091 
00098   class RefCounter
00099   {
00100   public:
00101     RefCounter() : refCount(1) {}
00102 
00103 #ifdef TAGLIB_ATOMIC_MAC
00104     void ref() { OSAtomicIncrement32Barrier(const_cast<int32_t*>(&refCount)); }
00105     bool deref() { return ! OSAtomicDecrement32Barrier(const_cast<int32_t*>(&refCount)); }
00106     int32_t count() { return refCount; }
00107   private:
00108     volatile int32_t refCount;
00109 #elif defined(TAGLIB_ATOMIC_WIN)
00110     void ref() { InterlockedIncrement(&refCount); }
00111     bool deref() { return ! InterlockedDecrement(&refCount); }
00112     long count() { return refCount; }
00113   private:
00114     volatile long refCount;
00115 #elif defined(TAGLIB_ATOMIC_GCC)
00116     void ref() { __sync_add_and_fetch(&refCount, 1); }
00117     bool deref() { return ! __sync_sub_and_fetch(&refCount, 1); }
00118     int count() { return refCount; }
00119   private:
00120     volatile int refCount;
00121 #else
00122     void ref() { refCount++; }
00123     bool deref() { return ! --refCount; }
00124     int count() { return refCount; }
00125   private:
00126     uint refCount;
00127 #endif
00128 
00129   };
00130 
00131 #endif // DO_NOT_DOCUMENT
00132 
00133 }
00134 
00226 #endif