Logo ROOT   6.14/05
Reference Guide
TClassRef.h
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 #ifndef ROOT_TClassRef
13 #define ROOT_TClassRef
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TClassRef //
18 // //
19 // Reference to a TClass object and intrusive list of other //
20 // to thise same TClass object references //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TClass.h"
25 #include "TRef.h"
26 
27 #include <string>
28 
29 class TClassRef {
30 
31 private:
32  std::string fClassName; //Name of referenced class
33 #ifdef __CINT__
34  TClass **fClassPtr; //! Ptr to the permanent TClass ptr/reference
35 #else
36  TClass *const*fClassPtr; //! Ptr to the permanent TClass ptr/reference
37 #endif
38 
39  friend class TClass;
40 
41  void Assign(const TClassRef &);
42  void Assign(TClass *);
43  TClass *InternalGetClass() const;
44 public:
45  TClassRef() : fClassName(), fClassPtr(0) {}
46  TClassRef(TClass *cl);
47  TClassRef(const char *classname);
48  TClassRef(const TClassRef&);
49  inline TClassRef &operator=(const TClassRef &rhs) {
50  // Inline implementation of operator= to speed the no-op case.
51  if (this != &rhs && (fClassPtr == 0 || fClassPtr != rhs.fClassPtr)) {
52  this->Assign(rhs);
53  }
54  return *this;
55  }
56  inline TClassRef &operator=(TClass *rhs) {
57  // Inline implementation of operator= to speed the no-op case.
58  if ( this->fClassPtr==0 || *(this->fClassPtr) != rhs) {
59  this->Assign(rhs);
60  }
61  return *this;
62  }
63 
64  ~TClassRef() { };
65 
66  void SetName(const char* new_name) {
67  if ( fClassPtr && fClassName != new_name ) Reset();
68  fClassName = new_name;
69  }
70  const char *GetClassName() { return fClassName.c_str(); }
71  TClass *GetClass() const { return (fClassPtr && *fClassPtr) ? *fClassPtr : InternalGetClass(); }
72  void Reset() { fClassPtr = 0; }
73 
74  TClass* operator->() const { return (fClassPtr && *fClassPtr) ? *fClassPtr : InternalGetClass(); }
75  operator TClass*() const { return (fClassPtr && *fClassPtr )? *fClassPtr : InternalGetClass(); }
76 
77 };
78 
79 #endif
TClass *const * fClassPtr
Definition: TClassRef.h:36
void SetName(const char *new_name)
Definition: TClassRef.h:66
TClassRef & operator=(const TClassRef &rhs)
Definition: TClassRef.h:49
const char * GetClassName()
Definition: TClassRef.h:70
void Reset()
Definition: TClassRef.h:72
TClass * operator->() const
Definition: TClassRef.h:74
TClass * GetClass() const
Definition: TClassRef.h:71
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
~TClassRef()
Definition: TClassRef.h:64
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
TClass * InternalGetClass() const
Return the current TClass object corresponding to fClassName.
Definition: TClassRef.cxx:83
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:29
TClassRef()
Definition: TClassRef.h:45
TClassRef & operator=(TClass *rhs)
Definition: TClassRef.h:56