ROOT logo
// @(#)root/meta:$Id: TClassRef.cxx 20882 2007-11-19 11:31:26Z rdm $
// Author: Philippe Canal 15/03/2005

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TClassRef is used to implement a permanent reference to a TClass     //
// object.  In particular this reference will change if and when the    //
// TClass object is regenerated.  This regeneration usually happens     //
// when a library containing the described class is loaded after a      //
// file containing an instance of this class has been opened.           //
//                                                                      //
// The references kept track of using an intrusive double linked list.  //
// The intrusive list is maintained by TClass::AddRef and               //
// TClass::RemoveRef.  The 'start' of the list is held in               //
// TClass::fRefStart.                                                   //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TClassRef.h"

//______________________________________________________________________________
TClassRef::TClassRef(const TClassRef &org) :
   fClassName(org.fClassName), fClassPtr(org.fClassPtr), fPrevious(0), fNext(0)
{
   // Copy ctor, increases reference count to original TClass object.

   if (fClassPtr) fClassPtr->AddRef(this);
}

//______________________________________________________________________________
TClassRef::TClassRef(const char *classname) :
    fClassName(classname), fClassPtr(0), fPrevious(0), fNext(0)
{
   // Create reference to specified class name, but don't set referenced
   // class object.
}

//______________________________________________________________________________
TClassRef::TClassRef(TClass *cl) : fClassPtr(cl), fPrevious(0), fNext(0)
{
   // Add reference to specified class object.
   
   if (fClassPtr) {
      fClassName = cl->GetName();
      fClassPtr->AddRef(this);
   }
}

//______________________________________________________________________________
TClassRef &TClassRef::operator=(const TClassRef &rhs)
{
   // Assignment operator, increases reference count to original class object.

   if (this != &rhs) {      
      if (fClassPtr != rhs.fClassPtr) {
         if (fClassPtr) fClassPtr->RemoveRef(this);
         fClassName = rhs.fClassName;
         fClassPtr  = rhs.fClassPtr;
         if (fClassPtr) fClassPtr->AddRef(this);
      }
   }
   return *this;
}

//______________________________________________________________________________
TClassRef &TClassRef::operator=(TClass* rhs)
{
   // Assignment operator, increases reference count to original class object.

   if (this->fClassPtr != rhs) {      
      if (fClassPtr) fClassPtr->RemoveRef(this);
      fClassPtr  = rhs;
      if (fClassPtr) {
         fClassName = fClassPtr->GetName();
         fClassPtr->AddRef(this);
      }
   }
   return *this;
}

//______________________________________________________________________________
TClass *TClassRef::InternalGetClass() const
{
   // Return the current TClass object corresponding to fClassName.

   if (fClassPtr) return fClassPtr;
   if (fClassName.size()==0) return 0;

   (const_cast<TClassRef*>(this))->fClassPtr = TClass::GetClass(fClassName.c_str());
   if (fClassPtr) fClassPtr->AddRef(const_cast<TClassRef*>(this));

   return fClassPtr;
}

//______________________________________________________________________________
void TClassRef::ListReset() 
{
   // Reset this object and all the objects in the list.
   // We assume that the TClass has also reset its fRefStart data member.

   for (TClassRef *ref = this; ref != 0; /* nothing */ ) {
      TClassRef *next = ref->fNext;
      ref->fNext = ref->fPrevious = 0;
      ref->fClassPtr = 0;
      ref = next;
   }
}
 TClassRef.cxx:1
 TClassRef.cxx:2
 TClassRef.cxx:3
 TClassRef.cxx:4
 TClassRef.cxx:5
 TClassRef.cxx:6
 TClassRef.cxx:7
 TClassRef.cxx:8
 TClassRef.cxx:9
 TClassRef.cxx:10
 TClassRef.cxx:11
 TClassRef.cxx:12
 TClassRef.cxx:13
 TClassRef.cxx:14
 TClassRef.cxx:15
 TClassRef.cxx:16
 TClassRef.cxx:17
 TClassRef.cxx:18
 TClassRef.cxx:19
 TClassRef.cxx:20
 TClassRef.cxx:21
 TClassRef.cxx:22
 TClassRef.cxx:23
 TClassRef.cxx:24
 TClassRef.cxx:25
 TClassRef.cxx:26
 TClassRef.cxx:27
 TClassRef.cxx:28
 TClassRef.cxx:29
 TClassRef.cxx:30
 TClassRef.cxx:31
 TClassRef.cxx:32
 TClassRef.cxx:33
 TClassRef.cxx:34
 TClassRef.cxx:35
 TClassRef.cxx:36
 TClassRef.cxx:37
 TClassRef.cxx:38
 TClassRef.cxx:39
 TClassRef.cxx:40
 TClassRef.cxx:41
 TClassRef.cxx:42
 TClassRef.cxx:43
 TClassRef.cxx:44
 TClassRef.cxx:45
 TClassRef.cxx:46
 TClassRef.cxx:47
 TClassRef.cxx:48
 TClassRef.cxx:49
 TClassRef.cxx:50
 TClassRef.cxx:51
 TClassRef.cxx:52
 TClassRef.cxx:53
 TClassRef.cxx:54
 TClassRef.cxx:55
 TClassRef.cxx:56
 TClassRef.cxx:57
 TClassRef.cxx:58
 TClassRef.cxx:59
 TClassRef.cxx:60
 TClassRef.cxx:61
 TClassRef.cxx:62
 TClassRef.cxx:63
 TClassRef.cxx:64
 TClassRef.cxx:65
 TClassRef.cxx:66
 TClassRef.cxx:67
 TClassRef.cxx:68
 TClassRef.cxx:69
 TClassRef.cxx:70
 TClassRef.cxx:71
 TClassRef.cxx:72
 TClassRef.cxx:73
 TClassRef.cxx:74
 TClassRef.cxx:75
 TClassRef.cxx:76
 TClassRef.cxx:77
 TClassRef.cxx:78
 TClassRef.cxx:79
 TClassRef.cxx:80
 TClassRef.cxx:81
 TClassRef.cxx:82
 TClassRef.cxx:83
 TClassRef.cxx:84
 TClassRef.cxx:85
 TClassRef.cxx:86
 TClassRef.cxx:87
 TClassRef.cxx:88
 TClassRef.cxx:89
 TClassRef.cxx:90
 TClassRef.cxx:91
 TClassRef.cxx:92
 TClassRef.cxx:93
 TClassRef.cxx:94
 TClassRef.cxx:95
 TClassRef.cxx:96
 TClassRef.cxx:97
 TClassRef.cxx:98
 TClassRef.cxx:99
 TClassRef.cxx:100
 TClassRef.cxx:101
 TClassRef.cxx:102
 TClassRef.cxx:103
 TClassRef.cxx:104
 TClassRef.cxx:105
 TClassRef.cxx:106
 TClassRef.cxx:107
 TClassRef.cxx:108
 TClassRef.cxx:109
 TClassRef.cxx:110
 TClassRef.cxx:111
 TClassRef.cxx:112
 TClassRef.cxx:113
 TClassRef.cxx:114
 TClassRef.cxx:115