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