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 TClass *const*fClassPtr; //! Ptr to the permanent TClass ptr/reference
33
34 friend class TClass;
35
36 void Assign(const TClassRef &);
37 void Assign(TClass *);
38 TClass *InternalGetClass() const;
39public:
40 TClassRef() : fClassName(), fClassPtr(nullptr) {}
41 TClassRef(TClass *cl);
42 TClassRef(const char *classname);
43 TClassRef(const TClassRef&);
44 inline TClassRef &operator=(const TClassRef &rhs) {
45 // Inline implementation of operator= to speed the no-op case.
46 if (this != &rhs && (!fClassPtr || fClassPtr != rhs.fClassPtr)) {
47 this->Assign(rhs);
48 }
49 return *this;
50 }
51 inline TClassRef &operator=(TClass *rhs) {
52 // Inline implementation of operator= to speed the no-op case.
53 if ( !this->fClassPtr|| *(this->fClassPtr) != rhs) {
54 this->Assign(rhs);
55 }
56 return *this;
57 }
58
60
61 void SetName(const char* new_name) {
62 if ( fClassPtr && fClassName != new_name ) Reset();
63 fClassName = new_name;
64 }
65 const char *GetClassName() { return fClassName.c_str(); }
66 TClass *GetClass() const { return (fClassPtr && *fClassPtr) ? *fClassPtr : InternalGetClass(); }
67 void Reset() { fClassPtr = nullptr; }
68
70 operator TClass*() const { return (fClassPtr && *fClassPtr )? *fClassPtr : InternalGetClass(); }
71
72};
73
74#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:61
TClassRef & operator=(TClass *rhs)
Definition TClassRef.h:51
TClass * InternalGetClass() const
Return the current TClass object corresponding to fClassName.
Definition TClassRef.cxx:83
TClass *const * fClassPtr
Definition TClassRef.h:32
TClass * GetClass() const
Definition TClassRef.h:66
std::string fClassName
Definition TClassRef.h:31
TClassRef & operator=(const TClassRef &rhs)
Definition TClassRef.h:44
TClass * operator->() const
Definition TClassRef.h:69
void Reset()
Definition TClassRef.h:67
const char * GetClassName()
Definition TClassRef.h:65
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:81