ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
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())
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 
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
Bool_t IsLocked() const
Definition: TGLLockable.h:60
TGLLockable & operator=(const TGLLockable &)
const TGLLockable * fLockable
Definition: TGLLockable.h:41
ELock CurrentLock() const
Definition: TGLLockable.h:61
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
virtual ~TGLLockable()
Definition: TGLLockable.h:54
ELock fLock
Definition: TGLLockable.h:32
TLine * l
Definition: textangle.C:4
Bool_t ReleaseLock(ELock lock) const
Release current lock, make sure it the same as the 'lock' argument.
Definition: TGLLockable.cxx:51
static const char * LockName(ELock lock)
Return name-string for given lock-type.
Definition: TGLLockable.cxx:69
Bool_t IsDrawOrSelectLock() const
Definition: TGLLockable.h:63
Bool_t TakeLock(ELock lock) const
Lock the object in mode 'lock'.
Definition: TGLLockable.cxx:32
virtual const char * LockIdStr() const
Definition: TGLLockable.h:56
ClassDef(TGLLockable, 0)
TUnlocker(const TUnlocker &)
Simple locking interface used by viewer and scene.
Definition: TGLLockable.h:17