OpendTect  6.3
undefval.h
Go to the documentation of this file.
1 #pragma once
2 /*+
3 ________________________________________________________________________
4 
5  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
6  Author: A.H. Lammertink
7  Date: 13/01/2005
8 ________________________________________________________________________
9 
10 -*/
11 
12 #include "basicmod.h"
13 #include "commondefs.h"
14 #include "plftypes.h"
15 
17 #define __mUndefDValue 1e30
18 #define __mUndefFValue 1e30f
19 #define __mIsUndefinedD(x) (((x)>9.99999e29)&&((x)<1.00001e30))
21 #define __mIsUndefinedF(x) (((x)>9.99999e29f)&&((x)<1.00001e30f))
22 #define __mUndefIntVal 2109876543
24 #define __mUndefIntVal64 9223344556677889900LL
26 
27 
41 namespace Values
42 {
43 
48 template<class T>
49 mClass(Basic) Undef
50 {
51 public:
52  static T val();
53  static bool hasUdf();
54  static bool isUdf(T);
55  void setUdf(T&);
56 };
57 
58 
63 template<>
65 {
66 public:
67  static od_int16 val() { return 32766; }
68  static bool hasUdf() { return false; }
69  static bool isUdf( od_int16 i ) { return i == 32766; }
70  static void setUdf( od_int16& i ) { i = 32766; }
71 };
72 
73 
78 template<>
80 {
81 public:
82  static od_uint16 val() { return 65534; }
83  static bool hasUdf() { return false; }
84  static bool isUdf( od_uint32 i ) { return i == 65534; }
85  static void setUdf( od_uint32& i ) { i = 65534; }
86 };
87 
88 
93 template<>
95 {
96 public:
97  static od_int32 val() { return __mUndefIntVal; }
98  static bool hasUdf() { return true; }
99  static bool isUdf( od_int32 i ) { return i == __mUndefIntVal; }
100  static void setUdf( od_int32& i ) { i = __mUndefIntVal; }
101 };
102 
103 
108 template<>
110 {
111 public:
112  static od_uint32 val() { return __mUndefIntVal; }
113  static bool hasUdf() { return true; }
114  static bool isUdf( od_uint32 i ) { return i == __mUndefIntVal; }
115  static void setUdf( od_uint32& i ) { i = __mUndefIntVal; }
116 };
117 
118 
123 template<>
125 {
126 public:
127  static od_int64 val() { return __mUndefIntVal64; }
128  static bool hasUdf() { return true; }
129  static bool isUdf( od_int64 i ) { return i == __mUndefIntVal64;}
130  static void setUdf( od_int64& i ) { i = __mUndefIntVal64; }
131 };
132 
133 
138 template<>
140 {
141 public:
142  static od_uint64 val() { return __mUndefIntVal64; }
143  static bool hasUdf() { return true; }
144  static bool isUdf( od_uint64 i ) { return i == __mUndefIntVal64;}
145  static void setUdf( od_uint64& i ) { i = __mUndefIntVal64; }
146 };
147 
148 
153 template<>
154 mClass(Basic) Undef<bool>
155 {
156 public:
157  static bool val() { return false; }
158  static bool hasUdf() { return false; }
159  static bool isUdf( bool b ) { return false; }
160  static void setUdf( bool& b ) { b = false; }
161 };
162 
163 
168 template<>
169 mClass(Basic) Undef<float>
170 {
171 public:
172  static float val() { return __mUndefFValue; }
173  static bool hasUdf() { return true; }
174  static bool isUdf( float f ) { return __mIsUndefinedF(f); }
175  static void setUdf( float& f ) { f = __mUndefFValue; }
176 };
177 
178 
183 template<>
184 mClass(Basic) Undef<double>
185 {
186 public:
187  static double val() { return __mUndefDValue; }
188  static bool hasUdf() { return true; }
189  static bool isUdf( double d ) { return __mIsUndefinedD(d); }
190  static void setUdf( double& d ) { d = __mUndefDValue; }
191 };
192 
193 
198 template<>
199 mClass(Basic) Undef<const char*>
200 {
201 public:
202  static const char* val() { return ""; }
203  static bool hasUdf() { return true; }
204  static bool isUdf( const char* s ) { return !s || !*s; }
205  static void setUdf( const char*& ) {}
206 };
207 
208 
213 template<>
214 mClass(Basic) Undef<char*>
215 {
216 public:
217  static const char* val() { return ""; }
218  static bool hasUdf() { return true; }
219  static bool isUdf( const char* s ) { return !s || !*s; }
220  static void setUdf( char*& s ) { if ( s ) *s = '\0'; }
221 };
222 
223 
228 template<>
229 mClass(Basic) Undef<char>
230 {
231 public:
232  static char val() { return -127; }
233  static bool hasUdf() { return true; }
234  static bool isUdf( const char s ) { return s==-127; }
235  static void setUdf( char& s ) { s = -127; }
236 };
237 
238 
239 
240 template <class T> inline
241 bool isUdf( const T& t )
242 {
243  return Undef<T>::isUdf(t);
244 }
245 
246 template <class T> inline
247 const T& udfVal( const T& t )
248 {
250  return u;
251 }
252 
253 template <class T> inline
254 bool hasUdf()
255 {
256  return Undef<T>::hasUdf();
257 }
258 
259 template <class T> inline
260 T& setUdf( T& u )
261 {
262  Undef<T>::setUdf( u );
263  return u;
264 }
265 
266 }
267 
268 
270 #define mUdf(type) Values::Undef<type>::val()
271 #define mSetUdf(val) Values::setUdf(val)
273 
274 
275 
276 template <class T>
277 inline bool isUdfImpl( T val )
278  { return Values::isUdf( val ); }
279 
280 mGlobal(Basic) bool isUdfImpl(float);
281 mGlobal(Basic) bool isUdfImpl(double);
282 
283 
285 # define mIsUdf(val) isUdfImpl(val)
286 
287 
292 #define mFastMaxReasonableFloat 1e20f
293 #define mFastIsFloatDefined(fval) \
294  ( (fval>-mFastMaxReasonableFloat && fval<mFastMaxReasonableFloat) || \
295  (!__mIsUndefinedF(fval) && Math::IsNormalNumber(fval)) )
static bool hasUdf()
Definition: undefval.h:158
static double val()
Definition: undefval.h:187
static bool isUdf(int64_t i)
Definition: undefval.h:129
static bool val()
Definition: undefval.h:157
Templatized undefined and initialisation (i.e. null) values.
Definition: color.h:113
static bool isUdf(float f)
Definition: undefval.h:174
bool hasUdf()
Definition: undefval.h:254
#define mGlobal(module)
Definition: commondefs.h:160
static bool hasUdf()
#define od_int64
Definition: plftypes.h:34
static void setUdf(unsigned int &i)
Definition: undefval.h:115
#define mDefineStaticLocalObject(type, var, init)
Definition: commondefs.h:199
static void setUdf(short &i)
Definition: undefval.h:70
bool isUdfImpl(T val)
Definition: undefval.h:277
static bool hasUdf()
Definition: undefval.h:233
static void setUdf(uint64_t &i)
Definition: undefval.h:145
static bool hasUdf()
Definition: undefval.h:173
static bool isUdf(short i)
Definition: undefval.h:69
#define __mIsUndefinedF(x)
Definition: undefval.h:21
static void setUdf(char &s)
Definition: undefval.h:235
static bool hasUdf()
Definition: undefval.h:143
static unsigned short val()
Definition: undefval.h:82
static bool isUdf(unsigned int i)
Definition: undefval.h:84
static int val()
Definition: undefval.h:97
static bool isUdf(unsigned int i)
Definition: undefval.h:114
static bool hasUdf()
Definition: undefval.h:68
#define __mUndefIntVal
Almost MAXINT so unlikely, but not MAXINT to avoid that.
Definition: undefval.h:23
static bool hasUdf()
Definition: undefval.h:188
#define od_uint32
Definition: plftypes.h:30
static bool isUdf(int i)
Definition: undefval.h:99
static const char * val()
Definition: undefval.h:217
void setUdf(T &)
static void setUdf(const char *&)
Definition: undefval.h:205
static const char * val()
Definition: undefval.h:202
static bool isUdf(T)
static void setUdf(double &d)
Definition: undefval.h:190
static float val()
Definition: undefval.h:172
static bool hasUdf()
Definition: undefval.h:83
static bool isUdf(uint64_t i)
Definition: undefval.h:144
static unsigned int val()
Definition: undefval.h:112
#define od_int16
Definition: plftypes.h:25
static char val()
Definition: undefval.h:232
#define od_uint64
Definition: plftypes.h:35
static bool hasUdf()
Definition: undefval.h:218
const T & udfVal(const T &t)
Definition: undefval.h:247
#define od_int32
Definition: plftypes.h:29
static bool hasUdf()
Definition: undefval.h:203
static bool isUdf(const char *s)
Definition: undefval.h:204
static void setUdf(unsigned int &i)
Definition: undefval.h:85
static bool isUdf(const char s)
Definition: undefval.h:234
static void setUdf(int64_t &i)
Definition: undefval.h:130
static bool isUdf(double d)
Definition: undefval.h:189
T & setUdf(T &u)
Definition: undefval.h:260
#define __mUndefDValue
Undefined value. IEEE gives NaN but that&#39;s not exactly what we want.
Definition: undefval.h:17
#define od_uint16
Definition: plftypes.h:26
static void setUdf(int &i)
Definition: undefval.h:100
static void setUdf(bool &b)
Definition: undefval.h:160
static bool hasUdf()
Definition: undefval.h:113
static bool isUdf(const char *s)
Definition: undefval.h:219
#define __mIsUndefinedD(x)
Check on undefined. Also works when double converted to float and vv.
Definition: undefval.h:20
static void setUdf(char *&s)
Definition: undefval.h:220
static bool isUdf(bool b)
Definition: undefval.h:159
#define __mUndefFValue
Definition: undefval.h:18
static bool hasUdf()
Definition: undefval.h:98
#define mClass(module)
Definition: commondefs.h:161
bool isUdf(const T &t)
Definition: undefval.h:241
static short val()
Definition: undefval.h:67
#define __mUndefIntVal64
Almost MAXINT64 therefore unlikely.
Definition: undefval.h:25
static uint64_t val()
Definition: undefval.h:142
static void setUdf(float &f)
Definition: undefval.h:175
static int64_t val()
Definition: undefval.h:127
Templatized undefined values.
Definition: undefval.h:49
static bool hasUdf()
Definition: undefval.h:128

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