TClassRef.cxx

Go to the documentation of this file.
00001 // @(#)root/meta:$Id: TClassRef.cxx 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 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TClassRef is used to implement a permanent reference to a TClass     //
00015 // object.  In particular this reference will change if and when the    //
00016 // TClass object is regenerated.  This regeneration usually happens     //
00017 // when a library containing the described class is loaded after a      //
00018 // file containing an instance of this class has been opened.           //
00019 //                                                                      //
00020 // The references kept track of using an intrusive double linked list.  //
00021 // The intrusive list is maintained by TClass::AddRef and               //
00022 // TClass::RemoveRef.  The 'start' of the list is held in               //
00023 // TClass::fRefStart.                                                   //
00024 //                                                                      //
00025 //////////////////////////////////////////////////////////////////////////
00026 
00027 #include "TClassRef.h"
00028 
00029 //______________________________________________________________________________
00030 TClassRef::TClassRef(const TClassRef &org) :
00031    fClassName(org.fClassName), fClassPtr(org.fClassPtr), fPrevious(0), fNext(0)
00032 {
00033    // Copy ctor, increases reference count to original TClass object.
00034 
00035    if (fClassPtr) fClassPtr->AddRef(this);
00036 }
00037 
00038 //______________________________________________________________________________
00039 TClassRef::TClassRef(const char *classname) :
00040     fClassName(classname), fClassPtr(0), fPrevious(0), fNext(0)
00041 {
00042    // Create reference to specified class name, but don't set referenced
00043    // class object.
00044 }
00045 
00046 //______________________________________________________________________________
00047 TClassRef::TClassRef(TClass *cl) : fClassPtr(cl), fPrevious(0), fNext(0)
00048 {
00049    // Add reference to specified class object.
00050    
00051    if (fClassPtr) {
00052       fClassName = cl->GetName();
00053       fClassPtr->AddRef(this);
00054    }
00055 }
00056 
00057 //______________________________________________________________________________
00058 void TClassRef::Assign(const TClassRef &rhs)
00059 {
00060    // Assignment operator implementation, increases reference count to original class object.
00061    // This routines assumes that the copy actually need to be done.
00062 
00063    if (fClassPtr) fClassPtr->RemoveRef(this);
00064    fClassName = rhs.fClassName;
00065    fClassPtr  = rhs.fClassPtr;
00066    if (fClassPtr) fClassPtr->AddRef(this);
00067 }
00068 
00069 //______________________________________________________________________________
00070 void TClassRef::Assign(TClass* rhs)
00071 {
00072    // Assignment operator, increases reference count to original class object.
00073    // This routines assumes that the copy actually need to be done.
00074 
00075    if (fClassPtr) fClassPtr->RemoveRef(this);
00076    fClassPtr  = rhs;
00077    if (fClassPtr) {
00078       fClassName = fClassPtr->GetName();
00079       fClassPtr->AddRef(this);
00080    } else {
00081       fClassName.clear();
00082    }
00083 }
00084 
00085 //______________________________________________________________________________
00086 TClass *TClassRef::InternalGetClass() const
00087 {
00088    // Return the current TClass object corresponding to fClassName.
00089 
00090    if (fClassPtr) return fClassPtr;
00091    if (fClassName.size()==0) return 0;
00092 
00093    (const_cast<TClassRef*>(this))->fClassPtr = TClass::GetClass(fClassName.c_str());
00094    if (fClassPtr) fClassPtr->AddRef(const_cast<TClassRef*>(this));
00095 
00096    return fClassPtr;
00097 }
00098 
00099 //______________________________________________________________________________
00100 void TClassRef::ListReset() 
00101 {
00102    // Reset this object and all the objects in the list.
00103    // We assume that the TClass has also reset its fRefStart data member.
00104 
00105    for (TClassRef *ref = this; ref != 0; /* nothing */ ) {
00106       TClassRef *next = ref->fNext;
00107       ref->fNext = ref->fPrevious = 0;
00108       ref->fClassPtr = 0;
00109       ref = next;
00110    }
00111 }

Generated on Tue Jul 5 14:11:55 2011 for ROOT_528-00b_version by  doxygen 1.5.1