OpendTect-6_4  6.4
arrayndslice.h
Go to the documentation of this file.
1 #ifndef arrayndslice_h
2 #define arrayndslice_h
3 
4 /*@+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Kristofer Tingdahl
9  Date: 10-12-1999
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 @$*/
14 
15 #include "basicmod.h"
16 #include "arraynd.h"
17 #include "varlenarray.h"
18 
33 {
34 public:
35  virtual ~ArrayNDSliceBase();
36  int getDimSize(int dim) const;
37  int getPos(int dim) const;
38  bool setPos(int dim,int pos);
39  bool init();
40  void setDimMap(int localdim, int remotedim );
41 protected:
42  ArrayNDSliceBase( ArrayNDInfo*,
43  const ArrayNDInfo& );
44  void getSourcePos(const int* localpos,
45  int* sourcepos) const;
48 
52 };
53 
54 
59 template <class T>
60 mClass(Basic) Array1DSlice : public Array1D<T>, public ArrayNDSliceBase
61 {
62 public:
64  Array1DSlice(const ArrayND<T>&);
65  ~Array1DSlice();
66 
67  ValueSeries<T>* clone() const;
68 
69  T get( int ) const;
70  void set( int, T );
71  const Array1DInfo& info() const;
72  bool isSettable() const;
73 
74 protected:
75  const ValueSeries<T>* getStorage_() const;
76 
77  bool writable_;
80 };
81 
82 
87 template <class T>
88 mClass(Basic) Array2DSlice : public Array2D<T>, public ArrayNDSliceBase
89 {
90 public:
92  Array2DSlice(const ArrayND<T>&);
93  ~Array2DSlice();
94 
95  T get(int,int) const;
96  void set(int,int, T );
97  const Array2DInfo& info() const;
98  bool isSettable() const;
99 
100 protected:
101  const ValueSeries<T>* getStorage_() const;
102  bool writable_;
103 
106 };
107 
108 
109 //Array1DSlice
110 template <class T> inline
112  : ArrayNDSliceBase( new Array1DInfoImpl, source.info() )
113  , source_( source )
114  , storage_( 0 )
115  , writable_( true )
116 {}
117 
118 
119 template <class T> inline
121  : ArrayNDSliceBase( new Array1DInfoImpl, source.info() )
122  , source_( const_cast<ArrayND<T>& >(source) )
123  , storage_( 0 )
124  , writable_( false )
125 {}
126 
127 
128 template <class T> inline
130 { delete storage_; }
131 
132 
133 template <class T> inline
135 { return writable_ && source_.isSettable(); }
136 
137 
138 template <class T> inline
139 void Array1DSlice<T>::set( int pos, T val )
140 {
141  if ( !writable_ ) return;
142  mAllocVarLenArr( int, srcpos, position_.size() );
143  getSourcePos( &pos, srcpos );
144  source_.setND( srcpos, val );
145 }
146 
147 
148 template <class T> inline
149 T Array1DSlice<T>::get( int pos ) const
150 {
151  mAllocVarLenArr( int, srcpos, position_.size() );
152  getSourcePos( &pos, srcpos );
153  return source_.getND( srcpos );
154 }
155 
156 
157 template <class T> inline
159 {
161  res->info_ = info_;
162  res->vardim_ = vardim_;
163  res->position_ = position_;
164  res->offset_ = offset_;
165 
166  return res;
167 }
168 
169 template <class T> inline
171 { return (const Array1DInfo&) info_; }
172 
173 
174 template <class T> inline
176 {
177  if ( offset_<0 )
178  return 0;
179 
180  if ( !source_.getStorage() )
181  return 0;
182 
183  if ( offset_==0 )
184  {
185  delete storage_;
186  storage_ = 0;
187  return source_.getStorage();
188  }
189 
190  if ( !storage_ || &storage_->source() != source_.getStorage() )
191  {
192  delete storage_;
193  storage_ =
194  new OffsetValueSeries<T>( *source_.getStorage(), offset_ );
195  }
196  else
197  storage_->setOffset( offset_ );
198  return storage_;
199 }
200 
201 
202 //Array2DSlice
203 template <class T> inline
205  : ArrayNDSliceBase( new Array2DInfoImpl, source.info() )
206  , source_( source )
207  , storage_( 0 )
208  , writable_( true )
209 {}
210 
211 
212 template <class T> inline
214  : ArrayNDSliceBase( new Array2DInfoImpl, source.info() )
215  , source_( const_cast<ArrayND<T>&>(source) )
216  , storage_( 0 )
217  , writable_( false )
218 {}
219 
220 
221 template <class T> inline
223 { delete storage_; }
224 
225 
226 template <class T> inline
228 { return writable_ && source_.isSettable(); }
229 
230 
231 template <class T> inline
232 void Array2DSlice<T>::set( int pos0, int pos1, T val )
233 {
234  if ( !writable_ ) return;
235 
236  const int localpos[] = { pos0, pos1 };
237  mAllocVarLenArr( int, srcpos, position_.size() );
238  getSourcePos( localpos, srcpos );
239  source_.setND( srcpos, val );
240 }
241 
242 
243 template <class T> inline
244 T Array2DSlice<T>::get( int pos0, int pos1 ) const
245 {
246  const int localpos[] = { pos0, pos1 };
247  mAllocVarLenArr( int, srcpos, position_.size() );
248  getSourcePos( localpos, srcpos );
249  return source_.getND( srcpos );
250 }
251 
252 
253 template <class T> inline
255 { return (const Array2DInfo&) info_; }
256 
257 
258 template <class T> inline
260 {
261  if ( offset_<0 )
262  return 0;
263 
264  if ( !source_.getStorage() )
265  return 0;
266 
267  if ( offset_==0 )
268  {
269  delete storage_;
270  storage_ = 0;
271  return source_.getStorage();
272  }
273 
274  if ( !storage_ || &storage_->source() != source_.getStorage() )
275  {
276  delete storage_;
277  storage_ =
278  new OffsetValueSeries<T>( *source_.getStorage(), offset_ );
279  }
280  else
281  storage_->setOffset( offset_ );
282 
283  return storage_;
284 }
285 
286 
287 
288 #endif
Array1D ( Subclass of ArrayND ) is a one dimensional array.
Definition: arraynd.h:101
#define mExpClass(module)
Definition: commondefs.h:160
bool writable_
Definition: arrayndslice.h:77
const Array2DInfo & info() const
Definition: arrayndslice.h:254
void getSourcePos(const int *localpos, int *sourcepos) const
Subclass of Array1D and ArrayNDSliceBase.
Definition: arrayndslice.h:60
#define od_int64
Definition: plftypes.h:36
bool init()
Contains the information about the size of ArrayND, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:23
Contains the information about the size of Array1D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:71
Array1DSlice(ArrayND< T > &)
Definition: arrayndslice.h:111
ValueSeries of offsets.
Definition: valseries.h:69
const ValueSeries< T > * getStorage_() const
Definition: arrayndslice.h:259
int64_t offset_
Definition: arrayndslice.h:51
OffsetValueSeries< T > * storage_
Definition: arrayndslice.h:79
Array2DSlice(ArrayND< T > &)
Definition: arrayndslice.h:204
Array2D ( Subclass of ArrayND ) is a two dimensional array.
Definition: arraynd.h:131
~Array1DSlice()
Definition: arrayndslice.h:129
Subclass of Array2D and ArrayNDSliceBase.
Definition: arrayndslice.h:88
bool isSettable() const
Definition: arrayndslice.h:134
const ArrayNDInfo & sourceinfo_
Definition: arrayndslice.h:47
Interface to a series of values.
Definition: odmemory.h:17
ArrayND< T > & source_
Definition: arrayndslice.h:78
const ValueSeries< T > * getStorage_() const
Definition: arrayndslice.h:175
Contains the information about the size of Array2D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:95
T get(int, int) const
Definition: arrayndslice.h:244
void set(int, int, T)
Definition: arrayndslice.h:232
#define mAllocVarLenArr(type, varnm, __size)
Definition: varlenarray.h:54
bool writable_
Definition: arrayndslice.h:102
ArrayND< T > & source_
Definition: arrayndslice.h:104
An ArrayND is an array with a given number of dimensions and a size.
Definition: arraynd.h:33
bool isSettable() const
Definition: arrayndslice.h:227
~Array2DSlice()
Definition: arrayndslice.h:222
size_type size() const
Definition: typeset.h:254
ValueSeries< T > * clone() const
Definition: arrayndslice.h:158
const Array1DInfo & info() const
Definition: arrayndslice.h:170
Implementation of Array1DInfo.
Definition: arrayndinfo.h:140
OffsetValueSeries< T > * storage_
Definition: arrayndslice.h:105
ArrayNDInfo & info_
Definition: arrayndslice.h:46
Implementation of Array2DInfo.
Definition: arrayndinfo.h:166
TypeSet< int > position_
Definition: arrayndslice.h:50
T get(int) const
Definition: arrayndslice.h:149
Base class of Array1DSlice and Array2DSlice. Access-tool to another ArrayND with higher dimensionalit...
Definition: arrayndslice.h:32
TypeSet< int > vardim_
Definition: arrayndslice.h:49
#define mClass(module)
Definition: commondefs.h:164
void set(int, T)
Definition: arrayndslice.h:139

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