26 template <
class RT,
class T>
30 inline RT roundOff(
double x ) {
return (
RT) ((x)>0 ? (x)+.5 : (x)-.5); }
33 inline RT roundOff(
float x ) {
return (
RT) ((x)>0 ? (x)+.5f : (x)-.5f); }
36 inline void Swap( T& a, T& b ) { T tmp = a; a = b; b = tmp; }
38 template <
class fT,
class eT>
39 inline bool isFPZero( fT v, eT eps ) {
return v < eps && v > -eps; }
41 template <
class T1,
class T2,
class eT>
44 #define mRounded(typ,x) roundOff<typ>( x ) 45 #define mNINT32(x) mRounded( od_int32, x ) 46 #define mNINT64(x) mRounded( od_int64, x ) 48 #define mMAX(x,y) ( (x)>(y) ? (x) : (y) ) 49 #define mMIN(x,y) ( (x)<(y) ? (x) : (y) ) 50 #define mMaxLimited(v,lim) ( (v)<(lim) ? (v) : (lim) ) 51 #define mMinLimited(v,lim) ( (v)>(lim) ? (v) : (lim) ) 53 #define mIsZero(x,eps) isFPZero( x, eps ) 54 #define mIsEqual(x,y,eps) isFPEqual( x, y, eps ) 55 #define mIsEqualWithUdf(x,y,e) ((mIsUdf(x) && mIsUdf(y)) || mIsEqual(x,y,e) ) 56 #define mDefEpsF (1e-10f) 57 #define mDefEpsD (1e-10) 58 #define mDefEps mDefEpsD 64 # define M_PI 3.14159265358979323846 67 # define M_PIl 3.1415926535897932384626433832795029L 70 # define M_2PI 6.28318530717958647692 73 # define M_PI_2 1.57079632679489661923 76 # define M_PI_4 0.78539816339744830962 79 # define M_SQRT2 1.41421356237309504880168872421 82 # define M_SQRT1_2 0.70710678118654752440 85 # define M_PIf 3.14159265358979323846f 88 # define M_2PIf 6.28318530717958647692f 91 # define M_PI_2f 1.57079632679489661923f 94 # define M_PI_4f 0.78539816339744830962f 97 # define M_SQRT2f 1.41421356237309504880168872421f 100 # define M_SQRT1_2f 0.70710678118654752440f 104 # define MAXFLOAT 3.4028234663852886e+38F 107 # define MAXDOUBLE 1.7976931348623157e+308 110 #define mFromFeetFactorF 0.3048f 111 #define mFromFeetFactorD 0.3048 112 #define mToFeetFactorF 3.2808399f 113 #define mToFeetFactorD 3.28083989501312336 114 #define mToPercent(f) (mIsUdf(f) ? f : f*100) 115 #define mFromPercent(f) (mIsUdf(f) ? f : f*0.01) 116 #define mDeg2RadD 0.017453292519943292 117 #define mRad2DegD 57.295779513082323 118 #define mDeg2RadF 0.017453292519943292f 119 #define mRad2DegF 57.295779513082323f 124 #define mCast(tp,v) ((tp)(v)) 125 #define cCast(tp,v) const_cast< tp >( v ) 126 #define dCast(tp,v) dynamic_cast< tp >( v ) 127 #define rCast(tp,v) reinterpret_cast< tp >( v ) 128 #define sCast(tp,v) static_cast< tp >( v ) 130 # define mDynamicCast(typ,out,in) out = dynamic_cast< typ >( in ); 131 # define mDynamicCastGet(typ,out,in) typ mDynamicCast(typ,out,in) 133 #define mDefSetupClssMemb(clss,typ,memb) \ 135 clss& memb( typ val ) { memb##_ = val; return *this; } 137 #define mDefSetupMemb(typ,memb) mDefSetupClssMemb(Setup,typ,memb) 147 # define __func__ __FUNCTION__ 156 # define mMaxFilePathLength 255 159 #define mExp( module ) Export_##module 160 #define mExpClass( module ) class mExp( module ) 161 #define mExpStruct( module ) struct mExp( module ) 163 #define mGlobal( module ) mExp( module ) 164 #define mClass( module ) class 165 #define mStruct( module ) mExpStruct( module ) 166 #define mExtern( module ) extern mExp( module ) 167 #define mExternC( module) extern "C" mExp( module ) 169 #define mExportInst( mod, tp ) Extern_##mod tp mExp(mod) 170 #define mExportTemplClassInst(mod) mExportInst(mod,template class) 182 #define mLockStaticInitLock( nm ) \ 183 static volatile int nm = 0; \ 184 Threads::lockSimpleSpinWaitLock( nm ) 186 #define mUnlockStaticInitLock( nm ) \ 187 Threads::unlockSimpleSpinLock( nm ) 191 #define mLockStaticInitLock( nm ) 192 #define mUnlockStaticInitLock( nm ) 196 #define mDefineStaticLocalObject( type, var, init ) \ 197 mLockStaticInitLock( static##var##lck__ ); \ 198 static type var init; \ 199 mUnlockStaticInitLock( static##var##lck__ ) 216 #define mIfNotFirstTime(act) \ 218 static volatile int _already_visited_ = 0; \ 219 if ( !Threads::atomicSetIfValueIs( _already_visited_, \ 228 # define mFDQtclass(cls) class cls; 229 # define mQtclass(cls) ::cls 230 # define mUseQtnamespace 232 # define mFDQtclass(cls) namespace QT_NAMESPACE { class cls; } 233 # define mQtclass(cls) ::QT_NAMESPACE::cls 234 # define mUseQtnamespace using namespace ::QT_NAMESPACE; 241 #define mTryAlloc(var,stmt) \ 242 { try { var = new stmt; } catch ( std::bad_alloc ) { var = 0; } } 244 #define mTryAllocPtrMan(var,stmt) \ 245 { try { var = new stmt; } catch ( std::bad_alloc ) { var.set( 0 ); } } 248 #define mDeclareAndTryAlloc(tp,var,stmt) \ 253 #define mGetIdxArr(tp,var,sz) \ 255 mTryAlloc(var,tp [sz]) \ 257 for ( tp idx=0; idx<sz; idx++ ) \ 280 #define mDoArrayPtrOperation( type, arr, operation, arrsz, ptrinc ) \ 282 type* __curptr = arr; \ 283 for ( const type* __stopptr = __curptr + arrsz; \ 284 __curptr!=__stopptr; \ 287 *__curptr operation; \ #define mGlobal(module)
Definition: commondefs.h:163
bool isFPZero(fT v, eT eps)
Definition: commondefs.h:39
interface to threads that should be portable.
Definition: atomic.h:28
bool isFPEqual(T1 v1, T2 v2, eT eps)
Definition: commondefs.h:42
RT roundOff(T x)
Definition: commondefs.h:27
bool atomicSetIfValueIs(volatile int &val, int curval, int newval, int *actualvalptr)
Definition: atomic.h:99
void Swap(T &a, T &b)
Definition: commondefs.h:36
void unlockSimpleSpinLock(volatile int &lock)
bool lockSimpleSpinWaitLock(volatile int &lock)