X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftaglib%2Ftoolkit%2Ftmap.tcc;fp=src%2Ftaglib%2Ftoolkit%2Ftmap.tcc;h=6e689d36ab7cfb19a7e9e59c1cab381b1098c2c1;hb=68d60ad21e61d1e3255673985ae19606ceb0c59d;hp=0000000000000000000000000000000000000000;hpb=dca4bf6a28a8b904d45ff26376e667b05063a400;p=someplayer diff --git a/src/taglib/toolkit/tmap.tcc b/src/taglib/toolkit/tmap.tcc new file mode 100644 index 0000000..6e689d3 --- /dev/null +++ b/src/taglib/toolkit/tmap.tcc @@ -0,0 +1,196 @@ +/*************************************************************************** + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * + * 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 RefCounter +{ +public: + MapPrivate() : RefCounter() {} +#ifdef WANT_CLASS_INSTANTIATION_OF_MAP + MapPrivate(const std::map& m) : RefCounter(), map(m) {} + std::map map; +#else + MapPrivate(const std::map& m) : RefCounter(), map(m) {} + std::map map; +#endif +}; + +template +Map::Map() +{ + d = new MapPrivate; +} + +template +Map::Map(const Map &m) : d(m.d) +{ + d->ref(); +} + +template +Map::~Map() +{ + if(d->deref()) + delete(d); +} + +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::Iterator Map::end() +{ + detach(); + return d->map.end(); +} + +template +typename Map::ConstIterator Map::end() const +{ + return d->map.end(); +} + +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) +{ + detach(); + d->map.erase(it); + return *this; +} + +template +Map &Map::erase(const Key &key) +{ + detach(); + Iterator it = d->map.find(key); + if(it != d->map.end()) + d->map.erase(it); + return *this; +} + +template +TagLib::uint Map::size() const +{ + return d->map.size(); +} + +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 &m) +{ + if(&m == this) + return *this; + + if(d->deref()) + delete(d); + d = m.d; + d->ref(); + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +// protected members +//////////////////////////////////////////////////////////////////////////////// + +template +void Map::detach() +{ + if(d->count() > 1) { + d->deref(); + d = new MapPrivate(d->map); + } +} + +} // namespace TagLib