Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
28class TClassRef {
29
30private:
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;
43public:
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
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
74 operator TClass*() const { return (fClassPtr && *fClassPtr )? *fClassPtr : InternalGetClass(); }
75
76};
77
78#endif
TClassRef is used to implement a permanent reference to a TClass object.
Definition TClassRef.h:28
void SetName(const char *new_name)
Definition TClassRef.h:65
TClassRef & operator=(TClass *rhs)
Definition TClassRef.h:55
TClass * InternalGetClass() const
Return the current TClass object corresponding to fClassName.
Definition TClassRef.cxx:83
TClass *const * fClassPtr
Definition TClassRef.h:35
TClass * GetClass() const
Definition TClassRef.h:70
std::string fClassName
Definition TClassRef.h:31
TClassRef & operator=(const TClassRef &rhs)
Definition TClassRef.h:48
TClass * operator->() const
Definition TClassRef.h:73
void Reset()
Definition TClassRef.h:71
const char * GetClassName()
Definition TClassRef.h:69
void Assign(const TClassRef &)
Assignment operator implementation, increases reference count to original class object.
Definition TClassRef.cxx:59
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80