ROOT logo
// @(#)root/cont:$Id$
// Author: Fons Rademakers   11/08/95

/*************************************************************************
 * 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.             *
 *************************************************************************/

#ifndef ROOT_TObjectTable
#define ROOT_TObjectTable


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TObjectTable                                                         //
//                                                                      //
// This class registers all instances of TObject and its derived        //
// classes in a hash table. The Add() and Remove() members are called   //
// from the TObject ctor and dtor, repectively. Using the Print()       //
// member one can see all currently active objects in the system.       //
// Using the runtime flag: Root.ObjectStat one can toggle this feature  //
// on or off.                                                           //
//                                                                      //
//////////////////////////////////////////////////////////////////////////


#ifndef ROOT_TObject
#include "TObject.h"
#endif

class TClass;


class TObjectTable : public TObject {

private:
   TObject  **fTable;
   Int_t      fSize;
   Int_t      fTally;

   Bool_t     HighWaterMark();
   void       Expand(Int_t newsize);
   Int_t      FindElement(TObject *obj);
   void       FixCollisions(Int_t index);

private:
   TObjectTable(const TObjectTable&);             // not implemented
   TObjectTable& operator=(const TObjectTable&);  // not implemented

public:
   TObjectTable(Int_t tableSize = 100);
   ~TObjectTable();

   void      Add(TObject *obj);
   void     *CheckPtrAndWarn(const char *msg, void *vp);
   void      Delete(Option_t *opt = "");
   Int_t     GetSize() const { return fSize; }
   Int_t     Instances() const { return fTally; }
   void      InstanceStatistics() const;
   void      Print(Option_t *option="") const;
   Bool_t    PtrIsValid(TObject *obj);
   void      Remove(TObject *obj);
   void      RemoveQuietly(TObject *obj);
   void      Statistics() { Print(); }
   void      Terminate();
   void      UpdateInstCount() const;

   static void AddObj(TObject *obj);

   ClassDef(TObjectTable,0)  //Table of active objects
};


inline Bool_t TObjectTable::HighWaterMark()
   { return (Bool_t) (fTally >= ((3*fSize)/4)); }

inline Bool_t TObjectTable::PtrIsValid(TObject *op)
   { return fTable[FindElement(op)] != 0; }


R__EXTERN TObjectTable *gObjectTable;

#endif
 TObjectTable.h:1
 TObjectTable.h:2
 TObjectTable.h:3
 TObjectTable.h:4
 TObjectTable.h:5
 TObjectTable.h:6
 TObjectTable.h:7
 TObjectTable.h:8
 TObjectTable.h:9
 TObjectTable.h:10
 TObjectTable.h:11
 TObjectTable.h:12
 TObjectTable.h:13
 TObjectTable.h:14
 TObjectTable.h:15
 TObjectTable.h:16
 TObjectTable.h:17
 TObjectTable.h:18
 TObjectTable.h:19
 TObjectTable.h:20
 TObjectTable.h:21
 TObjectTable.h:22
 TObjectTable.h:23
 TObjectTable.h:24
 TObjectTable.h:25
 TObjectTable.h:26
 TObjectTable.h:27
 TObjectTable.h:28
 TObjectTable.h:29
 TObjectTable.h:30
 TObjectTable.h:31
 TObjectTable.h:32
 TObjectTable.h:33
 TObjectTable.h:34
 TObjectTable.h:35
 TObjectTable.h:36
 TObjectTable.h:37
 TObjectTable.h:38
 TObjectTable.h:39
 TObjectTable.h:40
 TObjectTable.h:41
 TObjectTable.h:42
 TObjectTable.h:43
 TObjectTable.h:44
 TObjectTable.h:45
 TObjectTable.h:46
 TObjectTable.h:47
 TObjectTable.h:48
 TObjectTable.h:49
 TObjectTable.h:50
 TObjectTable.h:51
 TObjectTable.h:52
 TObjectTable.h:53
 TObjectTable.h:54
 TObjectTable.h:55
 TObjectTable.h:56
 TObjectTable.h:57
 TObjectTable.h:58
 TObjectTable.h:59
 TObjectTable.h:60
 TObjectTable.h:61
 TObjectTable.h:62
 TObjectTable.h:63
 TObjectTable.h:64
 TObjectTable.h:65
 TObjectTable.h:66
 TObjectTable.h:67
 TObjectTable.h:68
 TObjectTable.h:69
 TObjectTable.h:70
 TObjectTable.h:71
 TObjectTable.h:72
 TObjectTable.h:73
 TObjectTable.h:74
 TObjectTable.h:75
 TObjectTable.h:76
 TObjectTable.h:77
 TObjectTable.h:78
 TObjectTable.h:79
 TObjectTable.h:80
 TObjectTable.h:81
 TObjectTable.h:82
 TObjectTable.h:83
 TObjectTable.h:84
 TObjectTable.h:85
 TObjectTable.h:86