Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TObjectTable.h
Go to the documentation of this file.
1 // @(#)root/cont:$Id$
2 // Author: Fons Rademakers 11/08/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TObjectTable
13 #define ROOT_TObjectTable
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TObjectTable //
19 // //
20 // This class registers all instances of TObject and its derived //
21 // classes in a hash table. The Add() and Remove() members are called //
22 // from the TObject ctor and dtor, repectively. Using the Print() //
23 // member one can see all currently active objects in the system. //
24 // Using the runtime flag: Root.ObjectStat one can toggle this feature //
25 // on or off. //
26 // //
27 //////////////////////////////////////////////////////////////////////////
28 
29 
30 #include "TObject.h"
31 
32 class TClass;
33 
34 
35 class TObjectTable : public TObject {
36 
37 private:
38  TObject **fTable;
39  Int_t fSize;
40  Int_t fTally;
41 
42  Bool_t HighWaterMark();
43  void Expand(Int_t newsize);
44  Int_t FindElement(TObject *obj);
45  void FixCollisions(Int_t index);
46 
47 private:
48  TObjectTable(const TObjectTable&); // not implemented
49  TObjectTable& operator=(const TObjectTable&); // not implemented
50 
51 public:
52  TObjectTable(Int_t tableSize = 100);
53  ~TObjectTable();
54 
55  void Add(TObject *obj);
56  void *CheckPtrAndWarn(const char *msg, void *vp);
57  void Delete(Option_t *opt = "");
58  Int_t GetSize() const { return fSize; }
59  Int_t Instances() const { return fTally; }
60  void InstanceStatistics() const;
61  void Print(Option_t *option="") const;
62  Bool_t PtrIsValid(TObject *obj);
63  void Remove(TObject *obj);
64  void RemoveQuietly(TObject *obj);
65  void Statistics() { Print(); }
66  void Terminate();
67  void UpdateInstCount() const;
68 
69  static void AddObj(TObject *obj);
70 
71  ClassDef(TObjectTable,0) //Table of active objects
72 };
73 
74 
75 inline Bool_t TObjectTable::HighWaterMark()
76  { return (Bool_t) (fTally >= ((3*fSize)/4)); }
77 
78 inline Bool_t TObjectTable::PtrIsValid(TObject *op)
79  { return fTable[FindElement(op)] != 0; }
80 
81 
82 R__EXTERN TObjectTable *gObjectTable;
83 
84 #endif