ROOT  6.06/09
Reference Guide
TGeoExtension.h
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
3  * All rights reserved. *
4  * *
5  * For the licensing terms see $ROOTSYS/LICENSE. *
6  * For the list of contributors see $ROOTSYS/README/CREDITS. *
7  *************************************************************************/
8 
9 // Author: Andrei.Gheata@cern.ch 29/05/2013
10 // Following proposal by Markus Frank
11 
12 #ifndef ROOT_TGeoExtension
13 #define ROOT_TGeoExtension
14 
15 #include <cassert>
16 
17 #ifndef ROOT_TObject
18 #include "TObject.h"
19 #endif
20 
21 //______________________________________________________________________________
22 // TGeoExtension - ABC for user objects attached to TGeoVolume or TGeoNode.
23 // Provides interface for getting a reference (grab) and
24 // releasing the extension object (release), allowing for
25 // derived classes to implement reference counted sharing.
26 // The user who should attach extensions to logical volumes
27 // or nodes BEFORE applying misalignment information so that
28 // these will be available to all copies.
29 //______________________________________________________________________________
30 
31 class TGeoExtension : public TObject
32 {
33 protected:
35  virtual ~TGeoExtension() {}
36 
37 public:
38  // Method called whenever requiring a pointer to the extension
39  // Equivalent to new()
40  virtual TGeoExtension *Grab() = 0;
41  // Method called always when the pointer to the extension is not needed
42  // Equivalent to delete()
43  virtual void Release() const = 0;
44 
45  ClassDef(TGeoExtension, 1) // User extension for volumes and nodes
46 };
47 
48 
49 //______________________________________________________________________________
50 // TGeoRCExtension - Reference counted extension which has a pointer to and
51 // owns a user defined TObject. This class can be used as
52 // model for a reference counted derivation from TGeoExtension.
53 // The user object becomes owned by the extension.
54 //______________________________________________________________________________
55 
57 {
58 protected:
59  virtual ~TGeoRCExtension() {delete fUserObject;}
60 public:
63 
64  TGeoExtension *Grab() {fRC++; return this;}
65  void Release() const {assert(fRC > 0); fRC--; if (fRC ==0) delete this;}
66 
68  TObject *GetUserObject() const {return fUserObject;}
69 
70 
71 private:
72  // Copy constructor and assignment not allowed
73  TGeoRCExtension(const TGeoRCExtension &); // Not implemented
74  TGeoRCExtension &operator =(const TGeoRCExtension &); // Not implemented
75  mutable Int_t fRC; // Reference counter
76  TObject *fUserObject; // Attached user object
77 
78  ClassDef(TGeoRCExtension, 1) // Reference counted extension for volumes and nodes
79 };
80 
81 #endif
virtual ~TGeoRCExtension()
Definition: TGeoExtension.h:59
#define assert(cond)
Definition: unittest.h:542
void SetUserObject(TObject *obj)
Definition: TGeoExtension.h:67
int Int_t
Definition: RtypesCore.h:41
TGeoRCExtension(TObject *obj)
Definition: TGeoExtension.h:62
TObject * GetUserObject() const
Definition: TGeoExtension.h:68
TGeoExtension * Grab()
Definition: TGeoExtension.h:64
#define ClassDef(name, id)
Definition: Rtypes.h:254
TGeoRCExtension & operator=(const TGeoRCExtension &)
virtual ~TGeoExtension()
Definition: TGeoExtension.h:35
virtual void Release() const =0
void Release() const
Definition: TGeoExtension.h:65
TObject * fUserObject
Definition: TGeoExtension.h:76
Mother of all ROOT objects.
Definition: TObject.h:58
virtual TGeoExtension * Grab()=0
TObject * obj