00001 // @(#)root/meta:$Id: TClassRef.h 36061 2010-10-04 16:05:51Z pcanal $ 00002 // Author: Philippe Canal 15/03/2005 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TClassRef 00013 #define ROOT_TClassRef 00014 00015 ////////////////////////////////////////////////////////////////////////// 00016 // // 00017 // TClassRef // 00018 // // 00019 // Reference to a TClass object and intrusive list of other // 00020 // to thise same TClass object references // 00021 // // 00022 ////////////////////////////////////////////////////////////////////////// 00023 00024 #ifndef ROOT_TClass 00025 #include "TClass.h" 00026 #endif 00027 #ifndef ROOT_TRef 00028 #include "TRef.h" 00029 #endif 00030 00031 #include <string> 00032 00033 class TClassRef { 00034 00035 private: 00036 std::string fClassName; //Name of referenced class 00037 TClass *fClassPtr; //! Ptr to the TClass object 00038 TClassRef *fPrevious; //! link to the previous refs 00039 TClassRef *fNext; //! link to the next refs 00040 00041 friend class TClass; 00042 00043 void Assign(const TClassRef &); 00044 void Assign(TClass *); 00045 TClass *InternalGetClass() const; 00046 void ListReset(); 00047 public: 00048 TClassRef() : fClassName(), fClassPtr(0), fPrevious(0), fNext(0) {} 00049 TClassRef(TClass *cl); 00050 TClassRef(const char *classname); 00051 TClassRef(const TClassRef&); 00052 inline TClassRef &operator=(const TClassRef &rhs) { 00053 // Inline implementation of operator= to speed the no-op case. 00054 if (this != &rhs && fClassPtr != rhs.fClassPtr) { 00055 this->Assign(rhs); 00056 } 00057 return *this; 00058 } 00059 inline TClassRef &operator=(TClass *rhs) { 00060 // Inline implementation of operator= to speed the no-op case. 00061 if (this->fClassPtr != rhs) { 00062 this->Assign(rhs); 00063 } 00064 return *this; 00065 } 00066 00067 ~TClassRef() { if (fClassPtr) fClassPtr->RemoveRef(this); }; 00068 00069 void SetName(const char* new_name) { 00070 if ( fClassPtr && fClassName != new_name ) Reset(); 00071 fClassName = new_name; 00072 } 00073 const char *GetClassName() { return fClassName.c_str(); } 00074 TClass *GetClass() const { return fClassPtr ? fClassPtr : InternalGetClass(); } 00075 void Reset() { if (fClassPtr) fClassPtr->RemoveRef(this); fClassPtr = 0; } 00076 00077 TClass* operator->() const { return fClassPtr ? fClassPtr : InternalGetClass(); } 00078 operator TClass*() const { return fClassPtr ? fClassPtr : InternalGetClass(); } 00079 00080 }; 00081 00082 #endif