// @(#)root/base:$Id$
// Author: Rene Brun   26/12/94

/*************************************************************************
 * 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_TObject
#define ROOT_TObject


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TObject                                                              //
//                                                                      //
// Mother of all ROOT objects.                                          //
//                                                                      //
// The TObject class provides default behaviour and protocol for all    //
// objects in the ROOT system. It provides protocol for object I/O,     //
// error handling, sorting, inspection, printing, drawing, etc.         //
// Every object which inherits from TObject can be stored in the        //
// ROOT collection classes.                                             //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif
#ifndef ROOT_TStorage
#include "TStorage.h"
#endif
#ifndef ROOT_TVersionCheck
#include "TVersionCheck.h"
#endif
#ifndef ROOT_Riosfwd
#include "Riosfwd.h"
#endif
#include <stdarg.h>

#ifdef WIN32
#undef RemoveDirectory
#endif

class TList;
class TBrowser;
class TBuffer;
class TObjArray;
class TMethod;
class TTimer;


class TObject {

private:
   UInt_t         fUniqueID;   //object unique identifier
   UInt_t         fBits;       //bit field status word

   static Long_t  fgDtorOnly;    //object for which to call dtor only (i.e. no delete)
   static Bool_t  fgObjectStat;  //if true keep track of objects in TObjectTable

protected:
   void MakeZombie() { fBits |= kZombie; }
   virtual void DoError(int level, const char *location, const char *fmt, va_list va) const;

public:
   //----- Global bits (can be set for any object and should not be reused).
   //----- Bits 0 - 13 are reserved as global bits. Bits 14 - 23 can be used
   //----- in different class hierarchies (make sure there is no overlap in
   //----- any given hierarchy).
   enum EStatusBits {
      kCanDelete        = BIT(0),   // if object in a list can be deleted
      kMustCleanup      = BIT(3),   // if object destructor must call RecursiveRemove()
      kObjInCanvas      = BIT(3),   // for backward compatibility only, use kMustCleanup
      kIsReferenced     = BIT(4),   // if object is referenced by a TRef or TRefArray
      kHasUUID          = BIT(5),   // if object has a TUUID (its fUniqueID=UUIDNumber)
      kCannotPick       = BIT(6),   // if object in a pad cannot be picked
      kNoContextMenu    = BIT(8),   // if object does not want context menu
      kInvalidObject    = BIT(13)   // if object ctor succeeded but object should not be used
   };

   //----- Private bits, clients can only test but not change them
   enum {
      kIsOnHeap      = 0x01000000,    // object is on heap
      kNotDeleted    = 0x02000000,    // object has not been deleted
      kZombie        = 0x04000000,    // object ctor failed
      kBitMask       = 0x00ffffff
   };

   //----- Write() options
   enum {
      kSingleKey     = BIT(0),        // write collection with single key
      kOverwrite     = BIT(1),        // overwrite existing object with same name
      kWriteDelete   = BIT(2)         // write object, then delete previous key with same name
   };

   TObject();
   TObject(const TObject &object);
   TObject &operator=(const TObject &rhs);
   virtual ~TObject();

   virtual void        AppendPad(Option_t *option="");
   virtual void        Browse(TBrowser *b);
   virtual const char *ClassName() const;
   virtual void        Clear(Option_t * /*option*/ ="") { }
   virtual TObject    *Clone(const char *newname="") const;
   virtual Int_t       Compare(const TObject *obj) const;
   virtual void        Copy(TObject &object) const;
   virtual void        Delete(Option_t *option=""); // *MENU*
   virtual Int_t       DistancetoPrimitive(Int_t px, Int_t py);
   virtual void        Draw(Option_t *option="");
   virtual void        DrawClass() const; // *MENU*
   virtual TObject    *DrawClone(Option_t *option="") const; // *MENU*
   virtual void        Dump() const; // *MENU*
   virtual void        Execute(const char *method,  const char *params, Int_t *error=0);
   virtual void        Execute(TMethod *method, TObjArray *params, Int_t *error=0);
   virtual void        ExecuteEvent(Int_t event, Int_t px, Int_t py);
   virtual TObject    *FindObject(const char *name) const;
   virtual TObject    *FindObject(const TObject *obj) const;
   virtual Option_t   *GetDrawOption() const;
   virtual UInt_t      GetUniqueID() const;
   virtual const char *GetName() const;
   virtual const char *GetIconName() const;
   virtual Option_t   *GetOption() const { return ""; }
   virtual char       *GetObjectInfo(Int_t px, Int_t py) const;
   virtual const char *GetTitle() const;
   virtual Bool_t      HandleTimer(TTimer *timer);
   virtual ULong_t     Hash() const;
   virtual Bool_t      InheritsFrom(const char *classname) const;
   virtual Bool_t      InheritsFrom(const TClass *cl) const;
   virtual void        Inspect() const; // *MENU*
   virtual Bool_t      IsFolder() const;
   virtual Bool_t      IsEqual(const TObject *obj) const;
   virtual Bool_t      IsSortable() const { return kFALSE; }
           Bool_t      IsOnHeap() const { return TestBit(kIsOnHeap); }
           Bool_t      IsZombie() const { return TestBit(kZombie); }
   virtual Bool_t      Notify();
   virtual void        ls(Option_t *option="") const;
   virtual void        Paint(Option_t *option="");
   virtual void        Pop();
   virtual void        Print(Option_t *option="") const;
   virtual Int_t       Read(const char *name);
   virtual void        RecursiveRemove(TObject *obj);
   virtual void        SaveAs(const char *filename="",Option_t *option="") const; // *MENU*
   virtual void        SavePrimitive(std::ostream &out, Option_t *option = "");
   virtual void        SetDrawOption(Option_t *option="");  // *MENU*
   virtual void        SetUniqueID(UInt_t uid);
   virtual void        UseCurrentStyle();
   virtual Int_t       Write(const char *name=0, Int_t option=0, Int_t bufsize=0);
   virtual Int_t       Write(const char *name=0, Int_t option=0, Int_t bufsize=0) const;

   //----- operators
   void    *operator new(size_t sz) { return TStorage::ObjectAlloc(sz); }
   void    *operator new[](size_t sz) { return TStorage::ObjectAlloc(sz); }
   void    *operator new(size_t sz, void *vp) { return TStorage::ObjectAlloc(sz, vp); }
   void    *operator new[](size_t sz, void *vp) { return TStorage::ObjectAlloc(sz, vp); }
   void     operator delete(void *ptr);
   void     operator delete[](void *ptr);
