Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXDirVisitor.h
1 /********************************************************************************
2 * *
3 * D i r e c t o r y V i s i t o r *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2008,2024 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXDIRVISITOR_H
22 #define FXDIRVISITOR_H
23 
24 namespace FX {
25 
26 
57 class FXAPI FXDirVisitor {
58 private:
59  struct Seen;
60 private:
61  Seen* current;
62 private:
63  FXDirVisitor(const FXDirVisitor&);
64  FXDirVisitor& operator=(const FXDirVisitor&);
65 public:
66 
68  FXDirVisitor():current(nullptr){}
69 
71  FXuint traverse(const FXString& path,FXint limit=1000);
72 
74  FXbool visiting() const { return current!=nullptr; }
75 
77  const FXStat& info() const;
78 
80  virtual FXuint enter(const FXString& path);
81 
83  virtual FXuint visit(const FXString& path);
84 
86  virtual FXuint leave(const FXString& path);
87 
89  virtual ~FXDirVisitor();
90  };
91 
92 
97 class FXAPI FXGlobVisitor : public FXDirVisitor {
98 private:
99  FXString wildcard; // Match files against this wild card
100  FXuint options; // Matching options
101 private:
103  FXGlobVisitor& operator=(const FXGlobVisitor&);
104 public:
105 
107  FXGlobVisitor():options(0){}
108 
110  FXuint traverse(const FXString& path,const FXString& wild="*",FXuint opts=FXDir::MatchAll,FXint depth=1000);
111 
113  virtual FXuint enter(const FXString& path);
114 
116  virtual FXuint visit(const FXString& path);
117 
119  virtual FXuint leave(const FXString& path);
120 
122  virtual ~FXGlobVisitor();
123  };
124 
125 
132 class FXAPI FXGlobCountVisitor : public FXGlobVisitor {
133 private:
134  FXlong countFolders; // Count of folders seen
135  FXlong countFiles; // Count of files seen
136  FXlong countBytes; // Total number of bytes in files
137  FXlong maxDepth; // Maximum depth
138  FXlong depth; // Current depth during traversal
139 private:
141  FXGlobCountVisitor& operator=(const FXGlobCountVisitor&);
142 public:
143 
146 
148  FXuint traverse(const FXString& path,const FXString& wild="*",FXuint opts=FXDir::MatchAll,FXint limit=1000);
149 
151  FXlong getTotalFolders() const { return countFolders; }
152 
154  FXlong getTotalFiles() const { return countFiles; }
155 
157  FXlong getTotalBytes() const { return countBytes; }
158 
160  FXlong getMaximumDepth() const { return maxDepth; }
161 
163  virtual FXuint enter(const FXString& path);
164 
166  virtual FXuint visit(const FXString& path);
167 
169  virtual FXuint leave(const FXString& path);
170 
172  virtual ~FXGlobCountVisitor();
173  };
174 
175 
176 }
177 
178 #endif
FXlong getTotalBytes() const
Return total number of bytes in matching files.
Definition: FXDirVisitor.h:157
Directory visitor walks across all files and directories recursively, starting from the given path...
Definition: FXDirVisitor.h:57
Statistics about a file or directory.
Definition: FXStat.h:31
FXDirVisitor()
Initialize directory visitor.
Definition: FXDirVisitor.h:68
FXlong getTotalFolders() const
Return total number of folders found.
Definition: FXDirVisitor.h:151
Visit directory entries according to flags and matching with wild card pattern, as per FXGlobVisitor ...
Definition: FXDirVisitor.h:132
Visit directory entries according to flags and matching with wild card pattern, with similar matching...
Definition: FXDirVisitor.h:97
FXlong getTotalFiles() const
Return total number of files matched.
Definition: FXDirVisitor.h:154
Definition: FX4Splitter.h:28
FXbool visiting() const
Return true if we&#39;re actively visiting directories.
Definition: FXDirVisitor.h:74
FXGlobVisitor()
Construct directory visitor.
Definition: FXDirVisitor.h:107
FXlong getMaximumDepth() const
Return maximum depth of directory tree.
Definition: FXDirVisitor.h:160
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2022 Jeroen van der Zijp