// @(#)root/tree:$Id$
// Author: Axel Naumann   14/10/2004

/*************************************************************************
 * Copyright (C) 1995-2004, 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_TBranchBrowsable
#define ROOT_TBranchBrowsable

#ifndef ROOT_TNamed
#include "TNamed.h"
#endif

#ifndef ROOT_TList
#include "TList.h"
#endif

#include <list>

class TMethod;
class TBowser;
class TClass;
class TBranch;
class TBranchElement;
class TString;
class TStreamerElement;

class TVirtualBranchBrowsable: public TNamed {
public:

   // these methods are registered in RegisterGenerator, and
   // called to create the list of browsables. See e.g.
   // TMethodBrowsable::Register
   typedef Int_t (*MethodCreateListOfBrowsables_t)
      (TList&, const TBranch* branch, const TVirtualBranchBrowsable* parent);

   ~TVirtualBranchBrowsable();

   void Browse(TBrowser *b);
   const char *GetIconName() const {
      // return icon shown when browsing a TVirtualBranchBrowsable
      if (IsFolder()) return "TBranchElement-folder";
      else return "TBranchElement-leaf";
   }
   void GetScope(TString & scope) const;
   Bool_t IsFolder() const {
      // check whether we have sub-elements
      return (GetLeaves() && GetLeaves()->GetSize()); }

   static Int_t FillListOfBrowsables(TList& list, const TBranch* branch,
                                     const TVirtualBranchBrowsable* parent=0);

   const TBranch* GetBranch() const {
      // return the parent branch (might be many levels up)
      return fBranch; }
   const TVirtualBranchBrowsable* GetParent() const {
      // return the parent TVirtualBranchBrowsable
      return fParent; }
   TClass* GetClassType() const {
      // return the type of this browsable object
      return fClass; }
   Bool_t TypeIsPointer() const {
      // return whether the type of this browsable object is a pointer
      return fTypeIsPointer; }
   TList* GetLeaves() const;

   // static void Register()   has to be implemented for all derived classes!
   // static void Unregister() has to be implemented for all derived classes!

protected:
   TVirtualBranchBrowsable(const TBranch* b, TClass* type, Bool_t typeIsPointer,
      const TVirtualBranchBrowsable* parent=0);
   static TClass* GetCollectionContainedType(const TBranch* b,
      const TVirtualBranchBrowsable* parent, TClass* &contained);
   static std::list<MethodCreateListOfBrowsables_t>& GetRegisteredGenerators();
   static void RegisterGenerator(MethodCreateListOfBrowsables_t generator);
   static void UnregisterGenerator(MethodCreateListOfBrowsables_t generator);
   void SetType(TClass* type) {
      // sets the type of this browsable object
      fClass=type; }
   void SetTypeIsPointer(Bool_t set=kTRUE) {
      // sets whether the type of this browsable object is a pointer
      fTypeIsPointer=set; }

private:
   static void RegisterDefaultGenerators();
   const TBranch    *fBranch; // pointer to the branch element representing the top object
   const TVirtualBranchBrowsable *fParent; // parent method if this method is member of a returned class
   TList            *fLeaves; // pointer to leaves
   TClass           *fClass; // pointer to TClass representing our type (i.e. return type for methods), 0 if basic type
   Bool_t            fTypeIsPointer; // return type is pointer to class
   static std::list<MethodCreateListOfBrowsables_t> fgGenerators; // list of MethodCreateListOfBrowsables_t called by CreateListOfBrowsables
   static Bool_t     fgGeneratorsSet; // have we set the generators yet? empty is not good enough - user might have removed them
   ClassDef(TVirtualBranchBrowsable, 0); // Base class for helper objects used for browsing
};


class TMethodBrowsable: public TVirtualBranchBrowsable {
public:
   ~TMethodBrowsable() {};

   static Int_t GetBrowsables(TList& list, const TBranch* branch,
                              const TVirtualBranchBrowsable* parent=0);
   const char *GetIconName() const {
      // return our special icons
      if (IsFolder()) return "TMethodBrowsable-branch";
      return "TMethodBrowsable-leaf";}
   static Bool_t IsMethodBrowsable(const TMethod* m);
   static void Register();
   static void Unregister();

protected:
   static void GetBrowsableMethodsForClass(TClass* cl, TList& list);
   TMethodBrowsable(const TBranch* branch, TMethod* m,
      const TVirtualBranchBrowsable* parent=0);

private:
   TMethod         *fMethod; // pointer to a method
   ClassDef(TMethodBrowsable,0); // Helper object to browse methods
};


class TNonSplitBrowsable: public TVirtualBranchBrowsable {
public:
   ~TNonSplitBrowsable() {}

   static Int_t GetBrowsables(TList& list, const TBranch* branch,
                              const TVirtualBranchBrowsable* parent=0);
   static void Register();
   static void Unregister();

protected:
   TNonSplitBrowsable(const TStreamerElement* element, const TBranch* branch,
      const TVirtualBranchBrowsable* parent=0);

private:
   ClassDef(TNonSplitBrowsable, 0); // Helper object to browse unsplit objects
};


class TCollectionPropertyBrowsable: public TVirtualBranchBrowsable {
public:
   ~TCollectionPropertyBrowsable() {}

   void Browse(TBrowser *b);
   static Int_t GetBrowsables(TList& list, const TBranch* branch,
                              const TVirtualBranchBrowsable* parent=0);
   const char* GetDraw() const {
      // return the string passed to TTree::Draw
      return fDraw.Data(); }
   static void Register();
   static void Unregister();

protected:
   TCollectionPropertyBrowsable(const char* name, const char* title,
      const char* draw, const TBranch* branch, const TVirtualBranchBrowsable* parent=0):
   TVirtualBranchBrowsable(branch, 0, kFALSE, parent), fDraw(draw) {
      // constructor, which sets the name and title according to the parameters
      // (and thus differently than our base class TVirtualBranchBrowsable)
      SetNameTitle(name, title);
   }

private:
   TString fDraw; // string to send to TTree::Draw(), NOT by GetScope()!
   ClassDef(TCollectionPropertyBrowsable, 0); // Helper object to add browsable collection properties
};

class TCollectionMethodBrowsable: public TMethodBrowsable {
public:
   ~TCollectionMethodBrowsable() {};

   static Int_t GetBrowsables(TList& list, const TBranch* branch,
                              const TVirtualBranchBrowsable* parent=0);
   static void Register();
   static void Unregister();

protected:
   TCollectionMethodBrowsable(const TBranch* branch, TMethod* m,
      const TVirtualBranchBrowsable* parent=0);

   ClassDef(TCollectionMethodBrowsable,0); // Helper object to browse a collection's methods
};

#endif // defined ROOT_TBranchBrowsable
 TBranchBrowsable.h:1
 TBranchBrowsable.h:2
 TBranchBrowsable.h:3
 TBranchBrowsable.h:4
 TBranchBrowsable.h:5
 TBranchBrowsable.h:6
 TBranchBrowsable.h:7
 TBranchBrowsable.h:8
 TBranchBrowsable.h:9
 TBranchBrowsable.h:10
 TBranchBrowsable.h:11
 TBranchBrowsable.h:12
 TBranchBrowsable.h:13
 TBranchBrowsable.h:14
 TBranchBrowsable.h:15
 TBranchBrowsable.h:16
 TBranchBrowsable.h:17
 TBranchBrowsable.h:18
 TBranchBrowsable.h:19
 TBranchBrowsable.h:20
 TBranchBrowsable.h:21
 TBranchBrowsable.h:22
 TBranchBrowsable.h:23
 TBranchBrowsable.h:24
 TBranchBrowsable.h:25
 TBranchBrowsable.h:26
 TBranchBrowsable.h:27
 TBranchBrowsable.h:28
 TBranchBrowsable.h:29
 TBranchBrowsable.h:30
 TBranchBrowsable.h:31
 TBranchBrowsable.h:32
 TBranchBrowsable.h:33
 TBranchBrowsable.h:34
 TBranchBrowsable.h:35
 TBranchBrowsable.h:36
 TBranchBrowsable.h:37
 TBranchBrowsable.h:38
 TBranchBrowsable.h:39
 TBranchBrowsable.h:40
 TBranchBrowsable.h:41
 TBranchBrowsable.h:42
 TBranchBrowsable.h:43
 TBranchBrowsable.h:44
 TBranchBrowsable.h:45
 TBranchBrowsable.h:46
 TBranchBrowsable.h:47
 TBranchBrowsable.h:48
 TBranchBrowsable.h:49
 TBranchBrowsable.h:50
 TBranchBrowsable.h:51
 TBranchBrowsable.h:52
 TBranchBrowsable.h:53
 TBranchBrowsable.h:54
 TBranchBrowsable.h:55
 TBranchBrowsable.h:56
 TBranchBrowsable.h:57
 TBranchBrowsable.h:58
 TBranchBrowsable.h:59
 TBranchBrowsable.h:60
 TBranchBrowsable.h:61
 TBranchBrowsable.h:62
 TBranchBrowsable.h:63
 TBranchBrowsable.h:64
 TBranchBrowsable.h:65
 TBranchBrowsable.h:66
 TBranchBrowsable.h:67
 TBranchBrowsable.h:68
 TBranchBrowsable.h:69
 TBranchBrowsable.h:70
 TBranchBrowsable.h:71
 TBranchBrowsable.h:72
 TBranchBrowsable.h:73
 TBranchBrowsable.h:74
 TBranchBrowsable.h:75
 TBranchBrowsable.h:76
 TBranchBrowsable.h:77
 TBranchBrowsable.h:78
 TBranchBrowsable.h:79
 TBranchBrowsable.h:80
 TBranchBrowsable.h:81
 TBranchBrowsable.h:82
 TBranchBrowsable.h:83
 TBranchBrowsable.h:84
 TBranchBrowsable.h:85
 TBranchBrowsable.h:86
 TBranchBrowsable.h:87
 TBranchBrowsable.h:88
 TBranchBrowsable.h:89
 TBranchBrowsable.h:90
 TBranchBrowsable.h:91
 TBranchBrowsable.h:92
 TBranchBrowsable.h:93
 TBranchBrowsable.h:94
 TBranchBrowsable.h:95
 TBranchBrowsable.h:96
 TBranchBrowsable.h:97
 TBranchBrowsable.h:98
 TBranchBrowsable.h:99
 TBranchBrowsable.h:100
 TBranchBrowsable.h:101
 TBranchBrowsable.h:102
 TBranchBrowsable.h:103
 TBranchBrowsable.h:104
 TBranchBrowsable.h:105
 TBranchBrowsable.h:106
 TBranchBrowsable.h:107
 TBranchBrowsable.h:108
 TBranchBrowsable.h:109
 TBranchBrowsable.h:110
 TBranchBrowsable.h:111
 TBranchBrowsable.h:112
 TBranchBrowsable.h:113
 TBranchBrowsable.h:114
 TBranchBrowsable.h:115
 TBranchBrowsable.h:116
 TBranchBrowsable.h:117
 TBranchBrowsable.h:118
 TBranchBrowsable.h:119
 TBranchBrowsable.h:120
 TBranchBrowsable.h:121
 TBranchBrowsable.h:122
 TBranchBrowsable.h:123
 TBranchBrowsable.h:124
 TBranchBrowsable.h:125
 TBranchBrowsable.h:126
 TBranchBrowsable.h:127
 TBranchBrowsable.h:128
 TBranchBrowsable.h:129
 TBranchBrowsable.h:130
 TBranchBrowsable.h:131
 TBranchBrowsable.h:132
 TBranchBrowsable.h:133
 TBranchBrowsable.h:134
 TBranchBrowsable.h:135
 TBranchBrowsable.h:136
 TBranchBrowsable.h:137
 TBranchBrowsable.h:138
 TBranchBrowsable.h:139
 TBranchBrowsable.h:140
 TBranchBrowsable.h:141
 TBranchBrowsable.h:142
 TBranchBrowsable.h:143
 TBranchBrowsable.h:144
 TBranchBrowsable.h:145
 TBranchBrowsable.h:146
 TBranchBrowsable.h:147
 TBranchBrowsable.h:148
 TBranchBrowsable.h:149
 TBranchBrowsable.h:150
 TBranchBrowsable.h:151
 TBranchBrowsable.h:152
 TBranchBrowsable.h:153
 TBranchBrowsable.h:154
 TBranchBrowsable.h:155
 TBranchBrowsable.h:156
 TBranchBrowsable.h:157
 TBranchBrowsable.h:158
 TBranchBrowsable.h:159
 TBranchBrowsable.h:160
 TBranchBrowsable.h:161
 TBranchBrowsable.h:162
 TBranchBrowsable.h:163
 TBranchBrowsable.h:164
 TBranchBrowsable.h:165
 TBranchBrowsable.h:166
 TBranchBrowsable.h:167
 TBranchBrowsable.h:168
 TBranchBrowsable.h:169
 TBranchBrowsable.h:170
 TBranchBrowsable.h:171
 TBranchBrowsable.h:172
 TBranchBrowsable.h:173
 TBranchBrowsable.h:174
 TBranchBrowsable.h:175
 TBranchBrowsable.h:176
 TBranchBrowsable.h:177
 TBranchBrowsable.h:178
 TBranchBrowsable.h:179
 TBranchBrowsable.h:180
 TBranchBrowsable.h:181
 TBranchBrowsable.h:182
 TBranchBrowsable.h:183
 TBranchBrowsable.h:184
 TBranchBrowsable.h:185
 TBranchBrowsable.h:186
 TBranchBrowsable.h:187
 TBranchBrowsable.h:188
 TBranchBrowsable.h:189