OpendTect-6_4  6.4
convmemvalseries.h
Go to the documentation of this file.
1 #ifndef convmemvalseries_h
2 #define convmemvalseries_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Kris Tingdahl
9  Date: Oct 2006
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "valseries.h"
16 #include "datainterp.h"
17 #include "datachar.h"
18 #include "scaler.h"
19 #include "undefarray.h"
20 
21 
27 template <class T>
29 {
30 public:
31 
32  inline ConvMemValueSeries(od_int64 sz,
33  const BinDataDesc& stortype,
34  bool doundef=true,
35  const Scaler* scaler=0);
36 
37  inline ~ConvMemValueSeries();
38  inline bool isOK() const;
39 
40  ValueSeries<T>* clone() const;
41 
42  inline od_int64 size() const;
43  inline bool writable() const;
44  inline T value(od_int64 idx) const;
45  inline void setValue( od_int64 idx, T v );
46 
47  inline bool selfSufficient() const { return true; }
48  inline bool reSizeable() const { return true; }
49  inline bool setSize(od_int64);
50 
51  inline const T* arr() const;
52  inline T* arr();
53 
54  inline char* storArr();
55  inline const char* storArr() const;
56 
57  inline BinDataDesc dataDesc() const;
58  bool handlesUndef() const { return undefhandler_; }
59 
60 protected:
61 
65  const Scaler* scaler_;
66 
67  char* ptr_;
69 };
70 
71 
72 template <class T> inline
74  const BinDataDesc& stortype,
75  bool doundef,
76  const Scaler* scaler )
77  : ptr_( 0 )
78  , scaler_( scaler ? scaler->clone() : 0 )
79  , size_( -1 )
80  , interpreter_( DataCharacteristics(stortype) )
81  , undefhandler_( doundef ? new UndefArrayHandler(stortype) : 0 )
82 {
83  if ( undefhandler_ && !undefhandler_->isOK() )
84  { delete undefhandler_; undefhandler_ = 0; }
85 
86  T dummy;
87  rettype_ = BinDataDesc( dummy );
88  setSize( sz );
89 }
90 
91 
92 template <class T> inline
94 {
95  delete [] ptr_;
96  delete scaler_;
97  delete undefhandler_;
98 }
99 
100 
101 template <class T> inline
103 {
105  interpreter_.dataChar(), undefhandler_, scaler_ );
106  if ( storArr() )
107  OD::memCopy( res->storArr(), storArr(), size_ * interpreter_.nrBytes());
108 
109  return res;
110 }
111 
112 
113 
114 template <class T> inline
116 {
117  if ( undefhandler_ && !undefhandler_->isOK() )
118  return false;
119 
120  return ptr_;
121 }
122 
123 
124 template <class T> inline
126 {
127  if ( undefhandler_ && undefhandler_->isUdf( ptr_,idx ) )
128  return mUdf(T);
129 
130  const T val = interpreter_.get( ptr_, idx );
131  return mCast( T, scaler_ ? scaler_->unScale(val) : val );
132 }
133 
134 
135 template <class T> inline
137 {
138  if ( sz==size_ ) return true;
139 
140  delete [] ptr_;
141  mTryAlloc( ptr_, char[sz*interpreter_.nrBytes()] );
142  return ptr_;
143 }
144 
145 
146 template <class T> inline
148 { return true; }
149 
150 
151 template <class T> inline
153 { return size_; }
154 
155 
156 template <class T> inline
158 {
159  if ( undefhandler_ && mIsUdf(v) )
160  undefhandler_->setUdf( ptr_, idx );
161  else
162  {
163  const T val = mCast( T, scaler_ ? scaler_->scale(v) : v );
164  interpreter_.put( ptr_, idx, val );
165  if ( undefhandler_ ) undefhandler_->unSetUdf( ptr_, idx );
166  }
167 }
168 
169 
170 template <class T> inline
172 {
173  return interpreter_.dataChar() == rettype_
174  ? reinterpret_cast<const T*>(ptr_) : 0;
175 }
176 
177 template <class T> inline
179 { return interpreter_.dataChar()==rettype_ ? reinterpret_cast<T*>(ptr_) : 0; }
180 
181 
182 template <class T> inline
184 { return ptr_; }
185 
186 
187 template <class T> inline
189 { return ptr_; }
190 
191 
192 template <class T> inline
194 { return interpreter_.dataChar(); }
195 
196 
197 #endif
bool handlesUndef() const
Definition: convmemvalseries.h:58
void unSetUdf(void *ptr, od_int64 idx) const
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
bool isUdf(const void *ptr, od_int64 idx) const
od_int64 size_
Definition: convmemvalseries.h:68
void setValue(od_int64 idx, T v)
Definition: convmemvalseries.h:157
#define mCast(tp, v)
Definition: commondefs.h:124
char * ptr_
Definition: convmemvalseries.h:67
#define od_int64
Definition: plftypes.h:36
void setUdf(void *ptr, od_int64 idx) const
Class that handles undefvalues in arrays that are in a format described by a BinDataDesc.
Definition: undefarray.h:39
bool isOK() const
const T * arr() const
Definition: convmemvalseries.h:171
T value(od_int64 idx) const
Definition: convmemvalseries.h:125
char * storArr()
Definition: convmemvalseries.h:183
Byte-level data interpreter.
Definition: cbvswriter.h:22
byte-level data characteristics of stored data.
Definition: datachar.h:37
virtual double unScale(double) const
Definition: scaler.h:45
bool setSize(od_int64)
Definition: convmemvalseries.h:136
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
Interface to a series of values.
Definition: odmemory.h:17
#define mTryAlloc(var, stmt)
Catches bad_alloc and sets ptr to null as normal.
Definition: commondefs.h:241
bool writable() const
Definition: convmemvalseries.h:147
~ConvMemValueSeries()
Definition: convmemvalseries.h:93
Scaling of floating point numbers.
Definition: scaler.h:33
const Scaler * scaler_
Definition: convmemvalseries.h:65
Definition: convmemvalseries.h:28
UndefArrayHandler * undefhandler_
Definition: convmemvalseries.h:62
bool selfSufficient() const
Definition: convmemvalseries.h:47
ValueSeries< T > * clone() const
Definition: convmemvalseries.h:102
BinDataDesc dataDesc() const
Definition: convmemvalseries.h:193
od_int64 size() const
Definition: convmemvalseries.h:152
#define mClass(module)
Definition: commondefs.h:164
ConvMemValueSeries(od_int64 sz, const BinDataDesc &stortype, bool doundef=true, const Scaler *scaler=0)
Definition: convmemvalseries.h:73
virtual double scale(double) const =0
DataInterpreter< T > interpreter_
Definition: convmemvalseries.h:63
Description of binary data.
Definition: bindatadesc.h:43
BinDataDesc rettype_
Definition: convmemvalseries.h:64
bool reSizeable() const
Definition: convmemvalseries.h:48
bool isOK() const
Definition: convmemvalseries.h:115

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