Logo ROOT  
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 
26 #include <string>
27 
28 class TClassRef {
29 
30 private:
31  std::string fClassName; //Name of referenced class
32 #ifdef __CINT__
33  TClass **fClassPtr; //! Ptr to the permanent TClass ptr/reference
34 #else
35  TClass *const*fClassPtr; //! Ptr to the permanent TClass ptr/reference
36 #endif
37 
38  friend class TClass;
39 
40  void Assign(const TClassRef &);
41  void Assign(TClass *);
42  TClass *InternalGetClass() const;
43 public:
45  TClassRef(TClass *cl);
46  TClassRef(const char *classname);
47  TClassRef(const TClassRef&);
48  inline TClassRef &operator=(const TClassRef &rhs) {
49  // Inline implementation of operator= to speed the no-op case.
50  if (this != &rhs && (fClassPtr == 0 || fClassPtr != rhs.fClassPtr)) {
51  this->Assign(rhs);
52  }
53  return *this;
54  }
55  inline TClassRef &operator=(TClass *rhs) {
56  // Inline implementation of operator= to speed the no-op case.
57  if ( this->fClassPtr==0 || *(this->fClassPtr) != rhs) {
58  this->Assign(rhs);
59  }
60  return *this;
61  }
62 
63  ~TClassRef() { };
64 
65  void SetName(const char* new_name) {
66  if ( fClassPtr && fClassName != new_name ) Reset();
67  fClassName = new_name;
68  }
69  const char *GetClassName() { return fClassName.c_str(); }
70  TClass *GetClass() const { return (fClassPtr && *fClassPtr) ? *fClassPtr : InternalGetClass(); }
71  void Reset() { fClassPtr = 0; }
72 
73  TClass* operator->() const { return (fClassPtr && *fClassPtr) ? *fClassPtr : InternalGetClass(); }
74  operator TClass*() const { return (fClassPtr && *fClassPtr )? *fClassPtr : InternalGetClass(); }
75 
76 };
77 
78 #endif
TClassRef::Assign
void Assign(const TClassRef &)
Assignment operator implementation, increases reference count to original class object.
Definition: TClassRef.cxx:59
TClass.h
TClassRef::GetClassName
const char * GetClassName()
Definition: TClassRef.h:75
TClassRef::Reset
void Reset()
Definition: TClassRef.h:77
TClassRef::operator->
TClass * operator->() const
Definition: TClassRef.h:79
TClassRef::GetClass
TClass * GetClass() const
Definition: TClassRef.h:76
TClassRef::InternalGetClass
TClass * InternalGetClass() const
Return the current TClass object corresponding to fClassName.
Definition: TClassRef.cxx:83
TClassRef::SetName
void SetName(const char *new_name)
Definition: TClassRef.h:71
TClass
Definition: TClass.h:80
TClassRef::fClassPtr
TClass *const * fClassPtr
Definition: TClassRef.h:41
TClassRef
Definition: TClassRef.h:28
TClassRef::TClassRef
TClassRef()
Definition: TClassRef.h:50
TClassRef::operator=
TClassRef & operator=(const TClassRef &rhs)
Definition: TClassRef.h:54
TClassRef::fClassName
std::string fClassName
Definition: TClassRef.h:37
TClassRef::~TClassRef
~TClassRef()
Definition: TClassRef.h:69