1    	// @(#)root/base:$Id$
2    	// Author: Rene Brun   26/12/94
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_TObject
13   	#define ROOT_TObject
14   	
15   	
16   	//////////////////////////////////////////////////////////////////////////
17   	//                                                                      //
18   	// TObject                                                              //
19   	//                                                                      //
20   	// Mother of all ROOT objects.                                          //
21   	//                                                                      //
22   	// The TObject class provides default behaviour and protocol for all    //
23   	// objects in the ROOT system. It provides protocol for object I/O,     //
24   	// error handling, sorting, inspection, printing, drawing, etc.         //
25   	// Every object which inherits from TObject can be stored in the        //
26   	// ROOT collection classes.                                             //
27   	//                                                                      //
28   	//////////////////////////////////////////////////////////////////////////
29   	
30   	#ifndef ROOT_Rtypes
31   	#include "Rtypes.h"
32   	#endif
33   	#ifndef ROOT_TStorage
34   	#include "TStorage.h"
35   	#endif
36   	#ifndef ROOT_TVersionCheck
37   	#include "TVersionCheck.h"
38   	#endif
39   	#ifndef ROOT_Riosfwd
40   	#include "Riosfwd.h"
41   	#endif
42   	#include <stdarg.h>
43   	
44   	#ifdef WIN32
45   	#undef RemoveDirectory
46   	#endif
47   	
48   	class TList;
49   	class TBrowser;
50   	class TBuffer;
51   	class TObjArray;
52   	class TMethod;
53   	class TTimer;
54   	
55   	
56   	class TObject {
57   	
58   	private:
59   	   UInt_t         fUniqueID;   //object unique identifier
60   	   UInt_t         fBits;       //bit field status word
61   	
62   	   static Long_t  fgDtorOnly;    //object for which to call dtor only (i.e. no delete)
63   	   static Bool_t  fgObjectStat;  //if true keep track of objects in TObjectTable
64   	
65   	protected:
66   	   void MakeZombie() { fBits |= kZombie; }
67   	   virtual void DoError(int level, const char *location, const char *fmt, va_list va) const;
68   	
69   	public:
70   	   //----- Global bits (can be set for any object and should not be reused).
71   	   //----- Bits 0 - 13 are reserved as global bits. Bits 14 - 23 can be used
72   	   //----- in different class hierarchies (make sure there is no overlap in
73   	   //----- any given hierarchy).
74   	   enum EStatusBits {
75   	      kCanDelete        = BIT(0),   // if object in a list can be deleted
76   	      kMustCleanup      = BIT(3),   // if object destructor must call RecursiveRemove()
77   	      kObjInCanvas      = BIT(3),   // for backward compatibility only, use kMustCleanup
78   	      kIsReferenced     = BIT(4),   // if object is referenced by a TRef or TRefArray
79   	      kHasUUID          = BIT(5),   // if object has a TUUID (its fUniqueID=UUIDNumber)
80   	      kCannotPick       = BIT(6),   // if object in a pad cannot be picked
81   	      kNoContextMenu    = BIT(8),   // if object does not want context menu
82   	      kInvalidObject    = BIT(13)   // if object ctor succeeded but object should not be used
83   	   };
84   	
85   	   //----- Private bits, clients can only test but not change them
86   	   enum {
87   	      kIsOnHeap      = 0x01000000,    // object is on heap
88   	      kNotDeleted    = 0x02000000,    // object has not been deleted
89   	      kZombie        = 0x04000000,    // object ctor failed
90   	      kBitMask       = 0x00ffffff
91   	   };
92   	
93   	   //----- Write() options
94   	   enum {
95   	      kSingleKey     = BIT(0),        // write collection with single key
96   	      kOverwrite     = BIT(1),        // overwrite existing object with same name
97   	      kWriteDelete   = BIT(2)         // write object, then delete previous key with same name
98   	   };
99   	
100  	   TObject();
101  	   TObject(const TObject &object);
102  	   TObject &operator=(const TObject &rhs);
103  	   virtual ~TObject();
104  	
105  	   virtual void        AppendPad(Option_t *option="");
106  	   virtual void        Browse(TBrowser *b);
107  	   virtual const char *ClassName() const;
108  	   virtual void        Clear(Option_t * /*option*/ ="") { }
109  	   virtual TObject    *Clone(const char *newname="") const;
110  	   virtual Int_t       Compare(const TObject *obj) const;
111  	   virtual void        Copy(TObject &object) const;
112  	   virtual void        Delete(Option_t *option=""); // *MENU*
113  	   virtual Int_t       DistancetoPrimitive(Int_t px, Int_t py);
114  	   virtual void        Draw(Option_t *option="");
115  	   virtual void        DrawClass() const; // *MENU*
116  	   virtual TObject    *DrawClone(Option_t *option="") const; // *MENU*
117  	   virtual void        Dump() const; // *MENU*
118  	   virtual void        Execute(const char *method,  const char *params, Int_t *error=0);
119  	   virtual void        Execute(TMethod *method, TObjArray *params, Int_t *error=0);
120  	   virtual void        ExecuteEvent(Int_t event, Int_t px, Int_t py);
121  	   virtual TObject    *FindObject(const char *name) const;
122  	   virtual TObject    *FindObject(const TObject *obj) const;
123  	   virtual Option_t   *GetDrawOption() const;
124  	   virtual UInt_t      GetUniqueID() const;
125  	   virtual const char *GetName() const;
126  	   virtual const char *GetIconName() const;
127  	   virtual Option_t   *GetOption() const { return ""; }
128  	   virtual char       *GetObjectInfo(Int_t px, Int_t py) const;
129  	   virtual const char *GetTitle() const;
130  	   virtual Bool_t      HandleTimer(TTimer *timer);
131  	   virtual ULong_t     Hash() const;
132  	   virtual Bool_t      InheritsFrom(const char *classname) const;
133  	   virtual Bool_t      InheritsFrom(const TClass *cl) const;
134  	   virtual void        Inspect() const; // *MENU*
135  	   virtual Bool_t      IsFolder() const;
136  	   virtual Bool_t      IsEqual(const TObject *obj) const;
137  	   virtual Bool_t      IsSortable() const { return kFALSE; }
138  	           Bool_t      IsOnHeap() const { return TestBit(kIsOnHeap); }
139  	           Bool_t      IsZombie() const { return TestBit(kZombie); }
140  	   virtual Bool_t      Notify();
141  	   virtual void        ls(Option_t *option="") const;
142  	   virtual void        Paint(Option_t *option="");
143  	   virtual void        Pop();
144  	   virtual void        Print(Option_t *option="") const;
145  	   virtual Int_t       Read(const char *name);
146  	   virtual void        RecursiveRemove(TObject *obj);
147  	   virtual void        SaveAs(const char *filename="",Option_t *option="") const; // *MENU*
148  	   virtual void        SavePrimitive(ostream &out, Option_t *option = "");
149  	   virtual void        SetDrawOption(Option_t *option="");  // *MENU*
150  	   virtual void        SetUniqueID(UInt_t uid);
151  	   virtual void        UseCurrentStyle();
152  	   virtual Int_t       Write(const char *name=0, Int_t option=0, Int_t bufsize=0);
153  	   virtual Int_t       Write(const char *name=0, Int_t option=0, Int_t bufsize=0) const;
154  	
155  	   //----- operators
156  	   void    *operator new(size_t sz) { return TStorage::ObjectAlloc(sz); }
157  	   void    *operator new[](size_t sz) { return TStorage::ObjectAlloc(sz); }
158  	   void    *operator new(size_t sz, void *vp) { return TStorage::ObjectAlloc(sz, vp); }
159  	   void    *operator new[](size_t sz, void *vp) { return TStorage::ObjectAlloc(sz, vp); }
160  	   void     operator delete(void *ptr);
161  	   void     operator delete[](void *ptr);
162  	#ifdef R__PLACEMENTDELETE
163  	   void     operator delete(void *ptr, void *vp);
164  	   void     operator delete[](void *ptr, void *vp);
165  	#endif
166  	
167  	   //----- bit manipulation
168  	   void     SetBit(UInt_t f, Bool_t set);
169  	   void     SetBit(UInt_t f) { fBits |= f & kBitMask; }
(1) Event deref_parm: Directly dereferencing parameter "this".
170  	   void     ResetBit(UInt_t f) { fBits &= ~(f & kBitMask); }
171  	   Bool_t   TestBit(UInt_t f) const { return (Bool_t) ((fBits & f) != 0); }
172  	   Int_t    TestBits(UInt_t f) const { return (Int_t) (fBits & f); }
173  	   void     InvertBit(UInt_t f) { fBits ^= f & kBitMask; }
174  	
175  	   //---- error handling
176  	   virtual void     Info(const char *method, const char *msgfmt, ...) const
177  	#if defined(__GNUC__) && !defined(__CINT__)
178  	   __attribute__((format(printf, 3, 4)))   /* 1 is the this pointer */
179  	#endif
180  	   ;
181  	   virtual void     Warning(const char *method, const char *msgfmt, ...) const
182  	#if defined(__GNUC__) && !defined(__CINT__)
183  	   __attribute__((format(printf, 3, 4)))   /* 1 is the this pointer */
184  	#endif
185  	   ;
186  	   virtual void     Error(const char *method, const char *msgfmt, ...) const
187  	#if defined(__GNUC__) && !defined(__CINT__)
188  	   __attribute__((format(printf, 3, 4)))   /* 1 is the this pointer */
189  	#endif
190  	   ;
191  	   virtual void     SysError(const char *method, const char *msgfmt, ...) const
192  	#if defined(__GNUC__) && !defined(__CINT__)
193  	   __attribute__((format(printf, 3, 4)))   /* 1 is the this pointer */
194  	#endif
195  	   ;
196  	   virtual void     Fatal(const char *method, const char *msgfmt, ...) const
197  	#if defined(__GNUC__) && !defined(__CINT__)
198  	   __attribute__((format(printf, 3, 4)))   /* 1 is the this pointer */
199  	#endif
200  	   ;
201  	
202  	   void     AbstractMethod(const char *method) const;
203  	   void     MayNotUse(const char *method) const;
204  	   void     Obsolete(const char *method, const char *asOfVers, const char *removedFromVers) const;
205  	
206  	   //---- static functions
207  	   static Long_t    GetDtorOnly();
208  	   static void      SetDtorOnly(void *obj);
209  	   static Bool_t    GetObjectStat();
210  	   static void      SetObjectStat(Bool_t stat);
211  	
212  	   friend class TClonesArray; // needs to reset kNotDeleted in fBits
213  	
214  	   ClassDef(TObject,1)  //Basic ROOT object
215  	};
216  	
217  	// Global bits (can be set for any object and should not be reused).
218  	// Only here for backward compatibility reasons.
219  	// For detailed description see TObject::EStatusBits above.
220  	enum EObjBits {
221  	   kCanDelete        = TObject::kCanDelete,
222  	   kMustCleanup      = TObject::kMustCleanup,
223  	   kObjInCanvas      = TObject::kObjInCanvas,
224  	   kIsReferenced     = TObject::kIsReferenced,
225  	   kHasUUID          = TObject::kHasUUID,
226  	   kCannotPick       = TObject::kCannotPick,
227  	   kNoContextMenu    = TObject::kNoContextMenu,
228  	   kInvalidObject    = TObject::kInvalidObject
229  	};
230  	
231  	#ifndef ROOT_TBuffer
232  	#include "TBuffer.h"
233  	#endif
234  	
235  	#endif
236