OpendTect  6.3
monitoriter.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: Bert
8  Date: May 2001 / Mar 2016
9  Contents: PickSet base classes
10 ________________________________________________________________________
11 
12 -*/
13 
14 #include "monitorable.h"
15 
16 
30 template <class ITyp>
32 {
33 public:
34 
35  typedef ITyp IdxType;
36  typedef IdxType size_type;
37  enum Direction { Forward, Backward };
38 
39  inline MonitorableIterBase(const Monitorable&,IdxType startidx,
40  IdxType stopidx);
41  inline MonitorableIterBase(const MonitorableIterBase&);
42  inline virtual ~MonitorableIterBase() { retire(); }
43  inline const Monitorable& monitored() const { return obj_; }
44 
45  inline bool isEmpty() const { return size() < 1; }
46  inline size_type size() const;
47 
48  inline bool next();
49  inline bool isForward() const { return dir_ == Forward; }
50 
51  inline bool isValid() const { return isPresent(curidx_); }
52  inline bool atFirst() const { return curidx_ == startidx_; }
53  inline bool atLast() const { return curidx_ == stopidx_; }
54  inline IdxType curIdx() const { return curidx_; }
55  inline bool isPresent(IdxType) const;
56 
57  virtual void retire() {}
58  virtual void reInit();
59 
60 protected:
61 
62  const Monitorable& obj_;
63  const Direction dir_;
64  const IdxType startidx_;
65  const IdxType stopidx_;
66 
67  IdxType curidx_;
68 
69  mDefNoAssignmentOper(MonitorableIterBase)
70 
71 };
72 
73 
74 
82 template <class ITyp>
84 {
85 public:
86 
87  inline MonitorableIter4Read(const Monitorable&,
88  ITyp startidx,ITyp stopidx);
90 
91  virtual void reInit();
92  virtual void retire();
93 
94 protected:
95 
97 
99 
100 };
101 
102 
110 template <class ITyp>
112 {
113 public:
114 
116  ITyp startidx,ITyp stopidx);
118 
119  inline Monitorable& edited()
120  { return const_cast<Monitorable&>(this->monitored()); }
121  // compiler bug? does not work without the 'this'
122  // more of that in the implementations below ...
123 
124 protected:
125 
126  inline void insertedAtCurrent();
127  inline void currentRemoved();
128 
130 
131 };
132 
133 
134 template <class ITyp> inline
136  ITyp startidx, ITyp stopidx )
137  : obj_(obj)
138  , startidx_(startidx)
139  , stopidx_(stopidx)
140  , dir_(startidx<=stopidx ? Forward : Backward)
141 {
142  if ( startidx_ < 0 || stopidx_ < 0 )
143  {
144  // empty. make this a standard situation:
145  const_cast<IdxType&>( startidx_ ) = 0;
146  const_cast<IdxType&>( stopidx_ ) = -1;
147  const_cast<Direction&>( dir_ ) = Forward;
148  }
149  reInit();
150 }
151 
152 
153 template <class ITyp> inline
155  : obj_(oth.monitored())
156  , startidx_(oth.startidx_)
157  , stopidx_(oth.stopidx_)
158  , dir_(oth.dir_)
159  , curidx_(oth.curidx_)
160 {
161 }
162 
163 
164 template <class ITyp> inline
166 {
167  if ( dir_ == Forward )
168  { curidx_++; return curidx_ <= stopidx_; }
169  else
170  { curidx_--; return curidx_ >= stopidx_; }
171 }
172 
173 
174 template <class ITyp> inline
176 {
177  if ( dir_ == Forward )
178  return idx >= startidx_ && idx <= stopidx_;
179  else
180  return idx <= startidx_ && idx >= stopidx_;
181 }
182 
183 
184 template <class ITyp> inline typename
186 {
187  return dir_ == Forward ? stopidx_-startidx_+1 : startidx_-stopidx_+1;
188 }
189 
190 
191 template <class ITyp> inline
193 {
194  curidx_ = dir_ == Forward ? startidx_ - 1 : startidx_ + 1;
195 }
196 
197 
198 template <class ITyp> inline
200  ITyp startidx, ITyp stopidx )
201  : MonitorableIterBase<ITyp>(obj,startidx,stopidx)
202  , ml_(obj)
203 {
204 }
205 
206 
207 template <class ITyp> inline
209  const MonitorableIter4Read& oth )
210  : MonitorableIterBase<ITyp>(oth)
211  , ml_(oth.obj_)
212 {
213 }
214 
215 
216 template <class ITyp> inline
218 {
219  ml_.unlockNow();
220 }
221 
222 
223 template <class ITyp> inline
225 {
226  ml_.reLock();
228 }
229 
230 
231 template <class ITyp> inline
233  ITyp startidx, ITyp stopidx )
234  : MonitorableIterBase<ITyp>(obj,startidx,stopidx)
235 {
236 }
237 
238 
239 template <class ITyp> inline
241  const MonitorableIter4Write& oth )
242  : MonitorableIterBase<ITyp>(oth)
243 {
244 }
245 
246 
247 template <class ITyp> inline
249 {
251  const_cast<ITyp&>(this->startidx_)++;
252  else
253  {
254  const_cast<ITyp&>(this->stopidx_)++;
255  this->curidx_++;
256  }
257 }
258 
259 
260 template <class ITyp> inline
262 {
264  const_cast<ITyp&>(this->startidx_)--;
265  else
266  {
267  const_cast<ITyp&>(this->stopidx_)--;
268  this->curidx_--;
269  }
270 }
bool isEmpty() const
Definition: monitoriter.h:45
Object that can be MT-safely monitored from cradle to grave.
Definition: monitorable.h:76
MonitorableIter4Write(Monitorable &, ITyp startidx, ITyp stopidx)
Definition: monitoriter.h:232
void unlockNow()
IdxType curIdx() const
Definition: monitoriter.h:54
virtual void reInit()
Definition: monitoriter.h:192
base class for non-const Monitorable iterator.
Definition: monitoriter.h:111
bool isPresent(IdxType) const
Definition: monitoriter.h:175
bool next()
Definition: monitoriter.h:165
protects a Monitorable against change.
Definition: monitorable.h:252
base class for const Monitorable iterator.
Definition: monitoriter.h:83
Definition: monitoriter.h:37
void currentRemoved()
Definition: monitoriter.h:261
MonitorableIter4Read(const Monitorable &, ITyp startidx, ITyp stopidx)
Definition: monitoriter.h:199
bool atFirst() const
Definition: monitoriter.h:52
size_type size() const
Definition: monitoriter.h:185
const Direction dir_
Definition: monitoriter.h:63
const Monitorable & obj_
Definition: monitoriter.h:62
bool isValid() const
Definition: monitoriter.h:51
bool atLast() const
Definition: monitoriter.h:53
IdxType size_type
Definition: monitoriter.h:36
virtual ~MonitorableIterBase()
Definition: monitoriter.h:42
void reLock()
#define mDefNoAssignmentOper(clss)
Definition: commondefs.h:131
MonitorLock ml_
Definition: monitoriter.h:96
virtual void reInit()
Definition: monitoriter.h:224
virtual void retire()
Definition: monitoriter.h:57
const Monitorable & monitored() const
Definition: monitoriter.h:43
Direction
Definition: monitoriter.h:37
MonitorableIterBase(const Monitorable &, IdxType startidx, IdxType stopidx)
Definition: monitoriter.h:135
virtual void retire()
Definition: monitoriter.h:217
Monitorable & edited()
Definition: monitoriter.h:119
const Monitorable & obj_
Definition: monitorable.h:289
base class for Monitorable iterators. Inherit from one of its subclasses.
Definition: monitoriter.h:31
#define mClass(module)
Definition: commondefs.h:161
ITyp IdxType
Definition: monitoriter.h:35
const IdxType startidx_
Definition: monitoriter.h:64
IdxType curidx_
Definition: monitoriter.h:67
void insertedAtCurrent()
Definition: monitoriter.h:248
const IdxType stopidx_
Definition: monitoriter.h:65
bool isForward() const
Definition: monitoriter.h:49

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