StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TDataSet.h
1 // @(#)root/table:$Id$
2 // Author: Valery Fine(fine@mail.cern.ch) 03/07/98
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_TDataSet
13 #define ROOT_TDataSet
14 
15 
17 // //
18 // TDataSet //
19 // //
20 // TDataSet class is a base class to implement the directory-like //
21 // data structures and maintain it via TDataSetIter class iterator //
22 // //
24 
25 #include "TList.h"
26 #include "TObjArray.h"
27 
28 #include "TNamed.h"
29 #include "TNode.h"
30 
31 class TDataSetIter;
32 class TBrowser;
33 
34 class TDataSet : public TNamed
35 {
36 friend class TDataSetIter;
37 public:
38  // The control codes to navigate the TDataSet structure via TDataSet::Pass method
39 
40  typedef enum {
41  kContinue, // continue passing
42  kPrune, // stop passing of the current branch but continue with the next one if any
43  kStop, // break passing
44  kUp, // break passing, return to the previous level, then continue
45  kStruct, // work with structural links only
46  kAll, // work with all links
47  kRefs, // work with refs links only
48  kMarked // work with marked links only
49  } EDataSetPass;
50 
51 private:
52  void operator=(const TDataSet &){}
53 // -- Int_t IncCnt(){ fCnt++; return fCnt;}
54 // -- Int_t DecCnt(){ fCnt--; return fCnt;}
55 // -- Int_t Cnt() { return fCnt;}
56 protected:
57  static TDataSet *fgMainSet; // pointer the main dataset;
58  TDataSet *fParent; // pointer to mother of the directory
59  TSeqCollection *fList; // List of the the the objects included into this dataset
60 // -- Int_t fCnt; // reference counter.
61  virtual void SetMother(TObject *mother) {SetParent((TDataSet*)mother);}
62  TDataSet(const char *name,const char *title):
63  TNamed(name,title),fParent(0),fList(0){} // to support TDictionary
64  void AddMain(TDataSet *set);
65  static EDataSetPass SortIt(TDataSet *ds);
66  static EDataSetPass SortIt(TDataSet *ds,void *user);
68  void MakeCollection();
69 
70 
71 public:
72 
73  //----- dataset flags
74  enum ESetBits {
75  kMark = BIT(22) // if object is marked
76  ,kArray = BIT(20) // if object has TObjArray inside
77  };
78 
79  enum EBitOpt {
80  kSet = kTRUE,
81  kReset = kFALSE
82  };
83 
84  TDataSet(const char *name="", TDataSet *parent=0, Bool_t arrayFlag = kFALSE);
85  TDataSet(const TDataSet &src,EDataSetPass iopt=kAll);
86  TDataSet(TNode &src);
87  virtual ~TDataSet();
88  virtual void Add(TDataSet *dataset);
89  virtual void AddAt(TDataSet *dataset,Int_t idx=0);
90  virtual void AddAtAndExpand(TDataSet *dataset, Int_t idx=0);
91  virtual void AddFirst(TDataSet *dataset);
92  virtual void AddLast(TDataSet *dataset);
93  TDataSet *At(Int_t idx) const;
94  virtual void Browse(TBrowser *b);
95  virtual TObject *Clone(const char *newname="") const;
96  virtual void Delete(Option_t *opt="");
97  virtual TDataSet *Find(const char *path) const;
98  virtual TDataSet *FindByName(const char *name,const char *path="",Option_t *opt="") const;
99  virtual TDataSet *FindByPath(const char *path) const;
100  virtual TDataSet *FindByTitle(const char *title,const char *path="",Option_t *opt="") const;
101  TObject *FindObject(const char *name) const {return FindByName(name);}
102  TObject *FindObject(const TObject *o) const { return TObject::FindObject(o);}
103  virtual TDataSet *First() const;
104  TObjArray *GetObjArray() const { return (TObjArray *)fList; }
105  virtual TSeqCollection *GetCollection() const { return (TSeqCollection *)fList; }
106  TList *GetList() const { return (TList *)fList; }
107  virtual Int_t GetListSize() const;
108  static TDataSet *GetMainSet();
109  TObject *GetMother() const { return (TObject*)GetParent();}
110  virtual TObject *GetObject() const;
111  virtual TDataSet *GetParent() const { return fParent;}
112  virtual Long_t HasData() const {return 0;} // Check whether this dataset has extra "data-members"
113  virtual TDataSet *Instance() const;
114  static TDataSet *instance();
115  virtual TString Path() const; // return the "full" path of this dataset
116  virtual EDataSetPass Pass(EDataSetPass ( *callback)(TDataSet *),Int_t depth=0);
117  virtual EDataSetPass Pass(EDataSetPass ( *callback)(TDataSet *,void*),void *user,Int_t depth=0);
118  virtual void PrintContents(Option_t *opt="") const;
119  virtual Int_t Purge(Option_t *opt="");
120  virtual void Remove(TDataSet *set);
121  virtual TDataSet *RemoveAt(Int_t idx);
122  virtual void SetMother(TDataSet *parent=0){SetParent(parent);};
123  virtual void SetObject(TObject *obj);
124  virtual void SetParent(TDataSet *parent=0);
125  virtual void SetWrite();
126  virtual void Shunt(TDataSet *newParent=0);
127  virtual void Sort(); //Sort objects in lexical order
128  virtual Bool_t IsEmpty() const;
129  virtual Bool_t IsFolder() const {return kTRUE;}
130  virtual Bool_t IsMarked() const ;
131  virtual Bool_t IsThisDir(const char *dirname,int len=-1,int ignorecase=0) const ;
132  virtual TDataSet *Last() const;
133  virtual void ls(Option_t *option="") const; // Option "*" means print all levels
134  virtual void ls(Int_t depth) const; // Print the "depth" levels of this datatset
135  void Mark(); // *MENU*
136  void UnMark(); // *MENU*
137  void MarkAll(); // *MENU*
138  void UnMarkAll(); // *MENU*
139  void InvertAllMarks(); // *MENU*
140  void Mark(UInt_t flag,EBitOpt reset=kSet);
141  virtual TDataSet *Next() const;
142  virtual TDataSet *Prev() const;
143  virtual void Update(); // Update dataset
144  virtual void Update(TDataSet *set,UInt_t opt=0);// Update this dataset with the new one
145  virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0);
146  virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0) const;
147  ClassDef(TDataSet,1) // The base class to create the hierarchical data structures
148 };
149 
150 inline void TDataSet::Add(TDataSet *dataset){ AddLast(dataset); }
151 inline TDataSet *TDataSet::At(Int_t idx) const {return fList ? (TDataSet *)fList->At(idx) : 0; }
152 inline Int_t TDataSet::GetListSize() const {return (fList) ? fList->GetSize():0;}
153 inline TDataSet *TDataSet::instance() { return new TDataSet();}
154 inline Bool_t TDataSet::IsMarked() const { return TestBit(kMark); }
155 inline void TDataSet::Mark(UInt_t flag,EBitOpt reset){ SetBit(flag,reset); }
156 inline void TDataSet::Mark() { Mark(kMark,kSet); }
157 inline void TDataSet::UnMark() { Mark(kMark,kReset); }
158 
159 
160 #endif
virtual Bool_t IsThisDir(const char *dirname, int len=-1, int ignorecase=0) const
Definition: TDataSet.cxx:555
virtual TDataSet * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TDataSet.cxx:403
void MarkAll()
Mark all members of this dataset.
Definition: TDataSet.cxx:571
static TDataSet * GetMainSet()
return pointer to the main dataset
Definition: TDataSet.cxx:420
virtual TDataSet * Instance() const
Definition: TDataSet.cxx:546
virtual TDataSet * FindByTitle(const char *title, const char *path="", Option_t *opt="") const
Definition: TDataSet.cxx:394
virtual TDataSet * FindByPath(const char *path) const
Aliase for TDataSet::Find(const Char_t *path) method.
Definition: TDataSet.cxx:347
virtual EDataSetPass Pass(EDataSetPass(*callback)(TDataSet *), Int_t depth=0)
Definition: TDataSet.cxx:689
virtual void PrintContents(Option_t *opt="") const
Definition: TDataSet.cxx:618
virtual void AddAtAndExpand(TDataSet *dataset, Int_t idx=0)
Definition: TDataSet.cxx:254
virtual void Delete(Option_t *opt="")
Definition: TDataSet.cxx:320
virtual void Remove(TDataSet *set)
Remiove the "set" from this TDataSet.
Definition: TDataSet.cxx:641
virtual TDataSet * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TDataSet.cxx:437
TDataSet * GetRealParent()
return real parent
Definition: TDataSet.cxx:166
virtual void Browse(TBrowser *b)
Browse this dataset (called by TBrowser).
Definition: TDataSet.cxx:297
virtual void SetObject(TObject *obj)
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:480
virtual TObject * Clone(const char *newname="") const
the custom implementation fo the TObject::Clone
Definition: TDataSet.cxx:308
void InvertAllMarks()
Invert mark bit for all members of this dataset.
Definition: TDataSet.cxx:593
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Definition: TDataSet.cxx:893
virtual TDataSet * Prev() const
Definition: TDataSet.cxx:464
virtual TObject * FindObject(const Char_t *name) const
virtual void SetWrite()
Definition: TDataSet.cxx:797
virtual void ls(Option_t *option="") const
Definition: TDataSet.cxx:495
virtual void AddLast(TDataSet *dataset)
Add TDataSet object at the end of the dataset list of this dataset.
Definition: TDataSet.cxx:269
virtual Bool_t IsEmpty() const
return kTRUE if the "internal" collection has no member
Definition: TDataSet.cxx:608
virtual TDataSet * Next() const
Definition: TDataSet.cxx:447
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
virtual ~TDataSet()
std::cout << "Default destructor for " << GetName() << " - " << GetTitle() << std::endl; ...
Definition: TDataSet.cxx:213
virtual void AddFirst(TDataSet *dataset)
Add TDataSet object at the beginning of the dataset list of this dataset.
Definition: TDataSet.cxx:283
virtual void AddAt(TDataSet *dataset, Int_t idx=0)
Definition: TDataSet.cxx:235
virtual Int_t Purge(Option_t *opt="")
Definition: TDataSet.cxx:758
virtual void Shunt(TDataSet *newParent=0)
Definition: TDataSet.cxx:810
virtual void Sort()
Sort recursively all members of the TDataSet with TList::Sort method.
Definition: TDataSet.cxx:874
virtual TDataSet * FindByName(const char *name, const char *path="", Option_t *opt="") const
Definition: TDataSet.cxx:378
virtual void SetParent(TDataSet *parent=0)
Definition: TDataSet.cxx:784
virtual void Update()
Definition: TDataSet.cxx:864
virtual TString Path() const
return the full path of this data set
Definition: TDataSet.cxx:626
void UnMarkAll()
UnMark all members of this dataset.
Definition: TDataSet.cxx:582
void AddMain(TDataSet *set)
add data set to main data set
Definition: TDataSet.cxx:412
void MakeCollection()
Create the internal container at once if any.
Definition: TDataSet.cxx:221
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362
virtual TDataSet * RemoveAt(Int_t idx)
Definition: TDataSet.cxx:656