Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGeoExtension.cxx
Go to the documentation of this file.
1// Author: Andrei.Gheata@cern.ch 29/05/2013
2// Following proposal by Markus Frank
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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#include "TGeoExtension.h"
13#include "Rtypes.h"
14#include <cassert>
15
16
17/** \class TGeoExtension
18\ingroup Geometry_classes
19
20ABC for user objects attached to TGeoVolume or TGeoNode.
21Provides interface for getting a reference (grab) and
22releasing the extension object (release), allowing for
23derived classes to implement reference counted sharing.
24The user who should attach extensions to logical volumes
25or nodes BEFORE applying misalignment information so that
26these will be available to all copies.
27*/
28
29
30/** \class TGeoRCExtension
31\ingroup Geometry_classes
32
33Reference counted extension which has a pointer to and
34owns a user defined TObject. This class can be used as
35model for a reference counted derivation from TGeoExtension.
36
37Note: Creating a TGeoRCExtension with new() automatically grabs it, but the
38creator has to Release it before the pointer gets out of scope.
39The following sequence is valid:
40
41~~~ {.cpp}
42 // producer:
43 TGeoRCExtension *ext = new TGeoRCExtension();
44 some_TGeoVolume->SetUserExtension(ext);
45 ext->Release();
46 // user:
47 TGeoRCExtension *ext = dynamic_cast<TGeoRCExtension*>(some_TGeoVolume->GrabUserExtension());
48 // ... use extension
49 ext->Release();
50~~~
51
52The extension is going to be released by the TGeoVolume holder at the destruction
53or when calling SetUserExtension(0).
54
55The following usage is not correct:
56
57~~~ {.cpp}
58 some_TGeoVolume->SetUserExtension(new TGeoRCExtension())
59~~~
60
61since the producer code does not release the extension.
62One cannot call directly "delete ext" nor allocate an extension on the stack,
63since the destructor is protected. Use Release instead.
64*/
65
67{
68 assert(fRC > 0);
69 fRC--;
70 if (fRC == 0)
71 delete this;
72}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Release() const override