From fe452e3ac96699d51d47ecdc43c58778b512d72a Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 13 Feb 2013 10:46:39 -0600 Subject: Added SigList class. --- data/siglist_imp.h | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 data/siglist_imp.h (limited to 'data/siglist_imp.h') diff --git a/data/siglist_imp.h b/data/siglist_imp.h new file mode 100644 index 00000000..16ddd9b0 --- /dev/null +++ b/data/siglist_imp.h @@ -0,0 +1,156 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "siglist.h" + +template +void SigList::append(const T &value) +{ + QList::append(value); + onItemAdded(value, length() - 1); +} + +template +void SigList::prepend(const T &value) +{ + QList::prepend(value); + onItemAdded(value, 0); +} + +template +void SigList::append(const QList &other) +{ + int index = length(); + QList::append(other); + onItemsAdded(other, index); +} + +template +void SigList::clear() +{ + QList::clear(); + onInvalidated(); +} + +template +void SigList::erase(QList::iterator pos) +{ + T value = *pos; + int index = indexOf(*pos); + QList::erase(pos); + onItemRemoved(value, index); +} + +template +void SigList::erase(QList::iterator first, QList::iterator last) +{ + QList removedValues; + int firstIndex = indexOf(*first); + + for (QList::iterator iter = first; iter < last; iter++) + { + removedValues << *iter; + QList::erase(iter); + } + + onItemsRemoved(removedValues, firstIndex); +} + +template +void SigList::insert(int i, const T &t) +{ + QList::insert(i, t); + onItemAdded(t, i); +} + +template +void SigList::insert(QList::iterator before, const T &t) +{ + QList::insert(before, t); + onItemAdded(t, indexOf(t)); +} + +template +void SigList::move(int from, int to) +{ + const T &item = at(from); + QList::move(from, to); + onItemMoved(item, from, to); +} + +template +int SigList::removeAll(const T &t) +{ + int retVal = QList::removeAll(t); + onInvalidated(); + return retVal; +} + +template +bool SigList::removeOne(const T &t) +{ + int index = indexOf(t); + if (QList::removeOne(t)) + { + onItemRemoved(t, index); + return true; + } + return false; +} + +template +void SigList::swap(QList &other) +{ + QList::swap(other); + onInvalidated(); +} + +template +void SigList::swap(int i, int j) +{ + const T &item1 = at(i); + const T &item2 = at(j); + QList::swap(i, j); + onItemMoved(item1, i, j); + onItemMoved(item2, j, i); +} + +template +T SigList::takeAt(int i) +{ + T val = QList::takeAt(i); + onItemRemoved(val, i); + return val; +} + +template +T SigList::takeFirst() +{ + return takeAt(0); +} + +template +T SigList::takeLast() +{ + return takeAt(length() - 1); +} + +template +QList &SigList::operator =(const QList &other) +{ + QList::operator =(other); + onInvalidated(); + return *this; +} -- cgit v1.2.3