TBranchBrowsable.h

Go to the documentation of this file.
00001 // @(#)root/tree:$Id: TBranchBrowsable.h 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Axel Naumann   14/10/2004
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, 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_TBranchBrowsable
00013 #define ROOT_TBranchBrowsable
00014 
00015 #ifndef ROOT_TNamed
00016 #include "TNamed.h"
00017 #endif
00018 
00019 #ifndef ROOT_TList
00020 #include "TList.h"
00021 #endif
00022 
00023 #include <list>
00024 
00025 class TMethod;
00026 class TBowser;
00027 class TClass;
00028 class TBranch;
00029 class TBranchElement;
00030 class TString;
00031 class TStreamerElement;
00032 
00033 class TVirtualBranchBrowsable: public TNamed {
00034 public: 
00035 
00036    // these methods are registered in RegisterGenerator, and 
00037    // called to create the list of browsables. See e.g. 
00038    // TMethodBrowsable::Register
00039    typedef Int_t (*MethodCreateListOfBrowsables_t)
00040       (TList&, const TBranch* branch, const TVirtualBranchBrowsable* parent); 
00041 
00042    ~TVirtualBranchBrowsable();
00043 
00044    void Browse(TBrowser *b);
00045    const char *GetIconName() const {
00046       // return icon shown when browsing a TVirtualBranchBrowsable
00047       if (IsFolder()) return "TBranchElement-folder";
00048       else return "TBranchElement-leaf"; 
00049    }
00050    void GetScope(TString & scope) const;
00051    Bool_t IsFolder() const {
00052       // check whether we have sub-elements
00053       return (GetLeaves() && GetLeaves()->GetSize()); }
00054 
00055    static Int_t FillListOfBrowsables(TList& list, const TBranch* branch,
00056                                      const TVirtualBranchBrowsable* parent=0);
00057 
00058    const TBranch* GetBranch() const { 
00059       // return the parent branch (might be many levels up)
00060       return fBranch; }
00061    const TVirtualBranchBrowsable* GetParent() const { 
00062       // return the parent TVirtualBranchBrowsable
00063       return fParent; }
00064    TClass* GetClassType() const { 
00065       // return the type of this browsable object
00066       return fClass; }
00067    Bool_t TypeIsPointer() const { 
00068       // return whether the type of this browsable object is a pointer
00069       return fTypeIsPointer; }
00070    TList* GetLeaves() const; 
00071 
00072    // static void Register()   has to be implemented for all derived classes!
00073    // static void Unregister() has to be implemented for all derived classes!
00074 
00075 protected:
00076    TVirtualBranchBrowsable(const TBranch* b, TClass* type, Bool_t typeIsPointer, 
00077       const TVirtualBranchBrowsable* parent=0);
00078    static TClass* GetCollectionContainedType(const TBranch* b, 
00079       const TVirtualBranchBrowsable* parent, TClass* &contained);
00080    static std::list<MethodCreateListOfBrowsables_t>& GetRegisteredGenerators();
00081    static void RegisterGenerator(MethodCreateListOfBrowsables_t generator);
00082    static void UnregisterGenerator(MethodCreateListOfBrowsables_t generator);
00083    void SetType(TClass* type) { 
00084       // sets the type of this browsable object
00085       fClass=type; }
00086    void SetTypeIsPointer(Bool_t set=kTRUE) { 
00087       // sets whether the type of this browsable object is a pointer
00088       fTypeIsPointer=set; }
00089 
00090 private:
00091    static void RegisterDefaultGenerators();
00092    const TBranch    *fBranch; // pointer to the branch element representing the top object
00093    const TVirtualBranchBrowsable *fParent; // parent method if this method is member of a returned class
00094    TList            *fLeaves; // pointer to laves
00095    TClass           *fClass; // pointer to TClass representing our type (i.e. return type for methods), 0 if basic type
00096    Bool_t            fTypeIsPointer; // return type is pointer to class
00097    static std::list<MethodCreateListOfBrowsables_t> fgGenerators; // list of MethodCreateListOfBrowsables_t called by CreateListOfBrowsables
00098    static Bool_t     fgGeneratorsSet; // have we set the generators yet? empty is not good enough - user might have removed them
00099    ClassDef(TVirtualBranchBrowsable, 0); // Base class for helper objects used for browsing
00100 };
00101 
00102 
00103 class TMethodBrowsable: public TVirtualBranchBrowsable {
00104 public:
00105    ~TMethodBrowsable() {};
00106 
00107    static Int_t GetBrowsables(TList& list, const TBranch* branch,
00108                               const TVirtualBranchBrowsable* parent=0);
00109    const char *GetIconName() const {
00110       // return our special icons
00111       if (IsFolder()) return "TMethodBrowsable-branch"; 
00112       return "TMethodBrowsable-leaf";}
00113    static Bool_t IsMethodBrowsable(const TMethod* m);
00114    static void Register();
00115    static void Unregister();
00116 
00117 protected:
00118    static void GetBrowsableMethodsForClass(TClass* cl, TList& list);
00119    TMethodBrowsable(const TBranch* branch, TMethod* m, 
00120       const TVirtualBranchBrowsable* parent=0);
00121 
00122 private:
00123    TMethod         *fMethod; // pointer to a method
00124    ClassDef(TMethodBrowsable,0); // Helper object to browse methods
00125 };
00126 
00127 
00128 class TNonSplitBrowsable: public TVirtualBranchBrowsable {
00129 public:
00130    ~TNonSplitBrowsable() {}
00131 
00132    static Int_t GetBrowsables(TList& list, const TBranch* branch, 
00133                               const TVirtualBranchBrowsable* parent=0);
00134    static void Register();
00135    static void Unregister();
00136 
00137 protected:
00138    TNonSplitBrowsable(const TStreamerElement* element, const TBranch* branch, 
00139       const TVirtualBranchBrowsable* parent=0);
00140 
00141 private:
00142    ClassDef(TNonSplitBrowsable, 0); // Helper object to browse unsplit objects
00143 };
00144 
00145 
00146 class TCollectionPropertyBrowsable: public TVirtualBranchBrowsable {
00147 public:
00148    ~TCollectionPropertyBrowsable() {}
00149 
00150    void Browse(TBrowser *b);
00151    static Int_t GetBrowsables(TList& list, const TBranch* branch, 
00152                               const TVirtualBranchBrowsable* parent=0);
00153    const char* GetDraw() const {
00154       // return the string passed to TTree::Draw
00155       return fDraw.Data(); }
00156    static void Register();
00157    static void Unregister();
00158 
00159 protected:
00160    TCollectionPropertyBrowsable(const char* name, const char* title, 
00161       const char* draw, const TBranch* branch, const TVirtualBranchBrowsable* parent=0): 
00162    TVirtualBranchBrowsable(branch, 0, kFALSE, parent), fDraw(draw) {
00163       // contrsuctor, which sets the name and title according to the parameters
00164       // (and thus differently than our base class TVirtualBranchBrowsable)
00165       SetNameTitle(name, title);
00166    }
00167 
00168 private:
00169    TString fDraw; // string to send to TTree::Draw(), NOT by GetScope()!
00170    ClassDef(TCollectionPropertyBrowsable, 0); // Helper object to add browsable collection properties
00171 };
00172 
00173 class TCollectionMethodBrowsable: public TMethodBrowsable {
00174 public:
00175    ~TCollectionMethodBrowsable() {};
00176 
00177    static Int_t GetBrowsables(TList& list, const TBranch* branch, 
00178                               const TVirtualBranchBrowsable* parent=0);
00179    static void Register();
00180    static void Unregister();
00181 
00182 protected:
00183    TCollectionMethodBrowsable(const TBranch* branch, TMethod* m, 
00184       const TVirtualBranchBrowsable* parent=0);
00185 
00186    ClassDef(TCollectionMethodBrowsable,0); // Helper object to browse a collection's methods
00187 };
00188 
00189 #endif // defined ROOT_TBranchBrowsable

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