#ifdef R__PLACEMENTDELETE
   void     operator delete(void *ptr, void *vp);
   void     operator delete[](void *ptr, void *vp);
#endif

   //----- bit manipulation
   void     SetBit(UInt_t f, Bool_t set);
   void     SetBit(UInt_t f) { fBits |= f & kBitMask; }
   void     ResetBit(UInt_t f) { fBits &= ~(f & kBitMask); }
   Bool_t   TestBit(UInt_t f) const { return (Bool_t) ((fBits & f) != 0); }
   Int_t    TestBits(UInt_t f) const { return (Int_t) (fBits & f); }
   void     InvertBit(UInt_t f) { fBits ^= f & kBitMask; }

   //---- error handling
   virtual void     Info(const char *method, const char *msgfmt, ...) const
#if defined(__GNUC__) && !defined(__CINT__)
   __attribute__((format(printf, 3, 4)))   /* 1 is the this pointer */
#endif
   ;
   virtual void     Warning(const char *method, const char *msgfmt, ...) const
#if defined(__GNUC__) && !defined(__CINT__)
   __attribute__((format(printf, 3, 4)))   /* 1 is the this pointer */
#endif
   ;
   virtual void     Error(const char *method, const char *msgfmt, ...) const
#if defined(__GNUC__) && !defined(__CINT__)
   __attribute__((format(printf, 3, 4)))   /* 1 is the this pointer */
#endif
   ;
   virtual void     SysError(const char *method, const char *msgfmt, ...) const
#if defined(__GNUC__) && !defined(__CINT__)
   __attribute__((format(printf, 3, 4)))   /* 1 is the this pointer */
#endif
   ;
   virtual void     Fatal(const char *method, const char *msgfmt, ...) const
#if defined(__GNUC__) && !defined(__CINT__)
   __attribute__((format(printf, 3, 4)))   /* 1 is the this pointer */
#endif
   ;

   void     AbstractMethod(const char *method) const;
   void     MayNotUse(const char *method) const;
   void     Obsolete(const char *method, const char *asOfVers, const char *removedFromVers) const;

   //---- static functions
   static Long_t    GetDtorOnly();
   static void      SetDtorOnly(void *obj);
   static Bool_t    GetObjectStat();
   static void      SetObjectStat(Bool_t stat);

   friend class TClonesArray; // needs to reset kNotDeleted in fBits

   ClassDef(TObject,1)  //Basic ROOT object
};

// Global bits (can be set for any object and should not be reused).
// Only here for backward compatibility reasons.
// For detailed description see TObject::EStatusBits above.
enum EObjBits {
   kCanDelete        = TObject::kCanDelete,
   kMustCleanup      = TObject::kMustCleanup,
   kObjInCanvas      = TObject::kObjInCanvas,
   kIsReferenced     = TObject::kIsReferenced,
   kHasUUID          = TObject::kHasUUID,
   kCannotPick       = TObject::kCannotPick,
   kNoContextMenu    = TObject::kNoContextMenu,
   kInvalidObject    = TObject::kInvalidObject
};

#ifndef ROOT_TBuffer
#include "TBuffer.h"
#endif

