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