TClass.h

Go to the documentation of this file.
00001 // @(#)root/meta:$Id: TClass.h 37287 2010-12-05 04:14:11Z pcanal $
00002 // Author: Rene Brun   07/01/95
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_TClass
00013 #define ROOT_TClass
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TClass                                                               //
00019 //                                                                      //
00020 // Dictionary of a class.                                               //
00021 //                                                                      //
00022 //////////////////////////////////////////////////////////////////////////
00023 
00024 #ifndef ROOT_TDictionary
00025 #include "TDictionary.h"
00026 #endif
00027 #ifndef ROOT_TString
00028 #include "TString.h"
00029 #endif
00030 #ifndef ROOT_TObjArray
00031 #include "TObjArray.h"
00032 #endif
00033 #ifndef ROOT_TObjString
00034 #include "TObjString.h"
00035 #endif
00036 #include <map>
00037 #include <string>
00038 
00039 class TBaseClass;
00040 class TBrowser;
00041 class TDataMember;
00042 class TClassRef;
00043 class TMethod;
00044 class TRealData;
00045 class TCint;
00046 class TBuffer;
00047 class TVirtualStreamerInfo;
00048 class TVirtualCollectionProxy;
00049 class TMethodCall;
00050 class TVirtualIsAProxy;
00051 class TVirtualRefProxy;
00052 class THashTable;
00053 
00054 namespace ROOT {
00055    class TGenericClassInfo;
00056    class TCollectionProxyInfo;
00057    class TSchemaRuleSet;
00058 }
00059 
00060 namespace ROOT {
00061    class TMapTypeToTClass;
00062 }
00063 typedef ROOT::TMapTypeToTClass IdMap_t;
00064 
00065 class TClass : public TDictionary {
00066 
00067 friend class TCint;
00068 friend void ROOT::ResetClassVersion(TClass*, const char*, Short_t);
00069 friend class ROOT::TGenericClassInfo;
00070 
00071 public:
00072    // TClass status bits
00073    enum { kClassSaved  = BIT(12), kIgnoreTObjectStreamer = BIT(15), 
00074           kUnloaded    = BIT(16), kIsTObject = BIT(17),
00075           kIsForeign   = BIT(18), kIsEmulation = BIT(19),
00076           kStartWithTObject = BIT(20),  // see comments for IsStartingWithTObject()
00077           kWarned      = BIT(21),
00078           kHasNameMapNode = BIT(22)
00079    };
00080    enum ENewType { kRealNew = 0, kClassNew, kDummyNew };
00081 
00082 private:
00083 
00084    mutable TObjArray *fStreamerInfo;    //Array of TVirtualStreamerInfo
00085    mutable std::map<std::string, TObjArray*> *fConversionStreamerInfo; //Array of the streamer infos derived from another class.
00086    TList             *fRealData;        //linked list for persistent members including base classes
00087    TList             *fBase;            //linked list for base classes
00088    TList             *fData;            //linked list for data members
00089    TList             *fMethod;          //linked list for methods
00090    TList             *fAllPubData;      //all public data members (including from base classes)
00091    TList             *fAllPubMethod;    //all public methods (including from base classes)
00092    mutable TList     *fClassMenuList;   //list of class menu items
00093 
00094    const char        *fDeclFileName;    //name of class declaration file
00095    const char        *fImplFileName;    //name of class implementation file
00096    Short_t            fDeclFileLine;    //line of class declaration
00097    Short_t            fImplFileLine;    //line of class implementation
00098    UInt_t             fInstanceCount;   //number of instances of this class
00099    UInt_t             fOnHeap;          //number of instances on heap
00100    mutable UInt_t     fCheckSum;        //checksum of data members and base classes
00101    TVirtualCollectionProxy *fCollectionProxy; //Collection interface
00102    Version_t          fClassVersion;    //Class version Identifier
00103    ClassInfo_t       *fClassInfo;       //pointer to CINT class info class
00104    TString            fContextMenuTitle;//context menu title
00105    const type_info   *fTypeInfo;        //pointer to the C++ type information.
00106    ShowMembersFunc_t  fShowMembers;     //pointer to the class's ShowMembers function
00107    mutable void      *fInterShowMembers;//Interpreter call setup for ShowMembers
00108    TClassStreamer    *fStreamer;        //pointer to streamer function
00109    TString            fSharedLibs;      //shared libraries containing class code
00110 
00111    TVirtualIsAProxy  *fIsA;             //!pointer to the class's IsA proxy.
00112    IsAGlobalFunc_t    fGlobalIsA;       //pointer to a global IsA function.
00113    mutable TMethodCall *fIsAMethod;       //!saved info to call a IsA member function
00114 
00115    ROOT::NewFunc_t     fNew;            //pointer to a function newing one object.
00116    ROOT::NewArrFunc_t  fNewArray;       //pointer to a function newing an array of objects.
00117    ROOT::DelFunc_t     fDelete;         //pointer to a function deleting one object.
00118    ROOT::DelArrFunc_t  fDeleteArray;    //pointer to a function deleting an array of objects.
00119    ROOT::DesFunc_t     fDestructor;     //pointer to a function call an object's destructor.
00120    ROOT::DirAutoAdd_t  fDirAutoAdd;     //pointer which implements the Directory Auto Add feature for this class.']'
00121    ClassStreamerFunc_t fStreamerFunc;   //Wrapper around this class custom Streamer member function.
00122    Int_t               fSizeof;         //Sizeof the class.
00123 
00124    mutable Long_t     fProperty;        //!Property
00125    mutable Bool_t     fVersionUsed;     //!Indicates whether GetClassVersion has been called
00126 
00127    mutable Bool_t     fIsOffsetStreamerSet; //!saved remember if fOffsetStreamer has been set.
00128    mutable Long_t     fOffsetStreamer;  //!saved info to call Streamer
00129    Int_t              fStreamerType;    //!cached of the streaming method to use
00130    mutable TVirtualStreamerInfo     *fCurrentInfo;     //!cached current streamer info.
00131    TClassRef         *fRefStart;        //!List of references to this object
00132    TVirtualRefProxy  *fRefProxy;        //!Pointer to reference proxy if this class represents a reference
00133    ROOT::TSchemaRuleSet *fSchemaRules;  //! Schema evolution rules
00134 
00135    typedef void (TClass::*StreamerImpl_t)(void *obj, TBuffer &b, const TClass *onfile_class) const;
00136    mutable StreamerImpl_t fStreamerImpl;//! Pointer to the function implementing the right streaming behavior for the class represented by this object.
00137 
00138    TMethod           *GetClassMethod(Long_t faddr);
00139    TMethod           *GetClassMethod(const char *name, const char *signature);
00140    Int_t              GetBaseClassOffsetRecurse(const TClass *base);
00141    void Init(const char *name, Version_t cversion, const type_info *info,
00142              TVirtualIsAProxy *isa, ShowMembersFunc_t showmember,
00143              const char *dfil, const char *ifil,
00144              Int_t dl, Int_t il,
00145              Bool_t silent);
00146    void ForceReload (TClass* oldcl);
00147 
00148    void               SetClassVersion(Version_t version);
00149    void               SetClassSize(Int_t sizof) { fSizeof = sizof; }
00150    
00151    // Various implementation for TClass::Stramer
00152    void StreamerExternal(void *object, TBuffer &b, const TClass *onfile_class) const;
00153    void StreamerTObject(void *object, TBuffer &b, const TClass *onfile_class) const;
00154    void StreamerTObjectInitialized(void *object, TBuffer &b, const TClass *onfile_class) const;
00155    void StreamerTObjectEmulated(void *object, TBuffer &b, const TClass *onfile_class) const;
00156    void StreamerInstrumented(void *object, TBuffer &b, const TClass *onfile_class) const;
00157    void StreamerStreamerInfo(void *object, TBuffer &b, const TClass *onfile_class) const;
00158    void StreamerDefault(void *object, TBuffer &b, const TClass *onfile_class) const;
00159    
00160    static IdMap_t    *fgIdMap;          //Map from typeid to TClass pointer
00161    static ENewType    fgCallingNew;     //Intent of why/how TClass::New() is called
00162    static Int_t       fgClassCount;     //provides unique id for a each class
00163                                         //stored in TObject::fUniqueID
00164    // Internal status bits
00165    enum { kLoading = BIT(14) };
00166    // Internal streamer type.
00167    enum {kDefault=0, kEmulated=1, kTObject=2, kInstrumented=4, kForeign=8, kExternal=16};
00168 
00169    // When a new class is created, we need to be able to find
00170    // if there are any existing classes that have the same name
00171    // after any typedefs are expanded.  (This only really affects
00172    // template arguments.)  To avoid having to search through all classes
00173    // in that case, we keep a hash table mapping from the fully
00174    // typedef-expanded names to the original class names.
00175    // An entry is made in the table only if they are actually different.
00176    //
00177    // In these objects, the TObjString base holds the typedef-expanded
00178    // name (the hash key), and fOrigName holds the original class name
00179    // (the value to which the key maps).
00180    //
00181    class TNameMapNode
00182      : public TObjString
00183    {
00184    public:
00185      TNameMapNode (const char* typedf, const char* orig);
00186      TString fOrigName;
00187    };
00188 
00189    // These are the above-referenced hash tables.  (The pointers are null
00190    // if no entries have been made.)  There are actually two variants.
00191    // In the first, the typedef names are resolved with
00192    // TClassEdit::ResolveTypedef; in the second, the class names
00193    // are first massaged with TClassEdit::ShortType with kDropStlDefault.
00194    // (??? Are the two distinct tables really needed?)
00195    static THashTable* fgClassTypedefHash;
00196    static THashTable* fgClassShortTypedefHash;
00197 
00198 private:
00199    TClass(const TClass& tc);
00200    TClass& operator=(const TClass&);   
00201 
00202 protected:
00203    TVirtualStreamerInfo     *FindStreamerInfo(TObjArray* arr, UInt_t checksum) const;
00204    static THashTable        *GetClassShortTypedefHash();
00205 
00206 public:
00207    TClass();
00208    TClass(const char *name, Bool_t silent = kFALSE);
00209    TClass(const char *name, Version_t cversion,
00210           const char *dfil = 0, const char *ifil = 0,
00211           Int_t dl = 0, Int_t il = 0, Bool_t silent = kFALSE);
00212    TClass(const char *name, Version_t cversion,
00213           const type_info &info, TVirtualIsAProxy *isa,
00214           ShowMembersFunc_t showmember,
00215           const char *dfil, const char *ifil,
00216           Int_t dl, Int_t il, Bool_t silent = kFALSE);
00217    virtual           ~TClass();
00218 
00219    void               AddInstance(Bool_t heap = kFALSE) { fInstanceCount++; if (heap) fOnHeap++; }
00220    void               AddImplFile(const char *filename, int line);
00221    void               AddRef(TClassRef *ref);
00222    static Bool_t      AddRule(const char *rule);
00223    static Int_t       ReadRules(const char *filename);
00224    static Int_t       ReadRules();
00225    void               AdoptSchemaRules( ROOT::TSchemaRuleSet *rules );
00226    virtual void       Browse(TBrowser *b);
00227    void               BuildRealData(void *pointer=0, Bool_t isTransient = kFALSE);
00228    void               BuildEmulatedRealData(const char *name, Long_t offset, TClass *cl);
00229    void               CalculateStreamerOffset() const;
00230    Bool_t             CallShowMembers(void* obj, TMemberInspector &insp,
00231                                       Int_t isATObject = -1) const;
00232    Bool_t             CanSplit() const;
00233    Bool_t             CanIgnoreTObjectStreamer() { return TestBit(kIgnoreTObjectStreamer);}
00234    TObject           *Clone(const char *newname="") const;
00235    void               CopyCollectionProxy(const TVirtualCollectionProxy&);
00236    void               Draw(Option_t *option="");
00237    void               Dump() const { TDictionary::Dump(); }
00238    void               Dump(void *obj) const;
00239    char              *EscapeChars(const char *text) const;
00240    TVirtualStreamerInfo     *FindStreamerInfo(UInt_t checksum) const;
00241    TVirtualStreamerInfo     *GetConversionStreamerInfo( const char* onfile_classname, Int_t version ) const;
00242    TVirtualStreamerInfo     *FindConversionStreamerInfo( const char* onfile_classname, UInt_t checksum ) const;
00243    TVirtualStreamerInfo     *GetConversionStreamerInfo( const TClass* onfile_cl, Int_t version ) const;
00244    TVirtualStreamerInfo     *FindConversionStreamerInfo( const TClass* onfile_cl, UInt_t checksum ) const;
00245    Bool_t             HasDefaultConstructor() const;
00246    UInt_t             GetCheckSum(UInt_t code=0) const;
00247    TVirtualCollectionProxy *GetCollectionProxy() const;
00248    TVirtualIsAProxy  *GetIsAProxy() const;
00249    Version_t          GetClassVersion() const { fVersionUsed = kTRUE; return fClassVersion; }
00250    TDataMember       *GetDataMember(const char *datamember) const;
00251    Long_t              GetDataMemberOffset(const char *membername) const;
00252    const char        *GetDeclFileName() const { return fDeclFileName; }
00253    Short_t            GetDeclFileLine() const { return fDeclFileLine; }
00254    ROOT::DelFunc_t    GetDelete() const;
00255    ROOT::DesFunc_t    GetDestructor() const;
00256    ROOT::DelArrFunc_t GetDeleteArray() const;
00257    ClassInfo_t       *GetClassInfo() const { return fClassInfo; }
00258    const char        *GetContextMenuTitle() const { return fContextMenuTitle; }
00259    TVirtualStreamerInfo     *GetCurrentStreamerInfo() {
00260       if (fCurrentInfo) return fCurrentInfo;
00261       else return (fCurrentInfo=(TVirtualStreamerInfo*)(fStreamerInfo->At(fClassVersion)));
00262    }
00263    TList             *GetListOfDataMembers();
00264    TList             *GetListOfBases();
00265    TList             *GetListOfMethods();
00266    TList             *GetListOfRealData() const { return fRealData; }
00267    TList             *GetListOfAllPublicMethods();
00268    TList             *GetListOfAllPublicDataMembers();
00269    const char        *GetImplFileName() const { return fImplFileName; }
00270    Short_t            GetImplFileLine() const { return fImplFileLine; }
00271    TClass            *GetActualClass(const void *object) const;
00272    TClass            *GetBaseClass(const char *classname);
00273    TClass            *GetBaseClass(const TClass *base);
00274    Int_t              GetBaseClassOffset(const TClass *base);
00275    TClass            *GetBaseDataMember(const char *datamember);
00276    ROOT::DirAutoAdd_t GetDirectoryAutoAdd() const;
00277    UInt_t             GetInstanceCount() const { return fInstanceCount; }
00278    UInt_t             GetHeapInstanceCount() const { return fOnHeap; }
00279    void               GetMenuItems(TList *listitems);
00280    TList             *GetMenuList() const;
00281    TMethod           *GetMethod(const char *method, const char *params);
00282    TMethod           *GetMethodWithPrototype(const char *method, const char *proto);
00283    TMethod           *GetMethodAny(const char *method);
00284    TMethod           *GetMethodAllAny(const char *method);
00285    Int_t              GetNdata();
00286    ROOT::NewFunc_t    GetNew() const;
00287    ROOT::NewArrFunc_t GetNewArray() const;
00288    Int_t              GetNmethods();
00289    TRealData         *GetRealData(const char *name) const;
00290    TVirtualRefProxy  *GetReferenceProxy()  const   {  return fRefProxy; }
00291    const ROOT::TSchemaRuleSet *GetSchemaRules() const;
00292    ROOT::TSchemaRuleSet *GetSchemaRules(Bool_t create = kFALSE);
00293    const char        *GetSharedLibs();
00294    ShowMembersFunc_t  GetShowMembersWrapper() const { return fShowMembers; }
00295    TClassStreamer    *GetStreamer() const; 
00296    ClassStreamerFunc_t GetStreamerFunc() const;
00297    TObjArray         *GetStreamerInfos() const { return fStreamerInfo; }
00298    TVirtualStreamerInfo     *GetStreamerInfo(Int_t version=0) const;
00299    const type_info   *GetTypeInfo() const { return fTypeInfo; };
00300    void               IgnoreTObjectStreamer(Bool_t ignore=kTRUE);
00301    Bool_t             InheritsFrom(const char *cl) const;
00302    Bool_t             InheritsFrom(const TClass *cl) const;
00303    void               InterpretedShowMembers(void* obj, TMemberInspector &insp);
00304    Bool_t             IsFolder() const { return kTRUE; }
00305    Bool_t             IsLoaded() const;
00306    Bool_t             IsForeign() const;
00307    Bool_t             IsStartingWithTObject() const;
00308    Bool_t             IsTObject() const;
00309    void               ls(Option_t *opt="") const;
00310    void               MakeCustomMenuList();
00311    void               Move(void *arenaFrom, void *arenaTo) const;
00312    void              *New(ENewType defConstructor = kClassNew) const;
00313    void              *New(void *arena, ENewType defConstructor = kClassNew) const;
00314    void              *NewArray(Long_t nElements, ENewType defConstructor = kClassNew) const;
00315    void              *NewArray(Long_t nElements, void *arena, ENewType defConstructor = kClassNew) const;
00316    virtual void       PostLoadCheck();
00317    Long_t             Property() const;
00318    Int_t              ReadBuffer(TBuffer &b, void *pointer, Int_t version, UInt_t start, UInt_t count);
00319    Int_t              ReadBuffer(TBuffer &b, void *pointer);
00320    void               RemoveRef(TClassRef *ref); 
00321    void               ReplaceWith(TClass *newcl, Bool_t recurse = kTRUE) const;
00322    void               ResetClassInfo(Long_t tagnum);
00323    void               ResetInstanceCount() { fInstanceCount = fOnHeap = 0; }
00324    void               ResetMenuList();
00325    Int_t              Size() const;
00326    void               SetCollectionProxy(const ROOT::TCollectionProxyInfo&);
00327    void               SetContextMenuTitle(const char *title);
00328    void               SetCurrentStreamerInfo(TVirtualStreamerInfo *info);
00329    void               SetGlobalIsA(IsAGlobalFunc_t);
00330    void               SetDeclFile(const char *name, int line) { fDeclFileName = name; fDeclFileLine = line; }
00331    void               SetDelete(ROOT::DelFunc_t deleteFunc);
00332    void               SetDeleteArray(ROOT::DelArrFunc_t deleteArrayFunc);
00333    void               SetDirectoryAutoAdd(ROOT::DirAutoAdd_t dirAutoAddFunc);
00334    void               SetDestructor(ROOT::DesFunc_t destructorFunc);
00335    void               SetImplFileName(const char *implFileName) { fImplFileName = implFileName; }
00336    void               SetNew(ROOT::NewFunc_t newFunc);
00337    void               SetNewArray(ROOT::NewArrFunc_t newArrayFunc);
00338    TVirtualStreamerInfo     *SetStreamerInfo(Int_t version, const char *info="");
00339    void               SetUnloaded();
00340    Int_t              WriteBuffer(TBuffer &b, void *pointer, const char *info="");
00341 
00342    void               AdoptReferenceProxy(TVirtualRefProxy* proxy);
00343    void               AdoptStreamer(TClassStreamer *strm);
00344    void               AdoptMemberStreamer(const char *name, TMemberStreamer *strm);
00345    void               SetMemberStreamer(const char *name, MemberStreamerFunc_t strm);
00346    void               SetStreamerFunc(ClassStreamerFunc_t strm);
00347 
00348    // Function to retrieve the TClass object and dictionary function
00349    static void           AddClass(TClass *cl);
00350    static void           RemoveClass(TClass *cl);
00351    static TClass        *GetClass(const char *name, Bool_t load = kTRUE, Bool_t silent = kFALSE);
00352    static TClass        *GetClass(const type_info &typeinfo, Bool_t load = kTRUE, Bool_t silent = kFALSE);
00353    static VoidFuncPtr_t  GetDict (const char *cname);
00354    static VoidFuncPtr_t  GetDict (const type_info &info);
00355 
00356    static Int_t       AutoBrowse(TObject *obj, TBrowser *browser);
00357    static ENewType    IsCallingNew();
00358    static TClass     *Load(TBuffer &b);
00359    void               Store(TBuffer &b) const;
00360 
00361    // Pseudo-method apply to the 'obj'. In particular those are used to
00362    // implement TObject like methods for non-TObject classes
00363 
00364    Int_t              Browse(void *obj, TBrowser *b) const;
00365    void               DeleteArray(void *ary, Bool_t dtorOnly = kFALSE);
00366    void               Destructor(void *obj, Bool_t dtorOnly = kFALSE);
00367    void              *DynamicCast(const TClass *base, void *obj, Bool_t up = kTRUE);
00368    Bool_t             IsFolder(void *obj) const;
00369    inline void        Streamer(void *obj, TBuffer &b, const TClass *onfile_class = 0) const
00370    {
00371       // Inline for performance, skipping one function call.
00372        (this->*fStreamerImpl)(obj,b,onfile_class);
00373    }
00374 
00375    ClassDef(TClass,0)  //Dictionary containing class information
00376 };
00377 
00378 namespace ROOT {
00379 
00380    #ifndef R__NO_CLASS_TEMPLATE_SPECIALIZATION
00381       template <typename T> struct IsPointer { enum { kVal = 0 }; };
00382       template <typename T> struct IsPointer<T*> { enum { kVal = 1 }; };
00383    #else
00384       template <typename T> Bool_t IsPointer(const T* /* dummy */) { return false; };
00385       template <typename T> Bool_t IsPointer(const T** /* dummy */) { return true; };
00386    #endif
00387 
00388    template <typename T> TClass* GetClass(      T* /* dummy */)        { return TClass::GetClass(typeid(T)); }
00389    template <typename T> TClass* GetClass(const T* /* dummy */)        { return TClass::GetClass(typeid(T)); }
00390 
00391    #ifndef R__NO_CLASS_TEMPLATE_SPECIALIZATION
00392       // This can only be used when the template overload resolution can distringuish between
00393       // T* and T**
00394       template <typename T> TClass* GetClass(      T**       /* dummy */) { return GetClass((T*)0); }
00395       template <typename T> TClass* GetClass(const T**       /* dummy */) { return GetClass((T*)0); }
00396       template <typename T> TClass* GetClass(      T* const* /* dummy */) { return GetClass((T*)0); }
00397       template <typename T> TClass* GetClass(const T* const* /* dummy */) { return GetClass((T*)0); }
00398    #endif
00399 
00400    extern TClass *CreateClass(const char *cname, Version_t id,
00401                               const char *dfil, const char *ifil,
00402                               Int_t dl, Int_t il);
00403 }
00404 
00405 #endif // ROOT_TClass

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