Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:18

0001 // @(#)root/cont:$Id$
0002 // Author: Fons Rademakers   11/08/95
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TObjectTable
0013 #define ROOT_TObjectTable
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TObjectTable                                                         //
0019 //                                                                      //
0020 // This class registers all instances of TObject and its derived        //
0021 // classes in a hash table. The Add() and Remove() members are called   //
0022 // from the TObject ctor and dtor, repectively. Using the Print()       //
0023 // member one can see all currently active objects in the system.       //
0024 // Using the runtime flag: Root.ObjectStat one can toggle this feature  //
0025 // on or off.                                                           //
0026 //                                                                      //
0027 //////////////////////////////////////////////////////////////////////////
0028 
0029 
0030 #include "TObject.h"
0031 
0032 class TClass;
0033 
0034 
0035 class TObjectTable : public TObject {
0036 
0037 private:
0038    TObject  **fTable;
0039    Int_t      fSize;
0040    Int_t      fTally;
0041 
0042    Bool_t     HighWaterMark();
0043    void       Expand(Int_t newsize);
0044    Int_t      FindElement(TObject *obj);
0045    void       FixCollisions(Int_t index);
0046 
0047 private:
0048    TObjectTable(const TObjectTable&) = delete;
0049    TObjectTable& operator=(const TObjectTable&) = delete;
0050 
0051 public:
0052    TObjectTable(Int_t tableSize = 100);
0053    ~TObjectTable();
0054 
0055    void      Add(TObject *obj);
0056    void     *CheckPtrAndWarn(const char *msg, void *vp);
0057    void      Delete(Option_t *opt = "") override;
0058    Int_t     GetSize() const { return fSize; }
0059    Int_t     Instances() const { return fTally; }
0060    void      InstanceStatistics() const;
0061    void      Print(Option_t *option="") const override;
0062    Bool_t    PtrIsValid(TObject *obj);
0063    void      Remove(TObject *obj);
0064    void      RemoveQuietly(TObject *obj);
0065    void      Statistics() { Print(); }
0066    void      Terminate();
0067    void      UpdateInstCount() const;
0068 
0069    static void AddObj(TObject *obj);
0070 
0071    ClassDefOverride(TObjectTable,0)  //Table of active objects
0072 };
0073 
0074 
0075 inline Bool_t TObjectTable::HighWaterMark()
0076    { return (Bool_t) (fTally >= ((3*fSize)/4)); }
0077 
0078 inline Bool_t TObjectTable::PtrIsValid(TObject *op)
0079    { return fTable[FindElement(op)] != nullptr; }
0080 
0081 
0082 R__EXTERN TObjectTable *gObjectTable;
0083 
0084 #endif