Logo ROOT   6.10/09
Reference Guide
TGLLockable.h
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Matevz Tadel, Feb 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGLLockable_H
13 #define ROOT_TGLLockable_H
14 
15 #include <Rtypes.h>
16 
18 {
19 public:
20  enum ELock { kUnlocked, // Unlocked
21  kDrawLock, // Locked for draw, cannot select or modify
22  kSelectLock, // Locked for select, cannot modify (draw part of select)
23  kModifyLock // Locked for modify, cannot draw or select
24  };
25 
26 private:
27  TGLLockable(const TGLLockable&); // Not implemented
28  TGLLockable& operator=(const TGLLockable&); // Not implemented
29 
30 protected:
31  // Locking - can take/release via const handle
32  mutable ELock fLock; // Lock state.
33 
34  // Ensures unlocking in view of exceptions.
35  class TUnlocker
36  {
37  private:
38  TUnlocker(const TUnlocker&); // Not implemented
39  TUnlocker& operator=(const TUnlocker&); // Not implemented
40 
42 
43  public:
44  TUnlocker(const TGLLockable* l) : fLockable(l) {}
46  {
47  if (fLockable->IsLocked())
48  fLockable->ReleaseLock(fLockable->CurrentLock());
49  }
50  };
51 
52 public:
53  TGLLockable();
54  virtual ~TGLLockable() {}
55 
56  virtual const char* LockIdStr() const { return "<unknown>"; }
57 
58  Bool_t TakeLock(ELock lock) const;
59  Bool_t ReleaseLock(ELock lock) const;
60  Bool_t IsLocked() const { return (fLock != kUnlocked); }
61  ELock CurrentLock() const { return fLock; }
62 
63  Bool_t IsDrawOrSelectLock() const { return fLock == kDrawLock || fLock == kSelectLock; }
64 
65  static const char * LockName(ELock lock);
66  static Bool_t LockValid(ELock lock);
67 
68  ClassDef(TGLLockable, 0); // Lock for viewers and scenes.
69 }; // endclass TGLLockable
70 
71 #endif
TGLLockable & operator=(const TGLLockable &)
Bool_t ReleaseLock(ELock lock) const
Release current lock, make sure it the same as the &#39;lock&#39; argument.
Definition: TGLLockable.cxx:51
const TGLLockable * fLockable
Definition: TGLLockable.h:41
bool Bool_t
Definition: RtypesCore.h:59
TUnlocker(const TGLLockable *l)
Definition: TGLLockable.h:44
TUnlocker & operator=(const TUnlocker &)
static Bool_t LockValid(ELock lock)
Test if lock is a valid type to take/release.
Definition: TGLLockable.cxx:85
#define ClassDef(name, id)
Definition: Rtypes.h:297
virtual const char * LockIdStr() const
Definition: TGLLockable.h:56
virtual ~TGLLockable()
Definition: TGLLockable.h:54
ELock fLock
Definition: TGLLockable.h:32
Bool_t IsDrawOrSelectLock() const
Definition: TGLLockable.h:63
ELock CurrentLock() const
Definition: TGLLockable.h:61
TLine * l
Definition: textangle.C:4
static const char * LockName(ELock lock)
Return name-string for given lock-type.
Definition: TGLLockable.cxx:69
Bool_t IsLocked() const
Definition: TGLLockable.h:60
TUnlocker(const TUnlocker &)
Bool_t TakeLock(ELock lock) const
Lock the object in mode &#39;lock&#39;.
Definition: TGLLockable.cxx:32
Simple locking interface used by viewer and scene.
Definition: TGLLockable.h:17