OpendTect-6_4  6.4
undefval.h
Go to the documentation of this file.
1 #ifndef undefval_h
2 #define undefval_h
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: A.H. Lammertink
8  Date: 13/01/2005
9  RCS: $Id$
10 ________________________________________________________________________
11 
12 -*/
13 
14 #include "basicmod.h"
15 #include "commondefs.h"
16 #include "plftypes.h"
17 
19 #define __mUndefDValue 1e30
20 #define __mUndefFValue 1e30f
21 #define __mIsUndefinedD(x) (((x)>9.99999e29)&&((x)<1.00001e30))
23 #define __mIsUndefinedF(x) (((x)>9.99999e29f)&&((x)<1.00001e30f))
24 #define __mUndefIntVal 2109876543
26 #define __mUndefIntVal64 9223344556677889900LL
28 
29 
43 namespace Values
44 {
45 
50 template<class T>
51 mClass(Basic) Undef
52 {
53 public:
54  static T val();
55  static bool hasUdf();
56  static bool isUdf(T);
57  void setUdf(T&);
58 };
59 
60 
65 template<>
67 {
68 public:
69  static od_int16 val() { return 32766; }
70  static bool hasUdf() { return false; }
71  static bool isUdf( od_int16 i ) { return i == 32766; }
72  static void setUdf( od_int16& i ) { i = 32766; }
73 };
74 
75 
80 template<>
82 {
83 public:
84  static od_uint16 val() { return 65534; }
85  static bool hasUdf() { return false; }
86  static bool isUdf( od_uint32 i ) { return i == 65534; }
87  static void setUdf( od_uint32& i ) { i = 65534; }
88 };
89 
90 
95 template<>
97 {
98 public:
99  static od_int32 val() { return __mUndefIntVal; }
100  static bool hasUdf() { return true; }
101  static bool isUdf( od_int32 i ) { return i == __mUndefIntVal; }
102  static void setUdf( od_int32& i ) { i = __mUndefIntVal; }
103 };
104 
105 
110 template<>
112 {
113 public:
114  static od_uint32 val() { return __mUndefIntVal; }
115  static bool hasUdf() { return true; }
116  static bool isUdf( od_uint32 i ) { return i == __mUndefIntVal; }
117  static void setUdf( od_uint32& i ) { i = __mUndefIntVal; }
118 };
119 
120 
125 template<>
127 {
128 public:
129  static od_int64 val() { return __mUndefIntVal64; }
130  static bool hasUdf() { return true; }
131  static bool isUdf( od_int64 i ) { return i == __mUndefIntVal64;}
132  static void setUdf( od_int64& i ) { i = __mUndefIntVal64; }
133 };
134 
135 
140 template<>
142 {
143 public:
144  static od_uint64 val() { return __mUndefIntVal64; }
145  static bool hasUdf() { return true; }
146  static bool isUdf( od_uint64 i ) { return i == __mUndefIntVal64;}
147  static void setUdf( od_uint64& i ) { i = __mUndefIntVal64; }
148 };
149 
150 
155 template<>
156 mClass(Basic) Undef<bool>
157 {
158 public:
159  static bool val() { return false; }
160  static bool hasUdf() { return false; }
161  static bool isUdf( bool b ) { return false; }
162  static void setUdf( bool& b ) { b = false; }
163 };
164 
165 
170 template<>
171 mClass(Basic) Undef<float>
172 {
173 public:
174  static float val() { return __mUndefFValue; }
175  static bool hasUdf() { return true; }
176  static bool isUdf( float f ) { return __mIsUndefinedF(f); }
177  static void setUdf( float& f ) { f = __mUndefFValue; }
178 };
179 
180 
185 template<>
186 mClass(Basic) Undef<double>
187 {
188 public:
189  static double val() { return __mUndefDValue; }
190  static bool hasUdf() { return true; }
191  static bool isUdf( double d ) { return __mIsUndefinedD(d); }
192  static void setUdf( double& d ) { d = __mUndefDValue; }
193 };
194 
195 
200 template<>
201 mClass(Basic) Undef<const char*>
202 {
203 public:
204  static const char* val() { return ""; }
205  static bool hasUdf() { return true; }
206  static bool isUdf( const char* s ) { return !s || !*s; }
207  static void setUdf( const char*& ) {}
208 };
209 
210 
215 template<>
216 mClass(Basic) Undef<char*>
217 {
218 public:
219  static const char* val() { return ""; }
220  static bool hasUdf() { return true; }
221  static bool isUdf( const char* s ) { return !s || !*s; }
222  static void setUdf( char*& s ) { if ( s ) *s = '\0'; }
223 };
224 
225 
230 template<>
231 mClass(Basic) Undef<char>
232 {
233 public:
234  static char val() { return -127; }
235  static bool hasUdf() { return true; }
236  static bool isUdf( const char s ) { return s==-127; }
237  static void setUdf( char& s ) { s = -127; }
238 };
239 
240 
241 
242 template <class T> inline
243 bool isUdf( const T& t )
244 {
245  return Undef<T>::isUdf(t);
246 }
247 
248 template <class T> inline
249 const T& udfVal( const T& t )
250 {
252  return u;
253 }
254 
255 template <class T> inline
256 bool hasUdf()
257 {
258  return Undef<T>::hasUdf();
259 }
260 
261 template <class T> inline
262 T& setUdf( T& u )
263 {
264  Undef<T>::setUdf( u );
265  return u;
266 }
267 
268 }
269 
270 
272 #define mUdf(type) Values::Undef<type>::val()
273 #define mSetUdf(val) Values::setUdf(val)
275 
276 
277 
278 template <class T>
279 inline bool isUdfImpl( T val )
280  { return Values::isUdf( val ); }
281 
282 mGlobal(Basic) bool isUdfImpl(float);
283 mGlobal(Basic) bool isUdfImpl(double);
284 
285 
287 # define mIsUdf(val) isUdfImpl(val)
288 
289 
294 #define mFastMaxReasonableFloat 1e20f
295 #define mFastIsFloatDefined(fval) \
296  ( (fval>-mFastMaxReasonableFloat && fval<mFastMaxReasonableFloat) || \
297  (!__mIsUndefinedF(fval) && Math::IsNormalNumber(fval)) )
298 
299 
300 #endif
static bool hasUdf()
Definition: undefval.h:160
static double val()
Definition: undefval.h:189
static bool isUdf(int64_t i)
Definition: undefval.h:131
static bool val()
Definition: undefval.h:159
Templatized undefined and initialisation (i.e. null) values.
Definition: color.h:106
static bool isUdf(float f)
Definition: undefval.h:176
bool hasUdf()
Definition: undefval.h:256
#define mGlobal(module)
Definition: commondefs.h:163
static bool hasUdf()
#define od_int64
Definition: plftypes.h:36
static void setUdf(unsigned int &i)
Definition: undefval.h:117
#define mDefineStaticLocalObject(type, var, init)
Definition: commondefs.h:196
static void setUdf(short &i)
Definition: undefval.h:72
bool isUdfImpl(T val)
Definition: undefval.h:279
static bool hasUdf()
Definition: undefval.h:235
static void setUdf(uint64_t &i)
Definition: undefval.h:147
static bool hasUdf()
Definition: undefval.h:175
static bool isUdf(short i)
Definition: undefval.h:71
#define __mIsUndefinedF(x)
Definition: undefval.h:23
static void setUdf(char &s)
Definition: undefval.h:237
static bool hasUdf()
Definition: undefval.h:145
static unsigned short val()
Definition: undefval.h:84
static bool isUdf(unsigned int i)
Definition: undefval.h:86
static int val()
Definition: undefval.h:99
static bool isUdf(unsigned int i)
Definition: undefval.h:116
static bool hasUdf()
Definition: undefval.h:70
#define __mUndefIntVal
Almost MAXINT so unlikely, but not MAXINT to avoid that.
Definition: undefval.h:25
static bool hasUdf()
Definition: undefval.h:190
#define od_uint32
Definition: plftypes.h:32
static bool isUdf(int i)
Definition: undefval.h:101
static const char * val()
Definition: undefval.h:219
void setUdf(T &)
static void setUdf(const char *&)
Definition: undefval.h:207
static const char * val()
Definition: undefval.h:204
static bool isUdf(T)
static void setUdf(double &d)
Definition: undefval.h:192
static float val()
Definition: undefval.h:174
static bool hasUdf()
Definition: undefval.h:85
static bool isUdf(uint64_t i)
Definition: undefval.h:146
static unsigned int val()
Definition: undefval.h:114
#define od_int16
Definition: plftypes.h:27
static char val()
Definition: undefval.h:234
#define od_uint64
Definition: plftypes.h:37
static bool hasUdf()
Definition: undefval.h:220
const T & udfVal(const T &t)
Definition: undefval.h:249
#define od_int32
Definition: plftypes.h:31
static bool hasUdf()
Definition: undefval.h:205
static bool isUdf(const char *s)
Definition: undefval.h:206
static void setUdf(unsigned int &i)
Definition: undefval.h:87
static bool isUdf(const char s)
Definition: undefval.h:236
static void setUdf(int64_t &i)
Definition: undefval.h:132
static bool isUdf(double d)
Definition: undefval.h:191
T & setUdf(T &u)
Definition: undefval.h:262
#define __mUndefDValue
Undefined value. IEEE gives NaN but that&#39;s not exactly what we want.
Definition: undefval.h:19
#define od_uint16
Definition: plftypes.h:28
static void setUdf(int &i)
Definition: undefval.h:102
static void setUdf(bool &b)
Definition: undefval.h:162
static bool hasUdf()
Definition: undefval.h:115
static bool isUdf(const char *s)
Definition: undefval.h:221
#define __mIsUndefinedD(x)
Check on undefined. Also works when double converted to float and vv.
Definition: undefval.h:22
static void setUdf(char *&s)
Definition: undefval.h:222
static bool isUdf(bool b)
Definition: undefval.h:161
#define __mUndefFValue
Definition: undefval.h:20
static bool hasUdf()
Definition: undefval.h:100
#define mClass(module)
Definition: commondefs.h:164
bool isUdf(const T &t)
Definition: undefval.h:243
static short val()
Definition: undefval.h:69
#define __mUndefIntVal64
Almost MAXINT64 therefore unlikely.
Definition: undefval.h:27
static uint64_t val()
Definition: undefval.h:144
static void setUdf(float &f)
Definition: undefval.h:177
static int64_t val()
Definition: undefval.h:129
Templatized undefined values.
Definition: undefval.h:51
static bool hasUdf()
Definition: undefval.h:130

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019