Removed RefCounter implementation from a public header

This commit is contained in:
Tsuda Kageyu 2013-05-03 13:53:32 +09:00
parent 23bd3784a1
commit 198530547d
16 changed files with 183 additions and 72 deletions

View File

@ -16,6 +16,14 @@
/* Defined if your compiler supports codecvt */
#cmakedefine HAVE_STD_CODECVT 1
/* Defined if your compiler supports some atomic operations */
#cmakedefine HAVE_STD_ATOMIC 1
#cmakedefine HAVE_BOOST_ATOMIC 1
#cmakedefine HAVE_GCC_ATOMIC 1
#cmakedefine HAVE_MAC_ATOMIC 1
#cmakedefine HAVE_WIN_ATOMIC 1
#cmakedefine HAVE_IA64_ATOMIC 1
/* Defined if you have libz */
#cmakedefine HAVE_ZLIB 1

View File

@ -50,6 +50,7 @@ set(tag_HDRS
toolkit/tmap.h
toolkit/tmap.tcc
toolkit/tpropertymap.h
toolkit/trefcounter.h
mpeg/mpegfile.h
mpeg/mpegproperties.h
mpeg/mpegheader.h
@ -289,6 +290,7 @@ set(toolkit_SRCS
toolkit/tfilestream.cpp
toolkit/tdebug.cpp
toolkit/tpropertymap.cpp
toolkit/trefcounter.cpp
toolkit/unicode.cpp
)

View File

@ -25,6 +25,7 @@
#include <taglib.h>
#include <tdebug.h>
#include "trefcounter.h"
#include "asfattribute.h"
#include "asffile.h"

View File

@ -25,6 +25,7 @@
#include <taglib.h>
#include <tdebug.h>
#include "trefcounter.h"
#include "asfattribute.h"
#include "asffile.h"
#include "asfpicture.h"

View File

@ -36,6 +36,7 @@
#include <tfile.h>
#include <tstring.h>
#include <tdebug.h>
#include "trefcounter.h"
#include "fileref.h"
#include "asffile.h"

View File

@ -25,6 +25,7 @@
#include <taglib.h>
#include <tdebug.h>
#include "trefcounter.h"
#include "mp4coverart.h"
using namespace TagLib;

View File

@ -25,6 +25,7 @@
#include <taglib.h>
#include <tdebug.h>
#include "trefcounter.h"
#include "mp4item.h"
using namespace TagLib;

View File

@ -28,6 +28,7 @@
#include <tbytevector.h>
#include <tstring.h>
#include <tdebug.h>
#include "trefcounter.h"
#include "mpegheader.h"

View File

@ -3,14 +3,6 @@
/* Defined if your compiler supports std::wstring */
#cmakedefine TAGLIB_HAVE_STD_WSTRING 1
/* Defined if your compiler supports some atomic operations */
#cmakedefine TAGLIB_HAVE_STD_ATOMIC 1
#cmakedefine TAGLIB_HAVE_BOOST_ATOMIC 1
#cmakedefine TAGLIB_HAVE_GCC_ATOMIC 1
#cmakedefine TAGLIB_HAVE_MAC_ATOMIC 1
#cmakedefine TAGLIB_HAVE_WIN_ATOMIC 1
#cmakedefine TAGLIB_HAVE_IA64_ATOMIC 1
#define TAGLIB_WITH_ASF 1
#define TAGLIB_WITH_MP4 1

View File

@ -46,46 +46,6 @@
#include <string>
// Atomic increment/decrement operations
#if defined(TAGLIB_HAVE_STD_ATOMIC)
# include <atomic>
# define TAGLIB_ATOMIC_INT std::atomic<unsigned int>
# define TAGLIB_ATOMIC_INC(x) x.fetch_add(1)
# define TAGLIB_ATOMIC_DEC(x) (x.fetch_sub(1) - 1)
#elif defined(TAGLIB_HAVE_BOOST_ATOMIC)
# include <boost/atomic.hpp>
# define TAGLIB_ATOMIC_INT boost::atomic<unsigned int>
# define TAGLIB_ATOMIC_INC(x) x.fetch_add(1)
# define TAGLIB_ATOMIC_DEC(x) (x.fetch_sub(1) - 1)
#elif defined(TAGLIB_HAVE_GCC_ATOMIC)
# define TAGLIB_ATOMIC_INT int
# define TAGLIB_ATOMIC_INC(x) __sync_add_and_fetch(&x, 1)
# define TAGLIB_ATOMIC_DEC(x) __sync_sub_and_fetch(&x, 1)
#elif defined(TAGLIB_HAVE_WIN_ATOMIC)
# if !defined(NOMINMAX)
# define NOMINMAX
# endif
# include <windows.h>
# define TAGLIB_ATOMIC_INT long
# define TAGLIB_ATOMIC_INC(x) InterlockedIncrement(&x)
# define TAGLIB_ATOMIC_DEC(x) InterlockedDecrement(&x)
#elif defined(TAGLIB_HAVE_MAC_ATOMIC)
# include <libkern/OSAtomic.h>
# define TAGLIB_ATOMIC_INT int32_t
# define TAGLIB_ATOMIC_INC(x) OSAtomicIncrement32Barrier(&x)
# define TAGLIB_ATOMIC_DEC(x) OSAtomicDecrement32Barrier(&x)
#elif defined(TAGLIB_HAVE_IA64_ATOMIC)
# include <ia64intrin.h>
# define TAGLIB_ATOMIC_INT int
# define TAGLIB_ATOMIC_INC(x) __sync_add_and_fetch(&x, 1)
# define TAGLIB_ATOMIC_DEC(x) __sync_sub_and_fetch(&x, 1)
#else
# define TAGLIB_ATOMIC_INT int
# define TAGLIB_ATOMIC_INC(x) (++x)
# define TAGLIB_ATOMIC_DEC(x) (--x)
#endif
//! A namespace for all TagLib related classes and functions
/*!
@ -118,30 +78,6 @@ namespace TagLib {
#else
typedef std::basic_string<wchar> wstring;
#endif
#ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class.
/*!
* \internal
* This is just used as a base class for shared classes in TagLib.
*
* \warning This <b>is not</b> part of the TagLib public API!
*/
class RefCounter
{
public:
RefCounter() : refCount(1) {}
void ref() { TAGLIB_ATOMIC_INC(refCount); }
bool deref() { return (TAGLIB_ATOMIC_DEC(refCount) == 0); }
int count() { return refCount; }
private:
volatile TAGLIB_ATOMIC_INT refCount;
};
#endif // DO_NOT_DOCUMENT
}
/*!

View File

@ -41,6 +41,7 @@
#include <tstring.h>
#include <tdebug.h>
#include "trefcounter.h"
#include "tbytevector.h"

View File

@ -24,6 +24,7 @@
***************************************************************************/
#include <algorithm>
#include "trefcounter.h"
namespace TagLib {

View File

@ -23,6 +23,8 @@
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include "trefcounter.h"
namespace TagLib {
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,105 @@
/***************************************************************************
copyright : (C) 2013 by Tsuda Kageyu
email : tsuda.kageyu@gmail.com
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include "config.h"
#include "trefcounter.h"
#if defined(HAVE_STD_ATOMIC)
# include <atomic>
# define ATOMIC_INT std::atomic<unsigned int>
# define ATOMIC_INC(x) x.fetch_add(1)
# define ATOMIC_DEC(x) (x.fetch_sub(1) - 1)
#elif defined(HAVE_BOOST_ATOMIC)
# include <boost/atomic.hpp>
# define ATOMIC_INT boost::atomic<unsigned int>
# define ATOMIC_INC(x) x.fetch_add(1)
# define ATOMIC_DEC(x) (x.fetch_sub(1) - 1)
#elif defined(HAVE_GCC_ATOMIC)
# define ATOMIC_INT int
# define ATOMIC_INC(x) __sync_add_and_fetch(&x, 1)
# define ATOMIC_DEC(x) __sync_sub_and_fetch(&x, 1)
#elif defined(HAVE_WIN_ATOMIC)
# if !defined(NOMINMAX)
# define NOMINMAX
# endif
# include <windows.h>
# define ATOMIC_INT long
# define ATOMIC_INC(x) InterlockedIncrement(&x)
# define ATOMIC_DEC(x) InterlockedDecrement(&x)
#elif defined(HAVE_MAC_ATOMIC)
# include <libkern/OSAtomic.h>
# define ATOMIC_INT int32_t
# define ATOMIC_INC(x) OSAtomicIncrement32Barrier(&x)
# define ATOMIC_DEC(x) OSAtomicDecrement32Barrier(&x)
#elif defined(HAVE_IA64_ATOMIC)
# include <ia64intrin.h>
# define ATOMIC_INT int
# define ATOMIC_INC(x) __sync_add_and_fetch(&x, 1)
# define ATOMIC_DEC(x) __sync_sub_and_fetch(&x, 1)
#else
# define ATOMIC_INT int
# define ATOMIC_INC(x) (++x)
# define ATOMIC_DEC(x) (--x)
#endif
namespace TagLib
{
class RefCounter::RefCounterPrivate
{
public:
RefCounterPrivate() : refCount(1) {}
void ref() { ATOMIC_INC(refCount); }
bool deref() { return (ATOMIC_DEC(refCount) == 0); }
int count() const { return refCount; }
volatile ATOMIC_INT refCount;
};
RefCounter::RefCounter()
: d(new RefCounterPrivate())
{
}
RefCounter::~RefCounter()
{
delete d;
}
void RefCounter::ref()
{
d->ref();
}
bool RefCounter::deref()
{
return d->deref();
}
int RefCounter::count() const
{
return d->count();
}
}

View File

@ -0,0 +1,57 @@
/***************************************************************************
copyright : (C) 2013 by Tsuda Kageyu
email : tsuda.kageyu@gmail.com
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#ifndef TAGLIB_REFCOUNTER_H
#define TAGLIB_REFCOUNTER_H
#include "taglib.h"
#ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class.
/*!
* \internal
* This is just used as a base class for shared classes in TagLib.
*
* \warning This <b>is not</b> part of the TagLib public API!
*/
namespace TagLib
{
class RefCounter
{
public:
RefCounter();
virtual ~RefCounter();
void ref();
bool deref();
int count() const;
private:
class RefCounterPrivate;
RefCounterPrivate *d;
};
}
#endif // DO_NOT_DOCUMENT
#endif

View File

@ -30,6 +30,7 @@
#include "tstring.h"
#include "tdebug.h"
#include "tstringlist.h"
#include "trefcounter.h"
#include <iostream>
#include <string.h>