OpendTect  6.3
monitor.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: April 2016
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "monitorable.h"
14 
15 
16 // Tools for implementation of subclasses of Monitorable
17 
18 
21 #define mImplSimpleMonitoredGet(fnnm,typ,memb) \
22  typ fnnm() const { return getMemberSimple( memb ); }
23 
26 #define mImplSimpleMonitoredSet(fnnm,typ,memb,chgtyp) \
27  void fnnm( typ _set_to_ ) { setMemberSimple( memb, _set_to_, chgtyp, \
28  cUnspecChgID() ); }
29 
39 #define mImplSimpleMonitoredGetSet(pfx,fnnmget,fnnmset,typ,memb,chgtyp) \
40  pfx mImplSimpleMonitoredGet(fnnmget,typ,memb) \
41  pfx mImplSimpleMonitoredSet(fnnmset,const typ&,memb,chgtyp)
42 
43 
44 // Generalised; also available for friend classes
45 #define mLockMonitorable4Read(obj) \
46  Monitorable::AccessLocker accesslocker_( obj )
47 #define mLockMonitorable4Write(obj) \
48  Monitorable::AccessLocker accesslocker_( obj, false )
49 #define mMonitorableLock2Write(obj) accesslocker_.convertToWrite()
50 #define mMonitorableReLock(obj) accesslocker_.reLock()
51 #define mMonitorableUnlockAllAccess(obj) accesslocker_.unlockNow()
52 #define mMonitorableAccessLocker(obj) accesslocker_
53 #define mSendMonitorableChgNotif(obj,typ,id) \
54  (obj).sendChgNotif(accesslocker_,typ,id)
55 #define mSendMonitorableEntireObjChgNotif(obj) \
56  mSendMonitorableChgNotif(obj,Monitorable::cEntireObjectChange(), \
57  Monitorable::cEntireObjectChgID())
58 
59 // Shorthands for class implementation
60 #define mLock4Read() mLockMonitorable4Read(*this)
61 #define mLock4Write() mLockMonitorable4Write(*this)
62 #define mLock2Write() mMonitorableLock2Write(*this)
63 #define mReLock() mMonitorableReLock(*this)
64 #define mUnlockAllAccess() mMonitorableUnlockAllAccess(*this)
65 #define mAccessLocker() mMonitorableAccessLocker(*this)
66 #define mSendChgNotif(typ,id) mSendMonitorableChgNotif(*this,typ,id)
67 #define mSendEntireObjChgNotif() mSendMonitorableEntireObjChgNotif(*this)
68 
69 
70 
71 #define mDeclGenMonitorableAssignment(clss) \
72  private: \
73  void copyClassData(const clss&); \
74  ChangeType compareClassData(const clss&) const; \
75  protected: \
76  void copyAll(const clss&); \
77  public: \
78  clss(const clss&); \
79  clss& operator =(const clss&); \
80  bool operator ==(const clss&) const; \
81  inline bool operator !=( const clss& oth ) const \
82  { return !(*this == oth); } \
83  virtual clss* clone() const { return (clss*)getClone(); } \
84  ChangeType compareWith(const Monitorable&) const
85 
86 
105 #define mDeclAbstractMonitorableAssignment(clss) \
106  mDeclGenMonitorableAssignment(clss)
107 
111 #define mDeclMonitorableAssignment(clss) \
112  mDeclGenMonitorableAssignment(clss); \
113  virtual clss* getClone() const { return new clss( *this ); }
114 
115 
116 #define mImplEmptyMonitorableCopyClassData( clssnm ) \
117 void clssnm::copyClassData( const clssnm& oth ) \
118 { \
119 }
120 
121 #define mImplAlwaysDifferentMonitorableCompareClassData( clssnm ) \
122 Monitorable::ChangeType clssnm::compareClassData( const clssnm& oth ) const \
123 { \
124  return cEntireObjectChange(); \
125 }
126 
127 #define mImplEmptyMonitorableCompare( clssnm ) \
128 Monitorable::ChangeType clssnm::compareClassData( const clssnm& oth ) const \
129 { \
130  return cNoChange(); \
131 }
132 
133 
161 #define mGenImplMonitorableAssignment(pfx,clss,baseclss) \
162 pfx clss& clss::operator =( const clss& oth ) \
163 { \
164  const ChangeType chgtyp = compareWith( oth ); \
165  if ( chgtyp != cNoChange() ) \
166  { \
167  mLock4Write(); \
168  AccessLocker lckr( oth ); \
169  copyAll( oth ); \
170  mSendChgNotif( chgtyp, cUnspecChgID() ); \
171  } \
172  return *this; \
173 } \
174 \
175 pfx bool clss::operator ==( const clss& oth ) const \
176 \
177 { \
178  return compareWith( oth ) == cNoChange(); \
179 } \
180 \
181 pfx void clss::copyAll( const clss& oth ) \
182 { \
183  baseclss::copyAll( oth ); \
184  AccessLocker lckr( oth ); \
185  copyClassData( oth ); \
186 } \
187 \
188 pfx Monitorable::ChangeType clss::compareWith( const Monitorable& mon ) const \
189 { \
190  if ( this == &mon ) \
191  return cNoChange(); \
192  mDynamicCastGet( const clss*, oth, &mon ); \
193  if ( !oth ) \
194  return cEntireObjectChange(); \
195 \
196  mLock4Read(); \
197  AccessLocker lckr( *oth ); \
198  const ChangeType ct = compareClassData( *oth ); \
199  mUnlockAllAccess(); \
200 \
201  return ct != cNoChange() ? ct : baseclss::compareWith( *oth ); \
202 }
203 
204 
205 #define mImplMonitorableAssignment(clss,baseclss) \
206  mGenImplMonitorableAssignment(,clss,baseclss)
207 
208 
209 #define mImplMonitorableAssignmentWithNoMembers( clss, baseclss ) \
210  mImplMonitorableAssignment(clss,baseclss) \
211  mImplEmptyMonitorableCopyClassData( clss ) \
212  mImplEmptyMonitorableCompare( clss )
213 
214 
215 
235 #define mStartMonitorableCompare() ChangeType chgtype = cNoChange()
236 
237 #define mHandleMonitorableCompare( memb, val ) \
238  if ( !(memb == oth.memb) ) \
239  { \
240  if ( chgtype == cNoChange() || chgtype == val ) \
241  chgtype = val; \
242  else \
243  return cEntireObjectChange(); \
244  }
245 
246 #define mHandleMonitorableComparePtrContents( memb, val ) \
247  if ( (memb && !oth.memb) || (!memb && oth.memb) || !(*memb == *oth.memb) ) \
248  { \
249  if ( chgtype == cNoChange() || chgtype == val ) \
250  chgtype = val; \
251  else \
252  return cEntireObjectChange(); \
253  }
254 
255 #define mDeliverMonitorableCompare() return chgtype;
256 
257 
260 #define mDeliverSingCondMonitorableCompare(nochgcond,chgtype) \
261  return (nochgcond) ? cNoChange() : chgtype
262 
263 
266 #define mDeliverYesNoMonitorableCompare(nochgcond) \
267  mDeliverSingCondMonitorableCompare( nochgcond, cEntireObjectChange() )
268 
269 
272 template <class T>
273 inline T Monitorable::getMemberSimple( const T& memb ) const
274 {
275  mLock4Read();
276  return memb;
277 }
278 
279 
282 template <class TMember,class TSetTo>
283 inline void Monitorable::setMemberSimple( TMember& memb, TSetTo setto,
284  ChangeType typ, IDType id )
285 {
286  mLock4Read();
287  if ( memb == setto )
288  return; // common
289 
290  if ( mLock2Write() || !(memb == setto) )
291  {
292  memb = setto;
293  mSendChgNotif( typ, id );
294  }
295 }
#define mLock4Read()
Definition: monitor.h:60
int ChangeType
Definition: monitorable.h:80
#define mLock2Write()
Definition: monitor.h:62
int64_t IDType
Definition: monitorable.h:83
#define mSendChgNotif(typ, id)
Definition: monitor.h:66
void setMemberSimple(TMember &, TSetTo, ChangeType, IDType)
the set function used by mImplSimpleMonitoredSet
Definition: monitor.h:283
T getMemberSimple(const T &) const
the get function used by mImplSimpleMonitoredGet
Definition: monitor.h:273

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