TGenericClassInfo.cxx

Go to the documentation of this file.
00001 // @(#)root/meta:$Id: TGenericClassInfo.cxx 37102 2010-11-30 14:32:28Z rdm $
00002 // Author: Philippe Canal 08/05/2002
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2002, Rene Brun, Fons Rademakers and al.           *
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 #include "TROOT.h"
00013 #include "TClass.h"
00014 #include "TVirtualStreamerInfo.h"
00015 #include "TStreamer.h"
00016 #include "TVirtualIsAProxy.h"
00017 #include "TVirtualCollectionProxy.h"
00018 #include "TCollectionProxyInfo.h"
00019 #include "TSchemaRule.h"
00020 #include "TSchemaRuleSet.h"
00021 #include "TError.h"
00022 #include "TVirtualMutex.h"
00023 #include "TInterpreter.h"
00024 
00025 namespace ROOT {
00026 
00027    const TInitBehavior *DefineBehavior(void * /*parent_type*/,
00028                                        void * /*actual_type*/)
00029    {
00030 
00031       // This function loads the default behavior for the
00032       // loading of classes.
00033 
00034       static TDefaultInitBehavior theDefault;
00035       return &theDefault;
00036    }
00037 
00038 
00039    TGenericClassInfo::TGenericClassInfo(const char *fullClassname,
00040                                         const char *declFileName, Int_t declFileLine,
00041                                         const type_info &info, const TInitBehavior  *action,
00042                                         ShowMembersFunc_t showmembers, VoidFuncPtr_t dictionary,
00043                                         TVirtualIsAProxy *isa, Int_t pragmabits, Int_t sizof)
00044       : fAction(action), fClass(0), fClassName(fullClassname),
00045         fDeclFileName(declFileName), fDeclFileLine(declFileLine),
00046         fDictionary(dictionary), fInfo(info),
00047         fImplFileName(0), fImplFileLine(0),
00048         fIsA(isa), fShowMembers(showmembers),
00049         fVersion(1),
00050         fNew(0),fNewArray(0),fDelete(0),fDeleteArray(0),fDestructor(0), fDirAutoAdd(0), fStreamer(0),
00051         fStreamerFunc(0), fCollectionProxy(0), fSizeof(sizof),
00052         fCollectionProxyInfo(0), fCollectionStreamerInfo(0)
00053    {
00054       // Constructor.
00055 
00056       Init(pragmabits);
00057    }
00058 
00059    TGenericClassInfo::TGenericClassInfo(const char *fullClassname, Int_t version,
00060                                         const char *declFileName, Int_t declFileLine,
00061                                         const type_info &info, const TInitBehavior  *action,
00062                                         ShowMembersFunc_t showmembers,  VoidFuncPtr_t dictionary,
00063                                         TVirtualIsAProxy *isa, Int_t pragmabits, Int_t sizof)
00064       : fAction(action), fClass(0), fClassName(fullClassname),
00065         fDeclFileName(declFileName), fDeclFileLine(declFileLine),
00066         fDictionary(dictionary), fInfo(info),
00067         fImplFileName(0), fImplFileLine(0),
00068         fIsA(isa), fShowMembers(showmembers),
00069         fVersion(version),
00070         fNew(0),fNewArray(0),fDelete(0),fDeleteArray(0),fDestructor(0), fDirAutoAdd(0), fStreamer(0),
00071         fStreamerFunc(0), fCollectionProxy(0), fSizeof(sizof),
00072         fCollectionProxyInfo(0), fCollectionStreamerInfo(0)
00073    {
00074       // Constructor with version number.
00075 
00076       Init(pragmabits);
00077    }
00078 
00079    TGenericClassInfo::TGenericClassInfo(const char *fullClassname, Int_t version,
00080                                         const char *declFileName, Int_t declFileLine,
00081                                         const type_info &info, const TInitBehavior  *action,
00082                                         VoidFuncPtr_t dictionary,
00083                                         TVirtualIsAProxy *isa, Int_t pragmabits, Int_t sizof)
00084       : fAction(action), fClass(0), fClassName(fullClassname),
00085         fDeclFileName(declFileName), fDeclFileLine(declFileLine),
00086         fDictionary(dictionary), fInfo(info),
00087         fImplFileName(0), fImplFileLine(0),
00088         fIsA(isa), fShowMembers(0),
00089         fVersion(version),
00090         fNew(0),fNewArray(0),fDelete(0),fDeleteArray(0),fDestructor(0), fDirAutoAdd(0), fStreamer(0),
00091         fStreamerFunc(0), fCollectionProxy(0), fSizeof(sizof),
00092         fCollectionProxyInfo(0), fCollectionStreamerInfo(0)
00093 
00094    {
00095       // Constructor with version number and no showmembers.
00096 
00097       Init(pragmabits);
00098    }
00099 
00100    class TForNamespace {}; // Dummy class to give a typeid to namespace (See also TClassTable.cc)
00101 
00102    TGenericClassInfo::TGenericClassInfo(const char *fullClassname, Int_t version,
00103                                         const char *declFileName, Int_t declFileLine,
00104                                         const TInitBehavior  *action,
00105                                         VoidFuncPtr_t dictionary, Int_t pragmabits)
00106       : fAction(action), fClass(0), fClassName(fullClassname),
00107         fDeclFileName(declFileName), fDeclFileLine(declFileLine),
00108         fDictionary(dictionary), fInfo(typeid(TForNamespace)),
00109         fImplFileName(0), fImplFileLine(0),
00110         fIsA(0), fShowMembers(0),
00111         fVersion(version),
00112         fNew(0),fNewArray(0),fDelete(0),fDeleteArray(0),fDestructor(0), fDirAutoAdd(0), fStreamer(0),
00113         fStreamerFunc(0), fCollectionProxy(0), fSizeof(0),
00114         fCollectionProxyInfo(0), fCollectionStreamerInfo(0)
00115 
00116    {
00117       // Constructor for namespace
00118 
00119       Init(pragmabits);
00120    }
00121 
00122   /*  TGenericClassInfo::TGenericClassInfo(const TGenericClassInfo& gci) :
00123     fAction(gci.fAction),
00124     fClass(gci.fClass),
00125     fClassName(gci.fClassName),
00126     fDeclFileName(gci.fDeclFileName),
00127     fDeclFileLine(gci.fDeclFileLine),
00128     fDictionary(gci.fDictionary),
00129     fInfo(gci.fInfo),
00130     fImplFileName(gci.fImplFileName),
00131     fImplFileLine(gci.fImplFileLine),
00132     fIsA(gci.fIsA),
00133     fShowMembers(gci.fShowMembers),
00134     fVersion(gci.fVersion),
00135     fNew(gci.fNew),
00136     fNewArray(gci.fNewArray),
00137     fDelete(gci.fDelete),
00138     fDeleteArray(gci.fDeleteArray),
00139     fDestructor(gci.fDestructor),
00140     fStreamer(gci.fStreamer),
00141     fCollectionProxy(gci.fCollectionProxy),
00142     fSizeof(gci.fSizeof)
00143    { }
00144 
00145   TGenericClassInfo& TGenericClassInfo::operator=(const TGenericClassInfo& gci)
00146    {
00147      if(this!=&gci) {
00148        fAction=gci.fAction;
00149        fClass=gci.fClass;
00150        fClassName=gci.fClassName;
00151        fDeclFileName=gci.fDeclFileName;
00152        fDeclFileLine=gci.fDeclFileLine;
00153        fDictionary=gci.fDictionary;
00154        fInfo=gci.fInfo;
00155        fImplFileName=gci.fImplFileName;
00156        fImplFileLine=gci.fImplFileLine;
00157        fIsA=gci.fIsA;
00158        fShowMembers=gci.fShowMembers;
00159        fVersion=gci.fVersion;
00160        fNew=gci.fNew;
00161        fNewArray=gci.fNewArray;
00162        fDelete=gci.fDelete;
00163        fDeleteArray=gci.fDeleteArray;
00164        fDestructor=gci.fDestructor;
00165        fStreamer=gci.fStreamer;
00166        fCollectionProxy=gci.fCollectionProxy;
00167        fSizeof=gci.fSizeof;
00168      } return *this;
00169    }
00170   */
00171 
00172    void TGenericClassInfo::Init(Int_t pragmabits)
00173    {
00174       // Initilization routine.
00175 
00176       //TVirtualStreamerInfo::Class_Version MUST be the same as TStreamerInfo::Class_Version
00177       if (fVersion==-2) fVersion = TVirtualStreamerInfo::Class_Version();
00178       if (!fAction) return;
00179       GetAction().Register(fClassName,
00180                            fVersion,
00181                            fInfo, // typeid(RootClass),
00182                            fDictionary,
00183                            pragmabits);
00184    }
00185 
00186    TGenericClassInfo::~TGenericClassInfo()
00187    {
00188       // Destructor.
00189 
00190       delete fCollectionProxyInfo;
00191       delete fCollectionStreamerInfo;
00192       delete fStreamer;
00193       if (!fClass) delete fIsA; // fIsA is adopted by the class if any.
00194       fIsA = 0;
00195       if (!gROOT || !gROOT->GetListOfClasses()) return;
00196       if (fAction) GetAction().Unregister(GetClassName());
00197    }
00198 
00199    const TInitBehavior &TGenericClassInfo::GetAction() const
00200    {
00201       // Return the creator action.
00202 
00203       return *fAction;
00204    }
00205 
00206    TClass *TGenericClassInfo::GetClass()
00207    {
00208       // Generate and return the TClass object.
00209       R__LOCKGUARD2(gCINTMutex);
00210       if (!fClass && fAction) {
00211          fClass = GetAction().CreateClass(GetClassName(),
00212                                           GetVersion(),
00213                                           GetInfo(),
00214                                           GetIsA(),
00215                                           GetShowMembers(),
00216                                           GetDeclFileName(),
00217                                           GetImplFileName(),
00218                                           GetDeclFileLine(),
00219                                           GetImplFileLine());
00220          fClass->SetNew(fNew);
00221          fClass->SetNewArray(fNewArray);
00222          fClass->SetDelete(fDelete);
00223          fClass->SetDeleteArray(fDeleteArray);
00224          fClass->SetDestructor(fDestructor);
00225          fClass->SetDirectoryAutoAdd(fDirAutoAdd);
00226          fClass->SetStreamerFunc(fStreamerFunc);
00227          fClass->AdoptStreamer(fStreamer); fStreamer = 0;
00228          // If IsZombie is true, something went wront and we will not be
00229          // able to properly copy the collection proxy
00230          if (!fClass->IsZombie()) {
00231             if (fCollectionProxy) fClass->CopyCollectionProxy(*fCollectionProxy);
00232             else if (fCollectionProxyInfo) {
00233                fClass->SetCollectionProxy(*fCollectionProxyInfo);
00234             }
00235          }
00236          fClass->SetClassSize(fSizeof);
00237 
00238          //---------------------------------------------------------------------
00239          // Attach the schema evolution information
00240          //---------------------------------------------------------------------
00241          CreateRuleSet( fReadRules, true );
00242          CreateRuleSet( fReadRawRules, false );
00243       }
00244       return fClass;
00245    }
00246 
00247    //---------------------------------------------------------------------------
00248    void TGenericClassInfo::CreateRuleSet( std::vector<TSchemaHelper>& vect,
00249                                           Bool_t ProcessReadRules )
00250    {
00251       // Attach the schema evolution information to TClassObject
00252 
00253       if ( vect.empty() ) {
00254          return;
00255       }
00256 
00257       //------------------------------------------------------------------------
00258       // Get the rules set
00259       //------------------------------------------------------------------------
00260       TSchemaRuleSet* rset = fClass->GetSchemaRules( kTRUE );
00261 
00262       //------------------------------------------------------------------------
00263       // Process the rules
00264       //------------------------------------------------------------------------
00265       TSchemaRule* rule;
00266       std::vector<TSchemaHelper>::iterator it;
00267       for( it = vect.begin(); it != vect.end(); ++it ) {
00268          rule = new TSchemaRule();
00269          rule->SetTarget( it->fTarget );
00270          rule->SetTargetClass( fClass->GetName() );
00271          rule->SetSourceClass( it->fSourceClass );
00272          rule->SetSource( it->fSource );
00273          rule->SetCode( it->fCode );
00274          rule->SetVersion( it->fVersion );
00275          rule->SetChecksum( it->fChecksum );
00276          rule->SetEmbed( it->fEmbed );
00277          rule->SetInclude( it->fInclude );
00278          rule->SetAttributes( it->fAttributes );
00279 
00280          if( ProcessReadRules ) {
00281             rule->SetRuleType( TSchemaRule::kReadRule );
00282             rule->SetReadFunctionPointer( (TSchemaRule::ReadFuncPtr_t)it->fFunctionPtr );
00283          }
00284          else {
00285             rule->SetRuleType( TSchemaRule::kReadRawRule );
00286             rule->SetReadRawFunctionPointer( (TSchemaRule::ReadRawFuncPtr_t)it->fFunctionPtr );
00287          }
00288          if( !rset->AddRule( rule ) ) {
00289             ::Warning( "TGenericClassInfo", "The rule for class: \"%s\": version, \"%s\" and data members: \"%s\" has been skipped because it conflicts with one of the other rules.",
00290                         GetClassName(), it->fVersion.c_str(), it->fTarget.c_str() );
00291             delete rule;
00292          }
00293       }
00294    }
00295 
00296    const char *TGenericClassInfo::GetClassName() const
00297    {
00298       // Return the class name
00299 
00300       return fClassName;
00301    }
00302 
00303 
00304    TCollectionProxyInfo *TGenericClassInfo::GetCollectionProxyInfo() const
00305    {
00306       // Return the set of info we have for the CollectionProxy, if any
00307 
00308       return fCollectionProxyInfo;
00309    }
00310 
00311    TCollectionProxyInfo *TGenericClassInfo::GetCollectionStreamerInfo() const
00312    {
00313       // Return the set of info we have for the Collection Streamer, if any
00314 
00315       return fCollectionProxyInfo;
00316    }
00317 
00318    const type_info &TGenericClassInfo::GetInfo() const
00319    {
00320       // Return the typeifno value
00321 
00322       return fInfo;
00323    }
00324 
00325    const std::vector<TSchemaHelper>& TGenericClassInfo::GetReadRawRules() const
00326    {
00327       // Return the list of rule give raw access to the TBuffer.
00328 
00329       return fReadRawRules;
00330    }
00331 
00332 
00333    const std::vector<TSchemaHelper>& TGenericClassInfo::GetReadRules() const
00334    {
00335       // Return the list of Data Model Evolution regular read rules.
00336       return fReadRules;
00337    }
00338 
00339    ShowMembersFunc_t TGenericClassInfo::GetShowMembers() const
00340    {
00341       // Return the point of the ShowMembers function
00342       return fShowMembers;
00343    }
00344 
00345    void TGenericClassInfo::SetFromTemplate()
00346    {
00347       // Import the information from the class template.
00348 
00349       TNamed *info = ROOT::RegisterClassTemplate(GetClassName(), 0, 0);
00350       if (info) SetImplFile(info->GetTitle(), info->GetUniqueID());
00351    }
00352 
00353    Int_t TGenericClassInfo::SetImplFile(const char *file, Int_t line)
00354    {
00355       // Set the name of the implementation file.
00356 
00357       fImplFileName = file;
00358       fImplFileLine = line;
00359       if (fClass) fClass->AddImplFile(file,line);
00360       return 0;
00361    }
00362 
00363    Int_t TGenericClassInfo::SetDeclFile(const char *file, Int_t line)
00364    {
00365       // Set the name of the declaration file.
00366 
00367       fDeclFileName = file;
00368       fDeclFileLine = line;
00369       if (fClass) fClass->SetDeclFile(file,line);
00370       return 0;
00371    }
00372 
00373    Short_t TGenericClassInfo::SetVersion(Short_t version)
00374    {
00375       // Set a class version number.
00376 
00377       ROOT::ResetClassVersion(fClass, GetClassName(),version);
00378       fVersion = version;
00379       return version;
00380    }
00381 
00382    void TGenericClassInfo::AdoptCollectionProxyInfo(TCollectionProxyInfo *info)
00383    {
00384       // Set the info for the CollectionProxy and take ownership of the object
00385       // being passed
00386 
00387       delete fCollectionProxyInfo;;
00388       fCollectionProxyInfo = info;
00389    }
00390 
00391    void TGenericClassInfo::AdoptCollectionStreamerInfo(TCollectionProxyInfo *info)
00392    {
00393       // Set the info for the Collection Streamer and take ownership of the object
00394       // being passed
00395 
00396       delete fCollectionStreamerInfo;
00397       fCollectionStreamerInfo = info;
00398    }
00399 
00400    Short_t TGenericClassInfo::AdoptStreamer(TClassStreamer *streamer)
00401    {
00402       // Set a Streamer object.  The streamer object is now 'owned'
00403       // by the TGenericClassInfo.
00404 
00405       delete fStreamer; fStreamer = 0;
00406       if (fClass) {
00407          fClass->AdoptStreamer(streamer);
00408       } else {
00409          fStreamer = streamer;
00410       }
00411       return 0;
00412    }
00413 
00414    Short_t TGenericClassInfo::AdoptCollectionProxy(TVirtualCollectionProxy *collProxy)
00415    {
00416       // Set the CollectProxy object.  The CollectionProxy object is now 'owned'
00417       // by the TGenericClassInfo.
00418 
00419       delete fCollectionProxy; fCollectionProxy = 0;
00420       fCollectionProxy = collProxy;
00421       if (fClass && fCollectionProxy && !fClass->IsZombie()) {
00422          fClass->CopyCollectionProxy(*fCollectionProxy);
00423       }
00424       return 0;
00425    }
00426 
00427    void TGenericClassInfo::SetReadRawRules( const std::vector<TSchemaHelper>& rules )
00428    {
00429       // Set the list of Data Model Evolution read rules giving direct access to the TBuffer.
00430       fReadRawRules = rules;
00431    }
00432 
00433 
00434    void TGenericClassInfo::SetReadRules( const std::vector<TSchemaHelper>& rules )
00435    {
00436       // Set the list of Data Model Evolution regular read rules.
00437       fReadRules = rules;
00438    }
00439 
00440    Short_t TGenericClassInfo::SetStreamer(ClassStreamerFunc_t streamer)
00441    {
00442       // Set a External Streamer function.
00443 
00444       delete fStreamer; fStreamer = 0;
00445       if (fClass) {
00446          fClass->AdoptStreamer(new TClassStreamer(streamer));
00447       } else {
00448          fStreamer = new TClassStreamer(streamer);
00449       }
00450       return 0;
00451    }
00452 
00453    void TGenericClassInfo::SetStreamerFunc(ClassStreamerFunc_t streamer)
00454    {
00455       // Set a wrapper around the Streamer memger function.
00456 
00457       fStreamerFunc = streamer;
00458       if (fClass) fClass->SetStreamerFunc(streamer);
00459    }
00460 
00461    const char *TGenericClassInfo::GetDeclFileName() const
00462    {
00463       // Get the name of the declaring header file.
00464 
00465       return fDeclFileName;
00466    }
00467 
00468    Int_t TGenericClassInfo::GetDeclFileLine() const
00469    {
00470       // Get the declaring line number.
00471 
00472       return fDeclFileLine;
00473    }
00474 
00475    const char *TGenericClassInfo::GetImplFileName()
00476    {
00477       // Get the implementation filename.
00478 
00479       if (!fImplFileName) SetFromTemplate();
00480       return fImplFileName;
00481    }
00482 
00483    Int_t TGenericClassInfo::GetImplFileLine()
00484    {
00485       // Get the ClassImp line number.
00486 
00487       if (!fImplFileLine) SetFromTemplate();
00488       return fImplFileLine;
00489    }
00490 
00491    Int_t TGenericClassInfo::GetVersion() const
00492    {
00493       // Return the class version number.
00494 
00495       return fVersion;
00496    }
00497 
00498    TClass *TGenericClassInfo::IsA(const void *obj)
00499    {
00500       // Return the actual type of the object.
00501 
00502       return (*GetIsA())(obj);
00503    }
00504 
00505    TVirtualIsAProxy* TGenericClassInfo::GetIsA() const
00506    {
00507       // Return the IsA proxy.
00508 
00509       return fIsA;
00510    }
00511 
00512    void TGenericClassInfo::SetNew(NewFunc_t newFunc)
00513    {
00514       // Install a new wrapper around 'new'.
00515 
00516       fNew = newFunc;
00517       if (fClass) fClass->SetNew(fNew);
00518    }
00519 
00520    void TGenericClassInfo::SetNewArray(NewArrFunc_t newArrayFunc)
00521    {
00522       // Install a new wrapper around 'new []'.
00523 
00524       fNewArray = newArrayFunc;
00525       if (fClass) fClass->SetNewArray(fNewArray);
00526    }
00527 
00528    void TGenericClassInfo::SetDelete(DelFunc_t deleteFunc)
00529    {
00530       // Install a new wrapper around 'delete'.
00531 
00532       fDelete = deleteFunc;
00533       if (fClass) fClass->SetDelete(fDelete);
00534    }
00535 
00536    void TGenericClassInfo::SetDeleteArray(DelArrFunc_t deleteArrayFunc)
00537    {
00538       // Install a new wrapper around 'delete []'.
00539 
00540       fDeleteArray = deleteArrayFunc;
00541       if (fClass) fClass->SetDeleteArray(fDeleteArray);
00542    }
00543 
00544    void TGenericClassInfo::SetDestructor(DesFunc_t destructorFunc)
00545    {
00546       // Install a new wrapper around the destructor.
00547 
00548       fDestructor = destructorFunc;
00549       if (fClass) fClass->SetDestructor(fDestructor);
00550    }
00551 
00552    void TGenericClassInfo::SetDirectoryAutoAdd(DirAutoAdd_t func)
00553    {
00554       // Install a new wrapper around SetDirectoryAutoAdd.
00555 
00556       fDirAutoAdd = func;
00557       if (fClass) fClass->SetDirectoryAutoAdd(fDirAutoAdd);
00558    }
00559 
00560    NewFunc_t TGenericClassInfo::GetNew() const
00561    {
00562       // Get the wrapper around 'new'.
00563 
00564       return fNew;
00565    }
00566 
00567    NewArrFunc_t TGenericClassInfo::GetNewArray() const
00568    {
00569       // Get the wrapper around 'new []'.
00570 
00571       return fNewArray;
00572    }
00573 
00574    DelFunc_t TGenericClassInfo::GetDelete() const
00575    {
00576       // Get the wrapper around 'delete'.
00577 
00578       return fDelete;
00579    }
00580 
00581    DelArrFunc_t TGenericClassInfo::GetDeleteArray() const
00582    {
00583       // Get the wrapper around 'delete []'.
00584 
00585       return fDeleteArray;
00586    }
00587 
00588    DesFunc_t TGenericClassInfo::GetDestructor() const
00589    {
00590       // Get the wrapper around the destructor.
00591 
00592       return fDestructor;
00593    }
00594 
00595 
00596 }

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