• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

language/duchain

arrayhelpers.h

00001 /*
00002    Copyright 2008 David Nolden <david.nolden.kdevelop@art-master.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #ifndef ARRAYHELPERS_H
00020 #define ARRAYHELPERS_H
00021 
00022 #include <QtCore/QVector>
00023 #include <QtCore/QList>
00024 
00025 //Foreach macro that also works with KDevVarLengthArray
00026 #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)
00027 
00028 namespace KDevelop {
00029 
00030 template<class T, int num>
00031 QList<T> arrayToList(const KDevVarLengthArray<T, num>& array) {
00032   QList<T> ret;
00033   FOREACH_ARRAY(const T& item, array)
00034     ret << item;
00035 
00036   return ret;
00037 }
00038 
00039 template<class T, int num>
00040 QList<T> arrayToVector(const KDevVarLengthArray<T, num>& array) {
00041   QVector<T> ret;
00042   FOREACH_ARRAY(const T& item, array)
00043     ret << item;
00044 
00045   return ret;
00046 }
00047 
00048 template<class Container, class Type>
00049 bool arrayContains(Container& container, const Type& value) {
00050   for(int a = 0; a < container.size(); ++a)
00051     if(container[a] == value)
00052       return true;
00053 
00054   return false;
00055 }
00056 template<class Container, class Type>
00057 void insertToArray(Container& array, const Type& item, int position) {
00058   Q_ASSERT(position >= 0 && position <= array.size());
00059   array.resize(array.size()+1);
00060   for(int a = array.size()-1; a > position; --a) {
00061     array[a] = array[a-1];
00062   }
00063   array[position] = item;
00064 }
00065 
00066 template<class Container>
00067 void removeFromArray(Container& array, int position) {
00068   Q_ASSERT(position >= 0 && position < array.size());
00069   for(int a = position; a < array.size()-1; ++a) {
00070     array[a] = array[a+1];
00071   }
00072   array.resize(array.size()-1);
00073 }
00074 
00075 template<class Container, class Type>
00076 bool removeOne(Container& container, const Type& value) {
00077   for(int a = 0; a < container.size(); ++a) {
00078     if(container[a] == value) {
00079       removeFromArray(container, a);
00080       return true;
00081     }
00082   }
00083   return false;
00084 }
00085 }
00086 #endif

language/duchain

Skip menu "language/duchain"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal