QGpCoreTools/Global.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpCoreTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2007-07-05
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef GLOBAL_H
00029 #define GLOBAL_H
00030 
00031 #include <QtCore>
00032 
00033 namespace QGpCoreTools {
00034 
00035   // Redefine my own assert (assert even if QT_NO_DEBUG is defined)
00036   #if !defined(ASSERT)
00037   #ifndef NO_ASSERT
00038   #  define ASSERT(cond) do {if(!(cond))qt_assert(#cond,__FILE__,__LINE__);} while(0)
00039   #else
00040   #  define ASSERT(cond)
00041   #endif
00042   #endif
00043 
00044   // With gcc 4.1.2, I have a lot of unecessary warnings with -Wuninitialized
00045   // Maybe gcc will do a better job in the future
00046   #define SAFE_UNINITIALIZED(var,value) var=value;
00047 
00048   #define MAX_INT ((int)((uint)(-1)>>1))
00049   #define MAX_INT32 ((qint32)((quint32)(-1)>>1))
00050 
00051   // Usefull for compatibility with old names of properties in XML files
00052   #define DUMMY_PROPERTIES \
00053   public: \
00054     void setDummyProperty(const QString&) {} \
00055     void setDummyProperty(double) {} \
00056     void setDummyProperty(int) {} \
00057     QString dummyPropertyString() const {return QString::null;} \
00058     double dummyPropertyDouble() const {return 0.0;} \
00059     int dummyPropertyInt() const {return 0;}
00060 
00061   enum AxisType {XAxis, YAxis, ZAxis};
00062   Q_DECLARE_FLAGS(AxisTypes, AxisType)
00063 
00064   template<typename T>
00065   void unique(QList<T>& list)
00066   {
00067     for(int i=1; i<list.count(); ) {
00068       if(list.at(i-1)==list.at(i)) {
00069         list.removeAt(i);
00070       } else {
00071         i++;
00072       }
00073     }
00074   }
00075 
00076   template<typename T>
00077   void uniqueDeleteAll(QList<T>& list)
00078   {
00079     for(int i=1; i<list.count(); ) {
00080       if(list.at(i-1)==list.at(i)) {
00081         delete list.takeAt(i);
00082       } else {
00083         i++;
00084       }
00085     }
00086   }
00087 
00088   template<typename T, typename Equal>
00089   void unique(QList<T>& list, Equal equal)
00090   {
00091     for(int i=1; i<list.count(); ) {
00092       if(equal(list.at(i-1), list.at(i))) {
00093         list.removeAt(i);
00094       } else {
00095         i++;
00096       }
00097     }
00098   }
00099 
00100   template<typename T, typename Equal>
00101   void uniqueDeleteAll(QList<T>& list, Equal equal)
00102   {
00103     for(int i=1; i<list.count(); ) {
00104       if(equal(list.at(i-1), list.at(i))) {
00105         delete list.takeAt(i);
00106       } else {
00107         i++;
00108       }
00109     }
00110   }
00111 
00112   template<typename T>
00113   void unique(QVector<T>& v)
00114   {
00115     for(int i=1; i<v.count(); ) {
00116       if(v.at(i-1)==v.at(i)) {
00117         v.remove(i);
00118       } else {
00119         i++;
00120       }
00121     }
00122   }
00123 
00124   template<typename T>
00125   void uniqueDeleteAll(QVector<T>& v)
00126   {
00127     for(int i=1; i<v.count(); ) {
00128       if(v.at(i-1)==v.at(i)) {
00129         delete v.at(i);
00130         v.remove(i);
00131       } else {
00132         i++;
00133       }
00134     }
00135   }
00136 
00137   template<typename T, typename Equal>
00138   void unique(QVector<T>& v, Equal equal)
00139   {
00140     for(int i=1; i<v.count(); ) {
00141       if(equal(v.at(i-1), v.at(i))) {
00142         v.remove(i);
00143       } else {
00144         i++;
00145       }
00146     }
00147   }
00148 
00149   template<typename T, typename Equal>
00150   void uniqueDeleteAll(QVector<T>& v, Equal equal)
00151   {
00152     for(int i=1; i<v.count(); ) {
00153       if(equal(v.at(i-1), v.at(i))) {
00154         delete v.at(i);
00155         v.remove(i);
00156       } else {
00157         i++;
00158       }
00159     }
00160   }
00161 
00162   #define REGISTER_METATYPE(type) \
00163   class type##InitMetaType \
00164   { \
00165   public: \
00166     type##InitMetaType(); \
00167   }; \
00168   type##InitMetaType::type##InitMetaType() \
00169   { \
00170     qRegisterMetaType<type>(# type); \
00171   } \
00172   type##InitMetaType instance##type##InitMetaType;
00173 
00174 } // namespace QGpCoreTools
00175 
00176 #endif // GLOBAL_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines