Logo ROOT   6.08/07
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 class TGeoExtension : public TObject
22 {
23 protected:
25  virtual ~TGeoExtension() {}
26 
27 public:
28  // Method called whenever requiring a pointer to the extension
29  // Equivalent to new()
30  virtual TGeoExtension *Grab() = 0;
31  // Method called always when the pointer to the extension is not needed
32  // Equivalent to delete()
33  virtual void Release() const = 0;
34 
35  ClassDef(TGeoExtension, 1) // User extension for volumes and nodes
36 };
37 
39 {
40 protected:
41  virtual ~TGeoRCExtension() {delete fUserObject;}
42 public:
43  TGeoRCExtension() : TGeoExtension(), fRC(0), fUserObject(0) {fRC++;}
44  TGeoRCExtension(TObject *obj) : TGeoExtension(), fRC(0), fUserObject(obj) {fRC++;}
45 
46  TGeoExtension *Grab() {fRC++; return this;}
47  void Release() const {assert(fRC > 0); fRC--; if (fRC ==0) delete this;}
48 
49  void SetUserObject(TObject *obj) {fUserObject = obj;}
50  TObject *GetUserObject() const {return fUserObject;}
51 
52 
53 private:
54  // Copy constructor and assignment not allowed
55  TGeoRCExtension(const TGeoRCExtension &); // Not implemented
56  TGeoRCExtension &operator =(const TGeoRCExtension &); // Not implemented
57  mutable Int_t fRC; // Reference counter
58  TObject *fUserObject; // Attached user object
59 
60  ClassDef(TGeoRCExtension, 1) // Reference counted extension for volumes and nodes
61 };
62 
63 #endif
virtual ~TGeoRCExtension()
Definition: TGeoExtension.h:41
void Release() const
Definition: TGeoExtension.h:47
TObject * GetUserObject() const
Definition: TGeoExtension.h:50
void SetUserObject(TObject *obj)
Definition: TGeoExtension.h:49
int Int_t
Definition: RtypesCore.h:41
TGeoRCExtension(TObject *obj)
Definition: TGeoExtension.h:44
TGeoExtension * Grab()
Definition: TGeoExtension.h:46
#define ClassDef(name, id)
Definition: Rtypes.h:254
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.cxx:103
virtual ~TGeoExtension()
Definition: TGeoExtension.h:25
virtual void Release() const =0
ABC for user objects attached to TGeoVolume or TGeoNode.
Definition: TGeoExtension.h:21
Reference counted extension which has a pointer to and owns a user defined TObject.
Definition: TGeoExtension.h:38
TObject * fUserObject
Definition: TGeoExtension.h:58
Mother of all ROOT objects.
Definition: TObject.h:37
virtual TGeoExtension * Grab()=0