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