TDirectory.h

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TDirectory.h 27658 2009-02-28 05:34:57Z pcanal $
00002 // Author: Rene Brun   28/11/94
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TDirectory
00013 #define ROOT_TDirectory
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TDirectory                                                           //
00019 //                                                                      //
00020 // Describe directory structure in memory.                              //
00021 //                                                                      //
00022 //////////////////////////////////////////////////////////////////////////
00023 
00024 #ifndef ROOT_TNamed
00025 #include "TNamed.h"
00026 #endif
00027 #ifndef ROOT_TList
00028 #include "TList.h"
00029 #endif
00030 #ifndef ROOT_TDatime
00031 #include "TDatime.h"
00032 #endif
00033 #ifndef ROOT_TUUID
00034 #include "TUUID.h"
00035 #endif
00036 
00037 class TBrowser;
00038 class TKey;
00039 class TFile;
00040 
00041 R__EXTERN TDirectory *gDirectory;
00042 
00043 class TDirectory : public TNamed {
00044 public:
00045    /** @class Context
00046      *
00047      *  Small helper to keep current directory context.
00048      *  Automatically reverts to "old" directory
00049      */
00050    class TContext  {
00051    private:
00052       TDirectory *fDirectory;   //! Pointer to the previous current directory.
00053       TContext   *fPrevious;    //! Pointer to the next TContext in the implied list of context pointing to fPrevious.
00054       TContext   *fNext;        //! Pointer to the next TContext in the implied list of context pointing to fPrevious.
00055       TContext(TContext&);
00056       TContext& operator=(TContext&);
00057       void CdNull();
00058       friend class TDirectory;
00059    public:
00060       TContext(TDirectory* previous, TDirectory* newCurrent)
00061          : fDirectory(previous),fPrevious(0),fNext(0)
00062       {
00063          // Store the current directory so we can restore it
00064          // later and cd to the new directory.
00065          if ( fDirectory ) fDirectory->RegisterContext(this);
00066          if ( newCurrent ) newCurrent->cd();
00067       }
00068       TContext(TDirectory* newCurrent) : fDirectory(gDirectory),fPrevious(0),fNext(0)
00069       {
00070          // Store the current directory so we can restore it
00071          // later and cd to the new directory.
00072          if ( fDirectory ) fDirectory->RegisterContext(this);
00073          if ( newCurrent ) newCurrent->cd();
00074       }
00075       ~TContext()
00076       {
00077          // Destructor.   Reset the current directory to its
00078          // previous state.
00079          if ( fDirectory ) {
00080             fDirectory->UnregisterContext(this);
00081             fDirectory->cd();
00082          }
00083          else CdNull();
00084       }
00085    };
00086 
00087 protected:
00088 
00089    TObject      *fMother;          //pointer to mother of the directory
00090    TList        *fList;            //List of objects in memory
00091    TUUID         fUUID;            //Unique identifier
00092    TString       fPathBuffer;      //!Buffer for GetPath() function
00093    TContext     *fContext;         //!Pointer to a list of TContext object pointing to this TDirectory
00094    static Bool_t fgAddDirectory;   //!flag to add histograms, graphs,etc to the directory
00095 
00096           Bool_t  cd1(const char *path);
00097    static Bool_t  Cd1(const char *path);
00098 
00099    virtual void   CleanTargets();
00100            void   FillFullPath(TString& buf) const;
00101            void   RegisterContext(TContext *ctxt);
00102            void   UnregisterContext(TContext *ctxt);
00103    friend class TContext;
00104 
00105 protected:
00106    TDirectory(const TDirectory &directory);  //Directories cannot be copied
00107    void operator=(const TDirectory &); //Directorise cannot be copied
00108 
00109 public:
00110 
00111    TDirectory();
00112    TDirectory(const char *name, const char *title, Option_t *option="", TDirectory* motherDir = 0);
00113    virtual ~TDirectory();
00114    static  void        AddDirectory(Bool_t add=kTRUE);
00115    static  Bool_t      AddDirectoryStatus();
00116    virtual void        Append(TObject *obj, Bool_t replace = kFALSE);
00117    virtual void        Add(TObject *obj, Bool_t replace = kFALSE) { Append(obj,replace); }
00118    virtual Int_t       AppendKey(TKey *) {return 0;}
00119    virtual void        Browse(TBrowser *b);
00120    virtual void        Build(TFile* motherFile = 0, TDirectory* motherDir = 0);
00121    virtual void        Clear(Option_t *option="");
00122    virtual TObject    *CloneObject(const TObject *obj, Bool_t autoadd = kTRUE);
00123    virtual void        Close(Option_t *option="");
00124    virtual void        Copy(TObject &) const { MayNotUse("Copy(TObject &)"); }
00125    virtual Bool_t      cd(const char *path = 0);
00126    virtual void        DeleteAll(Option_t *option="");
00127    virtual void        Delete(const char *namecycle="");
00128    virtual void        Draw(Option_t *option="");
00129    virtual TKey       *FindKey(const char * /*keyname*/) const {return 0;}
00130    virtual TKey       *FindKeyAny(const char * /*keyname*/) const {return 0;}
00131    virtual TObject    *FindObject(const char *name) const;
00132    virtual TObject    *FindObject(const TObject *obj) const;
00133    virtual TObject    *FindObjectAny(const char *name) const;
00134    virtual TObject    *FindObjectAnyFile(const char * /*name*/) const {return 0;}
00135    virtual TObject    *Get(const char *namecycle);
00136    virtual TDirectory *GetDirectory(const char *namecycle, Bool_t printError = false, const char *funcname = "GetDirectory");
00137    template <class T> inline void GetObject(const char* namecycle, T*& ptr) // See TDirectory::Get for information
00138       {
00139          ptr = (T*)GetObjectChecked(namecycle,TBuffer::GetClass(typeid(T)));
00140       }
00141    virtual void       *GetObjectChecked(const char *namecycle, const char* classname);
00142    virtual void       *GetObjectChecked(const char *namecycle, const TClass* cl);
00143    virtual void       *GetObjectUnchecked(const char *namecycle);
00144    virtual Int_t       GetBufferSize() const {return 0;}
00145    virtual TFile      *GetFile() const { return 0; }
00146    virtual TKey       *GetKey(const char * /*name */, Short_t /* cycle */=9999) const {return 0;}
00147    virtual TList      *GetList() const { return fList; }
00148    virtual TList      *GetListOfKeys() const { return 0; }
00149    virtual TObject    *GetMother() const { return fMother; }
00150    virtual TDirectory *GetMotherDir() const { return fMother==0 ? 0 : dynamic_cast<TDirectory*>(fMother); }
00151    virtual Int_t       GetNbytesKeys() const { return 0; }
00152    virtual Int_t       GetNkeys() const { return 0; }
00153    virtual Long64_t    GetSeekDir() const { return 0; }
00154    virtual Long64_t    GetSeekParent() const { return 0; }
00155    virtual Long64_t    GetSeekKeys() const { return 0; }
00156    virtual const char *GetPathStatic() const;
00157    virtual const char *GetPath() const;
00158    TUUID               GetUUID() const {return fUUID;}
00159    virtual Bool_t      IsFolder() const { return kTRUE; }
00160    virtual Bool_t      IsModified() const { return kFALSE; }
00161    virtual Bool_t      IsWritable() const { return kFALSE; }
00162    virtual void        ls(Option_t *option="") const;
00163    virtual TDirectory *mkdir(const char *name, const char *title="");
00164    virtual TFile      *OpenFile(const char * /*name*/, Option_t * /*option*/ = "",
00165                             const char * /*ftitle*/ = "", Int_t /*compress*/ = 1,
00166                             Int_t /*netopt*/ = 0) {return 0;}
00167    virtual void        Paint(Option_t *option="");
00168    virtual void        Print(Option_t *option="") const;
00169    virtual void        Purge(Short_t /*nkeep*/=1) {}
00170    virtual void        pwd() const;
00171    virtual void        ReadAll(Option_t * /*option*/="") {}
00172    virtual Int_t       ReadKeys(Bool_t /*forceRead*/=kTRUE) {return 0;}
00173    virtual Int_t       ReadTObject(TObject * /*obj*/, const char * /*keyname*/) {return 0;}
00174    virtual TObject    *Remove(TObject*);
00175    virtual void        RecursiveRemove(TObject *obj);
00176    virtual void        rmdir(const char *name);
00177    virtual void        Save() {}
00178    virtual Int_t       SaveObjectAs(const TObject * /*obj*/, const char * /*filename*/="", Option_t * /*option*/="") const;
00179    virtual void        SaveSelf(Bool_t /*force*/ = kFALSE) {}
00180    virtual void        SetBufferSize(Int_t /* bufsize */) {}
00181    virtual void        SetModified() {}
00182    virtual void        SetMother(TObject *mother) {fMother = (TObject*)mother;}
00183    virtual void        SetName(const char* newname);
00184    virtual void        SetTRefAction(TObject * /*ref*/, TObject * /*parent*/) {}
00185    virtual void        SetSeekDir(Long64_t) {}
00186    virtual void        SetWritable(Bool_t) {}
00187    virtual Int_t       Sizeof() const {return 0;}
00188    virtual Int_t       Write(const char * /*name*/=0, Int_t /*opt*/=0, Int_t /*bufsize*/=0){return 0;}
00189    virtual Int_t       Write(const char * /*name*/=0, Int_t /*opt*/=0, Int_t /*bufsize*/=0) const {return 0;}
00190    virtual Int_t       WriteTObject(const TObject *obj, const char *name =0, Option_t * /*option*/="", Int_t /*bufsize*/ =0);
00191    template <class T> inline Int_t WriteObject(const T* obj, const char* name, Option_t *option="", Int_t bufsize=0) // see TDirectory::WriteTObject or TDirectoryWriteObjectAny for explanation
00192       {
00193          return WriteObjectAny(obj,TBuffer::GetClass(typeid(T)),name,option,bufsize);
00194       }
00195    virtual Int_t       WriteObjectAny(const void *, const char * /*classname*/, const char * /*name*/, Option_t * /*option*/="", Int_t /*bufsize*/ =0) {return 0;}
00196    virtual Int_t       WriteObjectAny(const void *, const TClass * /*cl*/, const char * /*name*/, Option_t * /*option*/="", Int_t /*bufsize*/ =0) {return 0;}
00197    virtual void        WriteDirHeader() {}
00198    virtual void        WriteKeys() {}
00199 
00200    static Bool_t       Cd(const char *path);
00201    static void         DecodeNameCycle(const char *namecycle, char *name, Short_t &cycle);
00202    static void         EncodeNameCycle(char *buffer, const char *name, Short_t cycle);
00203 
00204    ClassDef(TDirectory,5)  //Describe directory structure in memory
00205 };
00206 
00207 #endif

Generated on Tue Jul 5 14:10:26 2011 for ROOT_528-00b_version by  doxygen 1.5.1