Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
17 class TGLLockable
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 
41  const TGLLockable *fLockable;
42 
43  public:
44  TUnlocker(const TGLLockable* l) : fLockable(l) {}
45  ~TUnlocker()
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