1
/***************************************************************************
2
copyright : (C) 2002 - 2008 by Scott Wheeler
3
email : wheeler@kde.org
4
***************************************************************************/
6
/***************************************************************************
7
* This library is free software; you can redistribute it and/or modify *
8
* it under the terms of the GNU Lesser General Public License version *
9
* 2.1 as published by the Free Software Foundation. *
11
* This library is distributed in the hope that it will be useful, but *
12
* WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14
* Lesser General Public License for more details. *
16
* You should have received a copy of the GNU Lesser General Public *
17
* License along with this library; if not, write to the Free Software *
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
21
* Alternatively, this file is available under the Mozilla Public *
22
* License Version 1.1. You may obtain a copy of the License at *
23
* http://www.mozilla.org/MPL/ *
24
***************************************************************************/
30
////////////////////////////////////////////////////////////////////////////////
32
////////////////////////////////////////////////////////////////////////////////
34
// The functionality of List<T>::setAutoDelete() is implemented here partial
35
// template specialization. This is implemented in such a way that calling
36
// setAutoDelete() on non-pointer types will simply have no effect.
38
// A base for the generic and specialized private class types. New
39
// non-templatized members should be added here.
41
class ListPrivateBase : public RefCounter
44
ListPrivateBase() : autoDelete(false) {}
48
// A generic implementation
51
template <class TP> class List<T>::ListPrivate : public ListPrivateBase
54
ListPrivate() : ListPrivateBase() {}
55
ListPrivate(const std::list<TP> &l) : ListPrivateBase(), list(l) {}
62
// A partial specialization for all pointer types that implements the
63
// setAutoDelete() functionality.
66
template <class TP> class List<T>::ListPrivate<TP *> : public ListPrivateBase
69
ListPrivate() : ListPrivateBase() {}
70
ListPrivate(const std::list<TP *> &l) : ListPrivateBase(), list(l) {}
76
typename std::list<TP *>::const_iterator it = list.begin();
77
for(; it != list.end(); ++it)
85
////////////////////////////////////////////////////////////////////////////////
87
////////////////////////////////////////////////////////////////////////////////
92
d = new ListPrivate<T>;
96
List<T>::List(const List<T> &l) : d(l.d)
109
typename List<T>::Iterator List<T>::begin()
112
return d->list.begin();
116
typename List<T>::ConstIterator List<T>::begin() const
118
return d->list.begin();
122
typename List<T>::Iterator List<T>::end()
125
return d->list.end();
129
typename List<T>::ConstIterator List<T>::end() const
131
return d->list.end();
135
typename List<T>::Iterator List<T>::insert(Iterator it, const T &item)
138
return d->list.insert(it, item);
142
List<T> &List<T>::sortedInsert(const T &value, bool unique)
145
Iterator it = begin();
146
while(it != end() && *it < value)
148
if(unique && it != end() && *it == value)
155
List<T> &List<T>::append(const T &item)
158
d->list.push_back(item);
163
List<T> &List<T>::append(const List<T> &l)
166
d->list.insert(d->list.end(), l.begin(), l.end());
171
List<T> &List<T>::prepend(const T &item)
174
d->list.push_front(item);
179
List<T> &List<T>::prepend(const List<T> &l)
182
d->list.insert(d->list.begin(), l.begin(), l.end());
187
List<T> &List<T>::clear()
195
TagLib::uint List<T>::size() const
197
return d->list.size();
201
bool List<T>::isEmpty() const
203
return d->list.empty();
207
typename List<T>::Iterator List<T>::find(const T &value)
209
return std::find(d->list.begin(), d->list.end(), value);
213
typename List<T>::ConstIterator List<T>::find(const T &value) const
215
return std::find(d->list.begin(), d->list.end(), value);
219
bool List<T>::contains(const T &value) const
221
return std::find(d->list.begin(), d->list.end(), value) != d->list.end();
225
typename List<T>::Iterator List<T>::erase(Iterator it)
227
return d->list.erase(it);
231
const T &List<T>::front() const
233
return d->list.front();
240
return d->list.front();
244
const T &List<T>::back() const
246
return d->list.back();
250
void List<T>::setAutoDelete(bool autoDelete)
252
d->autoDelete = autoDelete;
259
return d->list.back();
263
T &List<T>::operator[](uint i)
265
Iterator it = d->list.begin();
267
for(uint j = 0; j < i; j++)
274
const T &List<T>::operator[](uint i) const
276
ConstIterator it = d->list.begin();
278
for(uint j = 0; j < i; j++)
285
List<T> &List<T>::operator=(const List<T> &l)
298
bool List<T>::operator==(const List<T> &l) const
300
return d->list == l.d->list;
303
////////////////////////////////////////////////////////////////////////////////
305
////////////////////////////////////////////////////////////////////////////////
308
void List<T>::detach()
312
d = new ListPrivate<T>(d->list);
316
} // namespace TagLib