OpendTect  6.3
i_datainterp.h
Go to the documentation of this file.
1 // No multiple inclusion protection!
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: A.H. Bril
8  Date: Mar 2001
9 ________________________________________________________________________
10 
11 -*/
12 
13 #ifndef mTheType
14 #error To include __FILE__, set mTheType
15 #endif
16 
17 #define mDICB(fntyp,fn) \
18 ((DataInterpreter<mTheType>::fntyp)(&DataInterpreter<mTheType>::fn))
19 
20 #define mDefGetPut(fnnm) \
21 { \
22  getfn = needswap ? mDICB(GetFn,get##fnnm##swp) : mDICB(GetFn,get##fnnm); \
23  putfn = needswap ? mDICB(PutFn,put##fnnm##swp) : mDICB(PutFn,put##fnnm); \
24 }
25 
26 #define mDefGetPutNoSwap(fnnm) \
27 { getfn = mDICB(GetFn,get##fnnm); putfn = mDICB(PutFn,put##fnnm); }
28 
29 
30 template <>
32  bool ignend )
33 {
34  swpfn = dc.nrBytes() == BinDataDesc::N1 ? mDICB(SwapFn,swap0)
35  : ( dc.nrBytes() == BinDataDesc::N8 ? mDICB(SwapFn,swap8)
36  : ( dc.nrBytes() == BinDataDesc::N4 ? mDICB(SwapFn,swap4)
37  : mDICB(SwapFn,swap2) ) );
38 
39  getfn = mDICB(GetFn,get0);
40  putfn = mDICB(PutFn,put0);
41  bool needswap = !ignend && dc.needSwap();
42 
43  if ( !dc.isInteger() )
44  {
45  if ( !dc.isIeee() )
46  {
47  if ( dc.nrBytes() == BinDataDesc::N4 )
48  mDefGetPut(FIbm)
49  }
50  else
51  {
52  if ( dc.nrBytes() == BinDataDesc::N4 )
53  mDefGetPut(F)
54  else if ( dc.nrBytes() == BinDataDesc::N8 )
55  mDefGetPut(D)
56  }
57  }
58  else
59  {
60  if ( dc.isSigned() )
61  {
62  if ( !dc.isIeee() )
63  {
64  switch ( dc.nrBytes() )
65  {
66  case BinDataDesc::N1: mDefGetPutNoSwap(S1) break;
67  case BinDataDesc::N2: mDefGetPut(S2Ibm) break;
68  case BinDataDesc::N4: mDefGetPut(S4Ibm) break;
69  default: pErrMsg("Invalid enum"); break;
70  }
71  }
72  else
73  {
74  switch ( dc.nrBytes() )
75  {
76  case BinDataDesc::N1: mDefGetPutNoSwap(S1) break;
77  case BinDataDesc::N2: mDefGetPut(S2) break;
78  case BinDataDesc::N4: mDefGetPut(S4) break;
79  case BinDataDesc::N8: mDefGetPut(S8) break;
80  }
81  }
82  }
83  else if ( dc.isIeee() )
84  {
85  switch ( dc.nrBytes() )
86  {
87  case BinDataDesc::N1: mDefGetPutNoSwap(U1) break;
88  case BinDataDesc::N2: mDefGetPut(U2) break;
89  case BinDataDesc::N4: mDefGetPut(U4) break;
90  default: pErrMsg("Unhandled enum"); break;
91  }
92  }
93  }
94 }
95 
96 
97 template <>
99  const DataCharacteristics& dc, bool ignend )
100 {
101  set( dc, ignend );
102 }
103 
104 
105 template <>
107  const DataInterpreter& di )
108  : swpfn(di.swpfn)
109  , getfn(di.getfn)
110  , putfn(di.putfn)
111 {
112 }
113 
114 
115 template <>
117  const DataInterpreter<mTheType>& di )
118 {
119  if ( &di != this )
120  {
121  swpfn = di.swpfn;
122  getfn = di.getfn;
123  putfn = di.putfn;
124  }
125  return *this;
126 }
127 
128 
129 template <>
131 {
135  : 1 ));
136 }
137 
138 
139 #define mSet(nb,isint,frmt,iss,swpd) \
140  dc = DataCharacteristics( isint, iss, (BinDataDesc::ByteCount)nb, \
141  DataCharacteristics::frmt, __islittle__ != swpd );
142 
143 template <>
145 {
147  switch ( nrBytes() )
148  {
149 
150  case 2: {
152  mSet(2,true,Ieee,true,false)
154  mSet(2,true,Ieee,false,false)
156  mSet(2,true,Ibm,true,false)
158  mSet(2,true,Ieee,true,true)
160  mSet(2,true,Ieee,false,true)
162  mSet(2,true,Ibm,true,true)
163  }
164 
165  case 4:
166  {
168  mSet(4,true,Ieee,true,false)
170  mSet(4,true,Ieee,false,false)
171  else if ( getfn == &DataInterpreter<mTheType>::getF )
172  mSet(4,false,Ieee,true,false)
174  mSet(4,true,Ibm,true,false)
176  mSet(4,false,Ibm,true,false)
178  mSet(4,true,Ieee,true,true)
180  mSet(4,true,Ieee,false,true)
182  mSet(4,false,Ieee,true,true)
184  mSet(4,true,Ibm,true,true)
186  mSet(4,false,Ibm,true,true)
187  }
188 
189  case 8:
190  {
192  mSet(8,false,Ieee,true,false)
194  mSet(8,false,Ieee,true,true)
196  mSet(8,true,Ieee,true,false)
198  mSet(8,true,Ieee,true,true)
199  }
200 
201  default:
202  {
204  mSet(1,true,Ieee,true,false)
206  mSet(1,true,Ieee,false,false)
207  }
208 
209  }
210 
211  return dc;
212 }
213 
214 #undef mSet
215 
216 
217 template <>
219 {
220  switch ( nrBytes() )
221  {
222  case 2: return getfn == &DataInterpreter<mTheType>::getS2swp
225 
226  case 4: return getfn == &DataInterpreter<mTheType>::getS4swp
231 
232  case 8: return getfn == &DataInterpreter<mTheType>::getDswp
234 
235  }
236  return false;
237 }
238 
239 
240 #define mDoChgSwp(typ) \
241  if ( getfn == &DataInterpreter<mTheType>::get##typ ) \
242  { \
243  getfn = &DataInterpreter<mTheType>::get##typ##swp; \
244  putfn = &DataInterpreter<mTheType>::put##typ##swp; \
245  } \
246  else if ( getfn == &DataInterpreter<mTheType>::get##typ##swp ) \
247  { \
248  getfn = &DataInterpreter<mTheType>::get##typ; \
249  putfn = &DataInterpreter<mTheType>::put##typ; \
250  }
251 
252 
253 template <>
255 {
256  switch ( nrBytes() )
257  {
258  case 2: {
259  mDoChgSwp(S2)
260  else mDoChgSwp(U2)
261  else mDoChgSwp(S2Ibm)
262  }
263 
264  case 4:
265  {
266  mDoChgSwp(S4)
267  else mDoChgSwp(U4)
268  else mDoChgSwp(F)
269  else mDoChgSwp(S4Ibm)
270  else mDoChgSwp(FIbm)
271  }
272 
273  case 8:
274  {
275  mDoChgSwp(D)
276  else mDoChgSwp(S8)
277  }
278 
279  }
280 }
int nrBytes() const
Definition: bindatadesc.h:45
#define mSet(nb, isint, frmt, iss, swpd)
Definition: i_datainterp.h:139
SwapFn swpfn
Definition: datainterp.h:152
DataCharacteristics dataChar() const
GetFn getfn
Definition: datainterp.h:150
void set(const DataCharacteristics &, bool ignoreendianness=false)
use ignoreendianness when you pre-byteswap the data
Definition: bindatadesc.h:45
bool isIeee() const
Definition: datachar.h:53
Byte-level data interpreter.
Definition: cbvswriter.h:20
ByteCount nrBytes() const
Definition: bindatadesc.h:60
Definition: bindatadesc.h:45
PutFn putfn
Definition: datainterp.h:151
#define mDoChgSwp(typ)
Definition: i_datainterp.h:240
byte-level data characteristics of stored data.
Definition: datachar.h:35
#define mDefGetPut(fnnm)
Definition: i_datainterp.h:20
#define mDefGetPutNoSwap(fnnm)
Definition: i_datainterp.h:26
DataInterpreter< T > & operator=(const DataInterpreter< T > &)
bool needSwap() const
Definition: datachar.h:82
bool isInteger() const
Definition: bindatadesc.h:58
bool needSwap() const
Definition: bindatadesc.h:45
#define mDICB(fntyp, fn)
Definition: i_datainterp.h:17
DataInterpreter(const DataCharacteristics &, bool ignoreendianness=false)
#define pErrMsg(msg)
Usual access point for programmer error messages.
Definition: errmsg.h:34
bool isSigned() const
Definition: bindatadesc.h:59

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