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

Last change on this file since 10058 was 9441, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 1.8 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, const TString &filter) const;
23 TString ConcatFileName(const char *dir, const char *name) const;
24 void PrintEntry(const TObject &o) const;
25 const TRegexp MakeRegexp(TString n) const;
26
27public:
28 MDirIter() : fNext(&fList), fDirPtr(NULL)
29 {
30 fList.SetOwner();
31 }
32 MDirIter(const MDirIter &dir) : TObject(), fNext(&fList), fDirPtr(NULL)
33 {
34 fList.SetOwner();
35
36 TObject *o=NULL;
37 TIter NextD(&dir.fList);
38 while ((o=NextD()))
39 AddDirectory(o->GetName(), o->GetTitle());
40 }
41 MDirIter(const char *dir, const char *filter="", Int_t rec=0) : fNext(&fList), fDirPtr(NULL)
42 {
43 fList.SetOwner();
44 AddDirectory(dir, filter, rec);
45 }
46 ~MDirIter()
47 {
48 Close();
49 }
50
51 void Sort();
52
53 Int_t AddDirectory(const char *dir, const char *filter="", Int_t recursive=0);
54 Int_t AddFile(const char *name);
55 void Add(const MDirIter &iter);
56 void Reset();
57
58 TString Next(Bool_t nocheck=kFALSE);
59 TString operator()(Bool_t nocheck=kFALSE) { return Next(nocheck); }
60
61 void SetFilter(const char *f="") { fFilter = f; }
62 UInt_t GetNumEntries() const
63 {
64 UInt_t n = 0;
65 MDirIter NextD(*this);
66 while (!NextD().IsNull()) n++;
67 return n;
68 }
69
70 void Print(const Option_t *o="") const;
71
72 ClassDef(MDirIter, 1) // Iterator for files in several directories (with filters)
73};
74
75#endif
Note: See TracBrowser for help on using the repository browser.