OpendTect  6.6
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  RCS: $Id$
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "basicmod.h"
14 #include "commondefs.h"
15 #include "plftypes.h"
16 
18 #define __mUndefDValue 1e30
19 #define __mUndefFValue 1e30f
20 #define __mIsUndefinedD(x) (((x)>9.99999e29)&&((x)<1.00001e30))
22 #define __mIsUndefinedF(x) (((x)>9.99999e29f)&&((x)<1.00001e30f))
23 #define __mIsUndefinedI(x,udfval) (((x)>=udfval)||((x)<=-udfval))
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_uint16 i ) { return i == 65534; }
87  static void setUdf( od_uint16& 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 )
102  { return i>=__mUndefIntVal || i<=-__mUndefIntVal; }
103  static void setUdf( od_int32& i ) { i = __mUndefIntVal; }
104 };
105 
106 
111 template<>
113 {
114 public:
115  static od_uint32 val() { return __mUndefIntVal; }
116  static bool hasUdf() { return true; }
117  static bool isUdf( od_uint32 i ) { return i >= __mUndefIntVal; }
118  static void setUdf( od_uint32& i ) { i = __mUndefIntVal; }
119 };
120 
121 
126 template<>
128 {
129 public:
130  static od_int64 val() { return __mUndefIntVal64; }
131  static bool hasUdf() { return true; }
132  static bool isUdf( od_int64 i )
133  { return i>=__mUndefIntVal64 || i<=-__mUndefIntVal64; }
134  static void setUdf( od_int64& i ) { i = __mUndefIntVal64; }
135 };
136 
137 
142 template<>
144 {
145 public:
146  static od_uint64 val() { return __mUndefIntVal64; }
147  static bool hasUdf() { return true; }
148  static bool isUdf( od_uint64 i ) { return i >= __mUndefIntVal64;}
149  static void setUdf( od_uint64& i ) { i = __mUndefIntVal64; }
150 };
151 
152 
157 template<>
159 {
160 public:
161  static bool val() { return false; }
162  static bool hasUdf() { return false; }
163  static bool isUdf( bool ) { return false; }
164  static void setUdf( bool& b ) { b = false; }
165 };
166 
167 
172 template<>
174 {
175 public:
176  static float val() { return __mUndefFValue; }
177  static bool hasUdf() { return true; }
178  static bool isUdf( float f ) { return __mIsUndefinedF(f); }
179  static void setUdf( float& f ) { f = __mUndefFValue; }
180 };
181 
182 
187 template<>
189 {
190 public:
191  static double val() { return __mUndefDValue; }
192  static bool hasUdf() { return true; }
193  static bool isUdf( double d ) { return __mIsUndefinedD(d); }
194  static void setUdf( double& d ) { d = __mUndefDValue; }
195 };
196 
197 
202 template<>
204 {
205 public:
206  static const char* val() { return ""; }
207  static bool hasUdf() { return true; }
208  static bool isUdf( const char* s ) { return !s || !*s; }
209  static void setUdf( const char*& ) {}
210 };
211 
212 
217 template<>
219 {
220 public:
221  static const char* val() { return ""; }
222  static bool hasUdf() { return true; }
223  static bool isUdf( const char* s ) { return !s || !*s; }
224  static void setUdf( char*& s ) { if ( s ) *s = '\0'; }
225 };
226 
227 
232 template<>
234 {
235 public:
236  static char val() { return -127; }
237  static bool hasUdf() { return true; }
238  static bool isUdf( const char s ) { return s==-127; }
239  static void setUdf( char& s ) { s = -127; }
240 };
241 
242 
243 
244 template <class T> inline
245 bool isUdf( const T& t )
246 {
247  return Undef<T>::isUdf(t);
248 }
249 
250 template <class T> inline
251 const T& udfVal( const T& )
252 {
254  return u;
255 }
256 
257 template <class T> inline
258 bool hasUdf()
259 {
260  return Undef<T>::hasUdf();
261 }
262 
263 template <class T> inline
264 T& setUdf( T& u )
265 {
266  Undef<T>::setUdf( u );
267  return u;
268 }
269 
270 }
271 
272 
274 #define mUdf(type) Values::Undef<type>::val()
275 #define mSetUdf(val) Values::setUdf(val)
277 
278 
279 
280 template <class T>
281 inline bool isUdfImpl( T val )
282  { return Values::isUdf( val ); }
283 
284 mGlobal(Basic) bool isUdfImpl(float);
285 mGlobal(Basic) bool isUdfImpl(double);
286 
287 
289 # define mIsUdf(val) isUdfImpl(val)
290 
291 
296 #define mFastMaxReasonableFloat 1e20f
297 #define mFastIsFloatDefined(fval) \
298  ( (fval>-mFastMaxReasonableFloat && fval<mFastMaxReasonableFloat) || \
299  (!__mIsUndefinedF(fval) && Math::IsNormalNumber(fval)) )
300 
301 
od_uint64
#define od_uint64
Definition: plftypes.h:36
Values::Undef< int >::isUdf
static bool isUdf(int i)
Definition: undefval.h:101
Values::Undef< unsigned int >::isUdf
static bool isUdf(unsigned int i)
Definition: undefval.h:117
Values::Undef< bool >
Undefined bool.
Definition: undefval.h:159
Values::Undef< unsigned int >::val
static unsigned int val()
Definition: undefval.h:115
Values::Undef< const char * >
Undefined const char*.
Definition: undefval.h:204
Values::Undef< int64_t >::isUdf
static bool isUdf(int64_t i)
Definition: undefval.h:132
Values::Undef< char * >::hasUdf
static bool hasUdf()
Definition: undefval.h:222
mGlobal
#define mGlobal(module)
Definition: commondefs.h:180
Values::Undef< char * >
Undefined char*.
Definition: undefval.h:219
Values::Undef< bool >::val
static bool val()
Definition: undefval.h:161
Values::Undef< bool >::isUdf
static bool isUdf(bool)
Definition: undefval.h:163
isUdfImpl
bool isUdfImpl(T val)
Definition: undefval.h:281
Values::Undef< bool >::hasUdf
static bool hasUdf()
Definition: undefval.h:162
commondefs.h
od_int64
#define od_int64
Definition: plftypes.h:35
Values::Undef< short >::isUdf
static bool isUdf(short i)
Definition: undefval.h:71
Values::Undef< int64_t >::hasUdf
static bool hasUdf()
Definition: undefval.h:131
Values::Undef< char * >::isUdf
static bool isUdf(const char *s)
Definition: undefval.h:223
Values::Undef< float >::setUdf
static void setUdf(float &f)
Definition: undefval.h:179
Values::Undef< unsigned int >::hasUdf
static bool hasUdf()
Definition: undefval.h:116
Values::Undef::hasUdf
static bool hasUdf()
Values::Undef< uint64_t >::isUdf
static bool isUdf(uint64_t i)
Definition: undefval.h:148
plftypes.h
Values::setUdf
T & setUdf(T &u)
Definition: undefval.h:264
Values::Undef< char >::hasUdf
static bool hasUdf()
Definition: undefval.h:237
Values::Undef< char >::setUdf
static void setUdf(char &s)
Definition: undefval.h:239
Values::Undef< char >
Undefined char.
Definition: undefval.h:234
Values::Undef< uint64_t >::val
static uint64_t val()
Definition: undefval.h:146
Values::Undef< int >::hasUdf
static bool hasUdf()
Definition: undefval.h:100
Values::Undef< const char * >::isUdf
static bool isUdf(const char *s)
Definition: undefval.h:208
__mIsUndefinedD
#define __mIsUndefinedD(x)
Check on undefined. Also works when double converted to float and vv.
Definition: undefval.h:21
Values::Undef::val
static T val()
Values::Undef< short >::val
static short val()
Definition: undefval.h:69
Values::Undef< float >::val
static float val()
Definition: undefval.h:176
Values::Undef< float >::hasUdf
static bool hasUdf()
Definition: undefval.h:177
Values::Undef< unsigned short >::isUdf
static bool isUdf(unsigned short i)
Definition: undefval.h:86
Values::isUdf
bool isUdf(const T &t)
Definition: undefval.h:245
__mUndefIntVal64
#define __mUndefIntVal64
Almost MAXINT64 therefore unlikely.
Definition: undefval.h:27
Values::Undef< unsigned short >::val
static unsigned short val()
Definition: undefval.h:84
Values::Undef< unsigned short >::hasUdf
static bool hasUdf()
Definition: undefval.h:85
Values::Undef< double >::hasUdf
static bool hasUdf()
Definition: undefval.h:192
Values::Undef< int >::setUdf
static void setUdf(int &i)
Definition: undefval.h:103
Values::Undef< unsigned int >::setUdf
static void setUdf(unsigned int &i)
Definition: undefval.h:118
__mIsUndefinedF
#define __mIsUndefinedF(x)
Definition: undefval.h:22
Values::Undef< char * >::setUdf
static void setUdf(char *&s)
Definition: undefval.h:224
mClass
#define mClass(module)
Definition: commondefs.h:181
od_int16
#define od_int16
Definition: plftypes.h:26
Values::Undef< float >::isUdf
static bool isUdf(float f)
Definition: undefval.h:178
__mUndefFValue
#define __mUndefFValue
Definition: undefval.h:19
__mUndefDValue
#define __mUndefDValue
Undefined value. IEEE gives NaN but that's not exactly what we want.
Definition: undefval.h:18
Values::udfVal
const T & udfVal(const T &)
Definition: undefval.h:251
Values::hasUdf
bool hasUdf()
Definition: undefval.h:258
Values::Undef::setUdf
void setUdf(T &)
Values::Undef< const char * >::setUdf
static void setUdf(const char *&)
Definition: undefval.h:209
od_uint16
#define od_uint16
Definition: plftypes.h:27
Values::Undef< int64_t >::setUdf
static void setUdf(int64_t &i)
Definition: undefval.h:134
Values::Undef< const char * >::hasUdf
static bool hasUdf()
Definition: undefval.h:207
Values::Undef< int64_t >::val
static int64_t val()
Definition: undefval.h:130
Values::Undef< double >
Undefined double.
Definition: undefval.h:189
Values::Undef< short >::setUdf
static void setUdf(short &i)
Definition: undefval.h:72
Values::Undef< char >::val
static char val()
Definition: undefval.h:236
Values::Undef< float >
Undefined float.
Definition: undefval.h:174
Values::Undef::isUdf
static bool isUdf(T)
Values::Undef< double >::val
static double val()
Definition: undefval.h:191
od_int32
#define od_int32
Definition: plftypes.h:30
Values::Undef< unsigned short >::setUdf
static void setUdf(unsigned short &i)
Definition: undefval.h:87
Values::Undef< bool >::setUdf
static void setUdf(bool &b)
Definition: undefval.h:164
__mUndefIntVal
#define __mUndefIntVal
Almost MAXINT so unlikely, but not MAXINT to avoid that.
Definition: undefval.h:25
Values::Undef
Templatized undefined values.
Definition: undefval.h:52
mDefineStaticLocalObject
#define mDefineStaticLocalObject(type, var, init)
Definition: commondefs.h:203
Values::Undef< short >::hasUdf
static bool hasUdf()
Definition: undefval.h:70
Values::Undef< const char * >::val
static const char * val()
Definition: undefval.h:206
Values
Templatized undefined and initialisation (i.e. null) values.
Definition: color.h:113
Values::Undef< double >::isUdf
static bool isUdf(double d)
Definition: undefval.h:193
od_uint32
#define od_uint32
Definition: plftypes.h:31
Values::Undef< char >::isUdf
static bool isUdf(const char s)
Definition: undefval.h:238
Values::Undef< uint64_t >::setUdf
static void setUdf(uint64_t &i)
Definition: undefval.h:149
Values::Undef< int >::val
static int val()
Definition: undefval.h:99
Values::Undef< double >::setUdf
static void setUdf(double &d)
Definition: undefval.h:194
Values::Undef< char * >::val
static const char * val()
Definition: undefval.h:221
Values::Undef< uint64_t >::hasUdf
static bool hasUdf()
Definition: undefval.h:147

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