Logo ROOT   6.10/09
Reference Guide
TClassRef.cxx
Go to the documentation of this file.
1 // @(#)root/meta:$Id$
2 // Author: Philippe Canal 15/03/2005
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 /** \class TClassRef
13 TClassRef is used to implement a permanent reference to a TClass
14 object. In particular this reference will change if and when the
15 TClass object is regenerated. This regeneration usually happens
16 when a library containing the described class is loaded after a
17 file containing an instance of this class has been opened.
18 
19 The references kept track of using an intrusive double linked list.
20 The intrusive list is maintained by TClass::AddRef and
21 TClass::RemoveRef. The 'start' of the list is held in
22 TClass::fRefStart.
23 */
24 
25 #include "TClassRef.h"
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// Copy ctor, increases reference count to original TClass object.
29 
31  fClassName(org.fClassName), fClassPtr(org.fClassPtr)
32 {
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Create reference to specified class name, but don't set referenced
37 /// class object.
38 
39 TClassRef::TClassRef(const char *classname) :
40  fClassName(classname), fClassPtr(0)
41 {
42 }
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Add reference to specified class object.
46 
48 {
49  if (cl) {
50  fClassName = cl->GetName();
52  }
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Assignment operator implementation, increases reference count to original class object.
57 /// This routines assumes that the copy actually need to be done.
58 
59 void TClassRef::Assign(const TClassRef &rhs)
60 {
61  fClassName = rhs.fClassName;
62  fClassPtr = rhs.fClassPtr;
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Assignment operator, increases reference count to original class object.
67 /// This routines assumes that the copy actually need to be done.
68 
70 {
71  if (rhs) {
72  fClassPtr = rhs->GetPersistentRef();
73  fClassName = rhs->GetName();
74  } else {
75  fClassPtr = 0;
76  fClassName.clear();
77  }
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Return the current TClass object corresponding to fClassName.
82 
84 {
85  if (fClassPtr && *fClassPtr) return *fClassPtr;
86  if (fClassName.size()==0) return 0;
87 
88  TClass *cl = TClass::GetClass(fClassName.c_str());
89  if (cl) {
90  (const_cast<TClassRef*>(this))->fClassPtr = cl->GetPersistentRef();
91  return cl;
92  } else {
93  return 0;
94  }
95 }
96 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
TClass *const * fClassPtr
Definition: TClassRef.h:36
void Assign(const TClassRef &)
Assignment operator implementation, increases reference count to original class object.
Definition: TClassRef.cxx:59
std::string fClassName
Definition: TClassRef.h:32
TClass *const * GetPersistentRef() const
Definition: TClass.h:425
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:71
TClass * InternalGetClass() const
Return the current TClass object corresponding to fClassName.
Definition: TClassRef.cxx:83
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2885
#define org(otri, vertexptr)
Definition: triangle.c:1037
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:29
TClassRef()
Definition: TClassRef.h:45