Logo ROOT   6.07/09
Reference Guide
TObject.h
Go to the documentation of this file.
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 #ifndef ROOT_Rtypes
17 #include "Rtypes.h"
18 #endif
19 #ifndef ROOT_TStorage
20 #include "TStorage.h"
21 #endif
22 #ifndef ROOT_TVersionCheck
23 #include "TVersionCheck.h"
24 #endif
25 #ifndef ROOT_Riosfwd
26 #include "Riosfwd.h"
27 #endif
28 
29 #include <stdarg.h>
30 #include <string>
31 
32 #ifdef WIN32
33 #undef RemoveDirectory
34 #endif
35 
36 class TList;
37 class TBrowser;
38 class TBuffer;
39 class TObjArray;
40 class TMethod;
41 class TTimer;
42 
43 
44 class TObject {
45 
46 private:
47  UInt_t fUniqueID; ///< object unique identifier
48  UInt_t fBits; ///< bit field status word
49 
50  static Long_t fgDtorOnly; ///< object for which to call dtor only (i.e. no delete)
51  static Bool_t fgObjectStat; ///< if true keep track of objects in TObjectTable
52 
53 protected:
54  void MakeZombie() { fBits |= kZombie; }
55  virtual void DoError(int level, const char *location, const char *fmt, va_list va) const;
56 
57 public:
58  //----- Global bits (can be set for any object and should not be reused).
59  //----- Bits 0 - 13 are reserved as global bits. Bits 14 - 23 can be used
60  //----- in different class hierarchies (make sure there is no overlap in
61  //----- any given hierarchy).
62  enum EStatusBits {
63  kCanDelete = BIT(0), ///< if object in a list can be deleted
64  kMustCleanup = BIT(3), ///< if object destructor must call RecursiveRemove()
65  kObjInCanvas = BIT(3), ///< for backward compatibility only, use kMustCleanup
66  kIsReferenced = BIT(4), ///< if object is referenced by a TRef or TRefArray
67  kHasUUID = BIT(5), ///< if object has a TUUID (its fUniqueID=UUIDNumber)
68  kCannotPick = BIT(6), ///< if object in a pad cannot be picked
69  kNoContextMenu = BIT(8), ///< if object does not want context menu
70  kInvalidObject = BIT(13) ///< if object ctor succeeded but object should not be used
71  };
72 
73  //----- Private bits, clients can only test but not change them
74  enum {
75  kIsOnHeap = 0x01000000, ///< object is on heap
76  kNotDeleted = 0x02000000, ///< object has not been deleted
77  kZombie = 0x04000000, ///< object ctor failed
78  kBitMask = 0x00ffffff
79  };
80 
81  //----- Write() options
82  enum {
83  kSingleKey = BIT(0), ///< write collection with single key
84  kOverwrite = BIT(1), ///< overwrite existing object with same name
85  kWriteDelete = BIT(2) ///< write object, then delete previous key with same name
86  };
87 
88  TObject();
89  TObject(const TObject &object);
90  TObject &operator=(const TObject &rhs);
91  virtual ~TObject();
92 
93  virtual void AppendPad(Option_t *option="");
94  virtual void Browse(TBrowser *b);
95  virtual const char *ClassName() const;
96  virtual void Clear(Option_t * /*option*/ ="") { }
97  virtual TObject *Clone(const char *newname="") const;
98  virtual Int_t Compare(const TObject *obj) const;
99  virtual void Copy(TObject &object) const;
100  virtual void Delete(Option_t *option=""); // *MENU*
101  virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
102  virtual void Draw(Option_t *option="");
103  virtual void DrawClass() const; // *MENU*
104  virtual TObject *DrawClone(Option_t *option="") const; // *MENU*
105  virtual void Dump() const; // *MENU*
106  virtual void Execute(const char *method, const char *params, Int_t *error=0);
107  virtual void Execute(TMethod *method, TObjArray *params, Int_t *error=0);
108  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
109  virtual TObject *FindObject(const char *name) const;
110  virtual TObject *FindObject(const TObject *obj) const;
111  virtual Option_t *GetDrawOption() const;
112  virtual UInt_t GetUniqueID() const;
113  virtual const char *GetName() const;
114  virtual const char *GetIconName() const;
115  virtual Option_t *GetOption() const { return ""; }
116  virtual char *GetObjectInfo(Int_t px, Int_t py) const;
117  virtual const char *GetTitle() const;
118  virtual Bool_t HandleTimer(TTimer *timer);
119  virtual ULong_t Hash() const;
120  virtual Bool_t InheritsFrom(const char *classname) const;
121  virtual Bool_t InheritsFrom(const TClass *cl) const;
122  virtual void Inspect() const; // *MENU*
123  virtual Bool_t IsFolder() const;
124  virtual Bool_t IsEqual(const TObject *obj) const;
125  virtual Bool_t IsSortable() const { return kFALSE; }
126  Bool_t IsOnHeap() const { return TestBit(kIsOnHeap); }
127  Bool_t IsZombie() const { return TestBit(kZombie); }
128  virtual Bool_t Notify();
129  virtual void ls(Option_t *option="") const;
130  virtual void Paint(Option_t *option="");
131  virtual void Pop();
132  virtual void Print(Option_t *option="") const;
133  virtual Int_t Read(const char *name);
134  virtual void RecursiveRemove(TObject *obj);
135  virtual void SaveAs(const char *filename="",Option_t *option="") const; // *MENU*
136  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
137  virtual void SetDrawOption(Option_t *option=""); // *MENU*
138  virtual void SetUniqueID(UInt_t uid);
139  virtual void UseCurrentStyle();
140  virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0);
141  virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0) const;
142 
143  //----- operators
144  void *operator new(size_t sz) { return TStorage::ObjectAlloc(sz); }
145  void *operator new[](size_t sz) { return TStorage::ObjectAllocArray(sz); }
146  void *operator new(size_t sz, void *vp) { return TStorage::ObjectAlloc(sz, vp); }
147  void *operator new[](size_t sz, void *vp) { return TStorage::ObjectAlloc(sz, vp); }
148  void operator delete(void *ptr);
149  void operator delete[](void *ptr);
150 #ifdef R__PLACEMENTDELETE
151  void operator delete(void *ptr, void *vp);
152  void operator delete[](void *ptr, void *vp);
153 #endif
154 
155  //----- bit manipulation
156  void SetBit(UInt_t f, Bool_t set);
157  void SetBit(UInt_t f) { fBits |= f & kBitMask; }
158  void ResetBit(UInt_t f) { fBits &= ~(f & kBitMask); }
159  Bool_t TestBit(UInt_t f) const { return (Bool_t) ((fBits & f) != 0); }
160  Int_t TestBits(UInt_t f) const { return (Int_t) (fBits & f); }
161  void InvertBit(UInt_t f) { fBits ^= f & kBitMask; }
162 
163  //---- error handling
164  virtual void Info(const char *method, const char *msgfmt, ...) const
165 #if defined(__GNUC__) && !defined(__CINT__)
166  __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */
167 #endif
168  ;
169  virtual void Warning(const char *method, const char *msgfmt, ...) const
170 #if defined(__GNUC__) && !defined(__CINT__)
171  __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */
172 #endif
173  ;
174  virtual void Error(const char *method, const char *msgfmt, ...) const
175 #if defined(__GNUC__) && !defined(__CINT__)
176  __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */
177 #endif
178  ;
179  virtual void SysError(const char *method, const char *msgfmt, ...) const
180 #if defined(__GNUC__) && !defined(__CINT__)
181  __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */
182 #endif
183  ;
184  virtual void Fatal(const char *method, const char *msgfmt, ...) const
185 #if defined(__GNUC__) && !defined(__CINT__)
186  __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */
187 #endif
188  ;
189 
190  void AbstractMethod(const char *method) const;
191  void MayNotUse(const char *method) const;
192  void Obsolete(const char *method, const char *asOfVers, const char *removedFromVers) const;
193 
194  //---- static functions
195  static Long_t GetDtorOnly();
196  static void SetDtorOnly(void *obj);
197  static Bool_t GetObjectStat();
198  static void SetObjectStat(Bool_t stat);
199 
200  friend class TClonesArray; // needs to reset kNotDeleted in fBits
201 
202  ClassDef(TObject,1) //Basic ROOT object
203 };
204 
205 // Global bits (can be set for any object and should not be reused).
206 // Only here for backward compatibility reasons.
207 // For detailed description see TObject::EStatusBits above.
208 enum EObjBits {
217 };
218 
219 namespace cling {
220  std::string printValue(TObject *val);
221 }
222 
223 #endif
virtual void Clear(Option_t *="")
Definition: TObject.h:96
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:830
object has not been deleted
Definition: TObject.h:76
UInt_t fUniqueID
object unique identifier
Definition: TObject.h:47
An array of TObjects.
Definition: TObjArray.h:39
object ctor failed
Definition: TObject.h:77
Bool_t IsOnHeap() const
Definition: TObject.h:126
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:488
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Computes distance from point (px,py) to the object.
Definition: TObject.cxx:246
virtual ULong_t Hash() const
Return hash value for this object.
Definition: TObject.cxx:478
const char Option_t
Definition: RtypesCore.h:62
void MayNotUse(const char *method) const
Use this method to signal that a method (defined in a base class) may not be called in a derived clas...
Definition: TObject.cxx:978
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:899
static void SetDtorOnly(void *obj)
Set destructor only flag.
Definition: TObject.cxx:1022
Int_t TestBits(UInt_t f) const
Definition: TObject.h:160
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
static void SetObjectStat(Bool_t stat)
Turn on/off tracking of objects in the TObjectTable.
Definition: TObject.cxx:1006
if object in a pad cannot be picked
Definition: TObject.h:68
Bool_t IsZombie() const
Definition: TObject.h:127
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition: TObject.cxx:179
static void * ObjectAlloc(size_t size)
Used to allocate a TObject on the heap (via TObject::operator new()).
Definition: TStorage.cxx:323
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects)...
Definition: TObject.cxx:518
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:255
virtual void SaveAs(const char *filename="", Option_t *option="") const
Save this object in the file specified by filename.
Definition: TObject.cxx:644
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this object in the current pad.
Definition: TObject.cxx:278
virtual void UseCurrentStyle()
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyl...
Definition: TObject.cxx:760
std::string printValue(TObject *val)
Print value overload.
Definition: TObject.cxx:1052
static std::string format(double x, double y, int digits, int width)
virtual Bool_t IsEqual(const TObject *obj) const
Default equal comparison (objects are equal if they have the same address in memory).
Definition: TObject.cxx:528
void InvertBit(UInt_t f)
Definition: TObject.h:161
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:739
static Long_t GetDtorOnly()
Return destructor only flag.
Definition: TObject.cxx:1014
overwrite existing object with same name
Definition: TObject.h:84
if object in a list can be deleted
Definition: TObject.h:63
virtual void RecursiveRemove(TObject *obj)
Recursively remove this object from a list.
Definition: TObject.cxx:617
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:165
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:953
object is on heap
Definition: TObject.h:75
static Long_t fgDtorOnly
object for which to call dtor only (i.e. no delete)
Definition: TObject.h:50
virtual void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
Definition: TObject.cxx:537
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:204
TStopwatch timer
Definition: pirndm.C:37
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:400
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Definition: TObject.cxx:551
virtual Bool_t HandleTimer(TTimer *timer)
Execute action in response of a timer timing out.
Definition: TObject.cxx:470
virtual void Inspect() const
Dump contents of this object in a graphics canvas.
Definition: TObject.cxx:509
virtual void Pop()
Pop on object drawn in a pad to the top of the display list.
Definition: TObject.cxx:573
virtual Option_t * GetOption() const
Definition: TObject.h:115
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition: TObject.cxx:607
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.cxx:103
virtual const char * GetIconName() const
Returns mime type name of object.
Definition: TObject.cxx:426
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
TObject()
TObject constructor.
Definition: TObject.cxx:65
virtual Bool_t IsSortable() const
Definition: TObject.h:125
for backward compatibility only, use kMustCleanup
Definition: TObject.h:65
virtual void Copy(TObject &object) const
Copy this to obj.
Definition: TObject.cxx:123
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:750
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:595
A doubly linked list.
Definition: TList.h:47
virtual void Delete(Option_t *option="")
Delete this object.
Definition: TObject.cxx:229
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
if object ctor succeeded but object should not be used
Definition: TObject.h:70
virtual void DrawClass() const
Draw class inheritance tree of the class to which this object belongs.
Definition: TObject.cxx:270
virtual void Execute(const char *method, const char *params, Int_t *error=0)
Execute method on this object with the given parameter string, e.g.
Definition: TObject.cxx:336
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:188
if object has a TUUID (its fUniqueID=UUIDNumber)
Definition: TObject.h:67
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:159
virtual void DoError(int level, const char *location, const char *fmt, va_list va) const
Interface to ErrorHandler (protected).
Definition: TObject.cxx:886
void AbstractMethod(const char *method) const
Use this method to implement an "abstract" method that you don&#39;t want to leave purely abstract...
Definition: TObject.cxx:967
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:57
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
void SetBit(UInt_t f)
Definition: TObject.h:157
write collection with single key
Definition: TObject.h:83
static Bool_t GetObjectStat()
Get status of object stat flag.
Definition: TObject.cxx:999
if object destructor must call RecursiveRemove()
Definition: TObject.h:64
UInt_t fBits
bit field status word
Definition: TObject.h:48
if object does not want context menu
Definition: TObject.h:69
long Long_t
Definition: RtypesCore.h:50
virtual void Paint(Option_t *option="")
This method must be overridden if a class wants to paint itself.
Definition: TObject.cxx:564
void Obsolete(const char *method, const char *asOfVers, const char *removedFromVers) const
Use this method to declare a method obsolete.
Definition: TObject.cxx:987
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
Definition: TObject.cxx:939
static Bool_t fgObjectStat
if true keep track of objects in TObjectTable
Definition: TObject.h:51
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Returns string containing info about the object at position (px,py).
Definition: TObject.cxx:445
double f(double x)
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to an event at (px,py).
Definition: TObject.cxx:370
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:416
EStatusBits
Definition: TObject.h:62
Print a TSeq at the prompt:
Definition: TDatime.h:114
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual ~TObject()
TObject destructor.
Definition: TObject.cxx:141
#define BIT(n)
Definition: Rtypes.h:120
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:434
Mother of all ROOT objects.
Definition: TObject.h:44
An array of clone (identical) objects.
Definition: TClonesArray.h:32
void MakeZombie()
Definition: TObject.h:54
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:40
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
if object is referenced by a TRef or TRefArray
Definition: TObject.h:66
virtual Int_t Compare(const TObject *obj) const
Compare abstract method.
Definition: TObject.cxx:219
static void * ObjectAllocArray(size_t size)
Used to allocate array of TObject on the heap (via TObject::operator new[]()).
Definition: TStorage.cxx:335
void ResetBit(UInt_t f)
Definition: TObject.h:158
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
Definition: TObject.cxx:722
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:460
write object, then delete previous key with same name
Definition: TObject.h:85
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:380
char name[80]
Definition: TGX11.cxx:109
virtual void Dump() const
Dump contents of object on stdout.
Definition: TObject.cxx:325
EObjBits
Definition: TObject.h:208
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:709
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:911