Clementine-audio-player-Mac.../3rdparty/taglib/toolkit/tmap.tcc

200 lines
5.0 KiB
Plaintext
Raw Permalink Normal View History

2012-10-28 02:12:18 +02:00
/***************************************************************************
copyright : (C) 2002 - 2008 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* 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 "trefcounter.h"
2012-10-28 02:12:18 +02:00
namespace TagLib {
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
2013-12-17 19:38:05 +01:00
// BIC change to RefCounter
2012-10-28 02:12:18 +02:00
template <class Key, class T>
template <class KeyP, class TP>
2013-12-17 19:38:05 +01:00
class Map<Key, T>::MapPrivate : public RefCounterOld
2012-10-28 02:12:18 +02:00
{
public:
2013-12-17 19:38:05 +01:00
MapPrivate() : RefCounterOld() {}
2012-10-28 02:12:18 +02:00
#ifdef WANT_CLASS_INSTANTIATION_OF_MAP
2013-12-17 19:38:05 +01:00
MapPrivate(const std::map<class KeyP, class TP>& m) : RefCounterOld(), map(m) {}
2012-10-28 02:12:18 +02:00
std::map<class KeyP, class TP> map;
#else
2013-12-17 19:38:05 +01:00
MapPrivate(const std::map<KeyP, TP>& m) : RefCounterOld(), map(m) {}
2012-10-28 02:12:18 +02:00
std::map<KeyP, TP> map;
#endif
};
template <class Key, class T>
2018-06-06 22:47:08 +02:00
Map<Key, T>::Map() :
d(new MapPrivate<Key, T>())
2012-10-28 02:12:18 +02:00
{
}
template <class Key, class T>
Map<Key, T>::Map(const Map<Key, T> &m) : d(m.d)
{
d->ref();
}
template <class Key, class T>
Map<Key, T>::~Map()
{
if(d->deref())
delete(d);
}
template <class Key, class T>
typename Map<Key, T>::Iterator Map<Key, T>::begin()
{
detach();
return d->map.begin();
}
template <class Key, class T>
typename Map<Key, T>::ConstIterator Map<Key, T>::begin() const
{
return d->map.begin();
}
template <class Key, class T>
typename Map<Key, T>::Iterator Map<Key, T>::end()
{
detach();
return d->map.end();
}
template <class Key, class T>
typename Map<Key, T>::ConstIterator Map<Key, T>::end() const
{
return d->map.end();
}
template <class Key, class T>
Map<Key, T> &Map<Key, T>::insert(const Key &key, const T &value)
{
detach();
d->map[key] = value;
return *this;
}
template <class Key, class T>
Map<Key, T> &Map<Key, T>::clear()
{
detach();
d->map.clear();
return *this;
}
template <class Key, class T>
bool Map<Key, T>::isEmpty() const
{
return d->map.empty();
}
template <class Key, class T>
typename Map<Key, T>::Iterator Map<Key, T>::find(const Key &key)
{
detach();
return d->map.find(key);
}
template <class Key, class T>
typename Map<Key,T>::ConstIterator Map<Key, T>::find(const Key &key) const
{
return d->map.find(key);
}
template <class Key, class T>
bool Map<Key, T>::contains(const Key &key) const
{
return d->map.find(key) != d->map.end();
}
template <class Key, class T>
Map<Key, T> &Map<Key,T>::erase(Iterator it)
{
detach();
d->map.erase(it);
return *this;
}
template <class Key, class T>
Map<Key, T> &Map<Key,T>::erase(const Key &key)
{
detach();
2015-11-24 19:36:24 +01:00
d->map.erase(key);
2012-10-28 02:12:18 +02:00
return *this;
}
template <class Key, class T>
2016-07-19 16:58:52 +02:00
unsigned int Map<Key, T>::size() const
2012-10-28 02:12:18 +02:00
{
2018-06-06 22:47:08 +02:00
return static_cast<unsigned int>(d->map.size());
2012-10-28 02:12:18 +02:00
}
template <class Key, class T>
const T &Map<Key, T>::operator[](const Key &key) const
{
return d->map[key];
}
template <class Key, class T>
T &Map<Key, T>::operator[](const Key &key)
{
detach();
return d->map[key];
}
template <class Key, class T>
Map<Key, T> &Map<Key, T>::operator=(const Map<Key, T> &m)
{
2018-06-06 22:47:08 +02:00
Map<Key, T>(m).swap(*this);
2012-10-28 02:12:18 +02:00
return *this;
}
2018-06-06 22:47:08 +02:00
template <class Key, class T>
void Map<Key, T>::swap(Map<Key, T> &m)
{
using std::swap;
swap(d, m.d);
}
2012-10-28 02:12:18 +02:00
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////
template <class Key, class T>
void Map<Key, T>::detach()
{
if(d->count() > 1) {
d->deref();
d = new MapPrivate<Key, T>(d->map);
}
}
} // namespace TagLib