Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef GLOBAL_H
00029 #define GLOBAL_H
00030
00031 #include <QtCore>
00032
00033 namespace QGpCoreTools {
00034
00035
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
00045
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
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 }
00175
00176 #endif // GLOBAL_H