#endif
 TObject.h:1
 TObject.h:2
 TObject.h:3
 TObject.h:4
 TObject.h:5
 TObject.h:6
 TObject.h:7
 TObject.h:8
 TObject.h:9
 TObject.h:10
 TObject.h:11
 TObject.h:12
 TObject.h:13
 TObject.h:14
 TObject.h:15
 TObject.h:16
 TObject.h:17
 TObject.h:18
 TObject.h:19
 TObject.h:20
 TObject.h:21
 TObject.h:22
 TObject.h:23
 TObject.h:24
 TObject.h:25
 TObject.h:26
 TObject.h:27
 TObject.h:28
 TObject.h:29
 TObject.h:30
 TObject.h:31
 TObject.h:32
 TObject.h:33
 TObject.h:34
 TObject.h:35
 TObject.h:36
 TObject.h:37
 TObject.h:38
 TObject.h:39
 TObject.h:40
 TObject.h:41
 TObject.h:42
 TObject.h:43
 TObject.h:44
 TObject.h:45
 TObject.h:46
 TObject.h:47
 TObject.h:48
 TObject.h:49
 TObject.h:50
 TObject.h:51
 TObject.h:52
 TObject.h:53
 TObject.h:54
 TObject.h:55
 TObject.h:56
 TObject.h:57
 TObject.h:58
 TObject.h:59
 TObject.h:60
 TObject.h:61
 TObject.h:62
 TObject.h:63
 TObject.h:64
 TObject.h:65
 TObject.h:66
 TObject.h:67
 TObject.h:68
 TObject.h:69
 TObject.h:70
 TObject.h:71
 TObject.h:72
 TObject.h:73
 TObject.h:74
 TObject.h:75
 TObject.h:76
 TObject.h:77
 TObject.h:78
 TObject.h:79
 TObject.h:80
 TObject.h:81
 TObject.h:82
 TObject.h:83
 TObject.h:84
 TObject.h:85
 TObject.h:86
 TObject.h:87
 TObject.h:88
 TObject.h:89
 TObject.h:90
 TObject.h:91
 TObject.h:92
 TObject.h:93
 TObject.h:94
 TObject.h:95
 TObject.h:96
 TObject.h:97
 TObject.h:98
 TObject.h:99
 TObject.h:100
 TObject.h:101
 TObject.h:102
 TObject.h:103
 TObject.h:104
 TObject.h:105
 TObject.h:106
 TObject.h:107
 TObject.h:108
 TObject.h:109
 TObject.h:110
 TObject.h:111
 TObject.h:112
 TObject.h:113
 TObject.h:114
 TObject.h:115
 TObject.h:116
 TObject.h:117
 TObject.h:118
 TObject.h:119
 TObject.h:120
 TObject.h:121
 TObject.h:122
 TObject.h:123
 TObject.h:124
 TObject.h:125
 TObject.h:126
 TObject.h:127
 TObject.h:128
 TObject.h:129
 TObject.h:130
 TObject.h:131
 TObject.h:132
 TObject.h:133
 TObject.h:134
 TObject.h:135
 TObject.h:136
 TObject.h:137
 TObject.h:138
 TObject.h:139
 TObject.h:140
 TObject.h:141
 TObject.h:142
 TObject.h:143
 TObject.h:144
 TObject.h:145
 TObject.h:146
 TObject.h:147
 TObject.h:148
 TObject.h:149
 TObject.h:150
 TObject.h:151
 TObject.h:152
 TObject.h:153
 TObject.h:154
 TObject.h:155
 TObject.h:156
 TObject.h:157
 TObject.h:158
 TObject.h:159
 TObject.h:160
 TObject.h:161
 TObject.h:162
 TObject.h:163
 TObject.h:164
 TObject.h:165
 TObject.h:166
 TObject.h:167
 TObject.h:168
 TObject.h:169
 TObject.h:170
 TObject.h:171
 TObject.h:172
 TObject.h:173
 TObject.h:174
 TObject.h:175
 TObject.h:176
 TObject.h:177
 TObject.h:178
 TObject.h:179
 TObject.h:180
 TObject.h:181
 TObject.h:182
 TObject.h:183
 TObject.h:184
 TObject.h:185
 TObject.h:186
 TObject.h:187
 TObject.h:188
 TObject.h:189
 TObject.h:190
 TObject.h:191
 TObject.h:192
 TObject.h:193
 TObject.h:194
 TObject.h:195
 TObject.h:196
 TObject.h:197
 TObject.h:198
 TObject.h:199
 TObject.h:200
 TObject.h:201
 TObject.h:202
 TObject.h:203
 TObject.h:204
 TObject.h:205
 TObject.h:206
 TObject.h:207
 TObject.h:208
 TObject.h:209
 TObject.h:210
 TObject.h:211
 TObject.h:212
 TObject.h:213
 TObject.h:214
 TObject.h:215
 TObject.h:216
 TObject.h:217
 TObject.h:218
 TObject.h:219
 TObject.h:220
 TObject.h:221
 TObject.h:222
 TObject.h:223
 TObject.h:224
 TObject.h:225
 TObject.h:226
 TObject.h:227
 TObject.h:228
 TObject.h:229
 TObject.h:230
 TObject.h:231
 TObject.h:232
 TObject.h:233
 TObject.h:234
 TObject.h:235