00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FXPOLICIES_H
00023 #define FXPOLICIES_H
00024
00025 #include "FXException.h"
00026
00027 namespace FX {
00028
00033 class QMtxHold;
00034
00035 namespace Pol {
00036
00040 class None0
00041 {
00042 protected:
00043 None0() { }
00044 ~None0() { }
00045 };
00049 template<class type> class None1
00050 {
00051 protected:
00052 None1() { }
00053 ~None1() { }
00054 };
00055
00063 template<class type> class deepCopy
00064 {
00065 protected:
00066 type *data;
00067 public:
00068 deepCopy(type *d) : data(d) { }
00069 deepCopy(const deepCopy &o) : data(o.data->copy()) { FXERRHM(data); }
00070 deepCopy &operator=(const deepCopy &o)
00071 {
00072 FXDELETE(data);
00073 FXERRHM(data=o.data->copy());
00074 return *this;
00075 }
00076 ~deepCopy() { FXDELETE(data); }
00077 friend type *PtrPtr(deepCopy &p) { return p.data; }
00078 friend const type *PtrPtr(const deepCopy &p) { return p.data; }
00079 friend type *&PtrRef(deepCopy &p) { return p.data; }
00080 friend const type *PtrRef(const deepCopy &p) { return p.data; }
00081 };
00082
00090 template<class type> class refCounted
00091 {
00092 protected:
00093 type *data;
00094 public:
00095 refCounted(type *d) : data(d) { ++data->refCount(); }
00096 refCounted(const refCounted &o) : data(o.data) { ++data->refCount(); }
00097 refCounted &operator=(const refCounted &o)
00098 {
00099 if(!--data->refCount()) FXDELETE(data);
00100 data=o.data;
00101 ++data->refCount();
00102 return *this;
00103 }
00104 ~refCounted()
00105 {
00106 if(!--data->refCount()) FXDELETE(data);
00107 }
00108 friend type *PtrPtr(refCounted &p) { return p.data; }
00109 friend const type *PtrPtr(const refCounted &p) { return p.data; }
00110 friend type *&PtrRef(refCounted &p) { return p.data; }
00111 friend const type *PtrRef(const refCounted &p) { return p.data; }
00112 };
00113
00119 template<class type> class destructiveCopyNoDelete
00120 {
00121 protected:
00122 mutable type *data;
00123 destructiveCopyNoDelete &operator=(const destructiveCopyNoDelete &o);
00124 public:
00125 destructiveCopyNoDelete(type *d) : data(d) { }
00126 destructiveCopyNoDelete(const destructiveCopyNoDelete &o) : data(o.data) { o.data=0; }
00127 friend type *PtrPtr(destructiveCopyNoDelete &p) { return p.data; }
00128 friend const type *PtrPtr(const destructiveCopyNoDelete &p) { return p.data; }
00129 friend type *&PtrRef(destructiveCopyNoDelete &p) { return p.data; }
00130 friend const type *PtrRef(const destructiveCopyNoDelete &p) { return p.data; }
00131 };
00132
00138 template<class type> class destructiveCopy : public destructiveCopyNoDelete<type>
00139 {
00140 public:
00141 destructiveCopy(type *d) : destructiveCopyNoDelete<type>(d) { }
00142 ~destructiveCopy() { FXDELETE(destructiveCopyNoDelete<type>::data); }
00143 destructiveCopy &operator=(const destructiveCopy &o)
00144 {
00145 FXDELETE(destructiveCopyNoDelete<type>::data);
00146 destructiveCopyNoDelete<type>::data=o.data;
00147 o.data=0;
00148 return *this;
00149 }
00150 };
00151
00157 template<class type> class noCopyNoDelete
00158 {
00159 protected:
00160 type *data;
00161 public:
00162 noCopyNoDelete(type *d) : data(d) { }
00163 friend type *PtrPtr(noCopyNoDelete &p) { return p.data; }
00164 friend const type *PtrPtr(const noCopyNoDelete &p) { return p.data; }
00165 friend type *&PtrRef(noCopyNoDelete &p) { return p.data; }
00166 friend const type *PtrRef(const noCopyNoDelete &p) { return p.data; }
00167 };
00168
00174 template<class type> class noCopy : public noCopyNoDelete<type>
00175 {
00176 public:
00177 noCopy(type *d) : noCopyNoDelete<type>(d) { }
00178 ~noCopy() { FXDELETE(noCopyNoDelete<type>::data); }
00179 };
00180
00187 template<class type> struct itMove
00188 {
00189 template<class L, class I> void move(L &list, I to, I &from) const
00190 {
00191 list.splice(to, list, from);
00192 from=--to;
00193 }
00194 };
00201 template<class type> struct itSwap
00202 {
00203 template<class L, class I> void swap(L &list, I &a, I &b) const
00204 {
00205 I _a=a, _b=b; ++_a; ++_b;
00206 if(_b==a)
00207 {
00208 list.splice(b, list, a);
00209 a=--_a; b=--_a;
00210 }
00211 else if(_a==b)
00212 {
00213 list.splice(a, list, b);
00214 b=--_b; a=--_b;
00215 }
00216 else
00217 {
00218 list.splice(b, list, a);
00219 list.splice(_a, list, b);
00220 a=--_a; b=--_b;
00221 }
00222 }
00223 };
00230 template<class type> struct itCompare
00231 {
00232 template<class L, class I> bool compare(L &list, I &a, I &b) const
00233 {
00234 return *a<*b;
00235 }
00236 };
00243 template<class type> struct itRevCompare
00244 {
00245 template<class L, class I> bool compare(L &list, I &a, I &b) const
00246 {
00247 return *a>*b;
00248 }
00249 };
00250
00251 }
00252
00253 }
00254
00255 #endif