Add AbstractDeclarationNavigationContext, and move the html-method from
[kdevelopdvcssupport.git] / language / duchain / arrayhelpers.h
blob4eff0bc0b9122e7ee3495097736c1add8718d5b6
1 /*
2 Copyright 2008 David Nolden <david.nolden.kdevelop@art-master.de>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #ifndef ARRAYHELPERS_H
20 #define ARRAYHELPERS_H
22 #include <QtCore/QVector>
23 #include <QtCore/QList>
25 //Foreach macro that also works with KDevVarLengthArray
26 #define FOREACH_ARRAY(item, container) for(int a = 0, mustDo = 1; a < container.size(); ++a) if((mustDo == 0 || mustDo == 1) && (mustDo = 2)) for(item(container[a]); mustDo; mustDo = 0)
28 namespace KDevelop {
30 template<class T, int num>
31 QList<T> arrayToList(const KDevVarLengthArray<T, num>& array) {
32 QList<T> ret;
33 FOREACH_ARRAY(const T& item, array)
34 ret << item;
36 return ret;
39 template<class T, int num>
40 QList<T> arrayToVector(const KDevVarLengthArray<T, num>& array) {
41 QVector<T> ret;
42 FOREACH_ARRAY(const T& item, array)
43 ret << item;
45 return ret;
48 template<class Container, class Type>
49 bool arrayContains(Container& container, const Type& value) {
50 for(int a = 0; a < container.size(); ++a)
51 if(container[a] == value)
52 return true;
54 return false;
56 template<class Container, class Type>
57 void insertToArray(Container& array, const Type& item, int position) {
58 Q_ASSERT(position >= 0 && position <= array.size());
59 array.resize(array.size()+1);
60 for(int a = array.size()-1; a > position; --a) {
61 array[a] = array[a-1];
63 array[position] = item;
66 template<class Container>
67 void removeFromArray(Container& array, int position) {
68 Q_ASSERT(position >= 0 && position < array.size());
69 for(int a = position; a < array.size()-1; ++a) {
70 array[a] = array[a+1];
72 array.resize(array.size()-1);
75 template<class Container, class Type>
76 bool removeOne(Container& container, const Type& value) {
77 for(int a = 0; a < container.size(); ++a) {
78 if(container[a] == value) {
79 removeFromArray(container, a);
80 return true;
83 return false;
86 #endif