/*************************************************************************** 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/ * ***************************************************************************/ namespace TagLib { //////////////////////////////////////////////////////////////////////////////// // public members //////////////////////////////////////////////////////////////////////////////// template template class Map::MapPrivate { public: MapPrivate() = default; #ifdef WANT_CLASS_INSTANTIATION_OF_MAP MapPrivate(const std::map& m) : map(m) {} MapPrivate(std::initializer_list> init) : map(init) {} std::map map; #else MapPrivate(const std::map& m) : map(m) {} MapPrivate(std::initializer_list> init) : map(init) {} std::map map; #endif }; template Map::Map() : d(std::make_shared>()) { } template Map::Map(const Map &) = default; template Map::Map(std::initializer_list> init) : d(std::make_shared>(init)) { } template Map::~Map() = default; template typename Map::Iterator Map::begin() { detach(); return d->map.begin(); } template typename Map::ConstIterator Map::begin() const { return d->map.begin(); } template typename Map::ConstIterator Map::cbegin() const { return d->map.cbegin(); } template typename Map::Iterator Map::end() { detach(); return d->map.end(); } template typename Map::ConstIterator Map::end() const { return d->map.end(); } template typename Map::ConstIterator Map::cend() const { return d->map.cend(); } template Map &Map::insert(const Key &key, const T &value) { detach(); d->map[key] = value; return *this; } template Map &Map::clear() { detach(); d->map.clear(); return *this; } template bool Map::isEmpty() const { return d->map.empty(); } template typename Map::Iterator Map::find(const Key &key) { detach(); return d->map.find(key); } template typename Map::ConstIterator Map::find(const Key &key) const { return d->map.find(key); } template bool Map::contains(const Key &key) const { return d->map.find(key) != d->map.end(); } template Map &Map::erase(Iterator it) { d->map.erase(it); return *this; } template Map &Map::erase(const Key &key) { detach(); d->map.erase(key); return *this; } template unsigned int Map::size() const { return static_cast(d->map.size()); } template T Map::value(const Key &key, const T &defaultValue) const { auto it = d->map.find(key); return it != d->map.end() ? it->second : defaultValue; } template const T &Map::operator[](const Key &key) const { return d->map[key]; } template T &Map::operator[](const Key &key) { detach(); return d->map[key]; } template Map &Map::operator=(const Map &) = default; template Map &Map::operator=(std::initializer_list> init) { Map(init).swap(*this); return *this; } template void Map::swap(Map &m) noexcept { using std::swap; swap(d, m.d); } template bool Map::operator==(const Map &m) const { return d->map == m.d->map; } template bool Map::operator!=(const Map &m) const { return d->map != m.d->map; } //////////////////////////////////////////////////////////////////////////////// // protected members //////////////////////////////////////////////////////////////////////////////// template void Map::detach() { if(d.use_count() > 1) { d = std::make_shared>(d->map); } } } // namespace TagLib