source: trunk/Mars/mbase/MDirIter.h@ 19945

Last change on this file since 19945 was 19720, checked in by tbretz, 5 years ago
Added a constructor which allows to instantiate MDIrIter with just one argument
File size: 2.0 KB
Line 
1#ifndef MARS_MDirIter
2#define MARS_MDirIter
3
4#ifndef ROOT_TObjArray
5#include <TObjArray.h>
6#endif
7
8class MDirIter : public TObject
9{
10private:
11 TObjArray fList;
12 TString fFilter;
13
14 TIter fNext; //!
15 void *fDirPtr; //!
16 TObject *fCurrentPath; //!
17
18 void *Open();
19 void Close();
20 Bool_t CheckEntry(const TString n) const;
21 Int_t IsDir(const char *dir) const;
22 Bool_t MatchFilter(const TString &name, TString filter) const;
23 TString ConcatFileName(const char *dir, const char *name) const;
24 void PrintEntry(const TObject &o) const;
25
26public:
27 MDirIter() : fNext(&fList), fDirPtr(NULL)
28 {
29 fList.SetOwner();
30 }
31 MDirIter(const MDirIter &dir) : TObject(), fNext(&fList), fDirPtr(NULL)
32 {
33 fList.SetOwner();
34
35 TObject *o=NULL;
36 TIter NextD(&dir.fList);
37 while ((o=NextD()))
38 AddDirectory(o->GetName(), o->GetTitle());
39 }
40 MDirIter(const char *dir, const char *filter, Int_t rec=0) : fNext(&fList), fDirPtr(NULL)
41 {
42 fList.SetOwner();
43 AddDirectory(dir, filter, rec);
44 }
45 MDirIter(const char *dir, Int_t rec=0) : fNext(&fList), fDirPtr(NULL)
46 {
47 fList.SetOwner();
48 AddFile(dir, rec);
49 }
50 ~MDirIter()
51 {
52 Close();
53 }
54
55 Int_t ReadList(const char *fname, const TString &path="");
56 void Sort();
57
58 Int_t AddDirectory(const char *dir, const char *filter="", Int_t recursive=0);
59 Int_t AddFile(const char *name, Int_t rec=0);
60 void Add(const MDirIter &iter);
61 void Reset();
62
63 TString Next(Bool_t nocheck=kFALSE);
64 TString operator()(Bool_t nocheck=kFALSE) { return Next(nocheck); }
65
66 void SetFilter(const char *f="") { fFilter = f; }
67 UInt_t GetNumEntries() const
68 {
69 UInt_t n = 0;
70 MDirIter NextD(*this);
71 while (!NextD().IsNull()) n++;
72 return n;
73 }
74
75 void Print(const Option_t *o="") const;
76
77 ClassDef(MDirIter, 1) // Iterator for files in several directories (with filters)
78};
79
80#endif
Note: See TracBrowser for help on using the repository browser.