Switch to unified view

a/src/utils/fstreewalk.h b/src/utils/fstreewalk.h
1
#ifndef _FSTREEWALK_H_INCLUDED_
1
#ifndef _FSTREEWALK_H_INCLUDED_
2
#define _FSTREEWALK_H_INCLUDED_
2
#define _FSTREEWALK_H_INCLUDED_
3
/* @(#$Id: fstreewalk.h,v 1.3 2005-04-04 13:18:47 dockes Exp $  (C) 2004 J.F.Dockes */
3
/* @(#$Id: fstreewalk.h,v 1.4 2006-01-17 09:31:10 dockes Exp $  (C) 2004 J.F.Dockes */
4
4
5
#include <string>
5
#include <string>
6
#include <list>
6
7
7
#ifndef NO_NAMESPACES
8
#ifndef NO_NAMESPACES
8
using std::string;
9
using std::string;
10
using std::list;
9
#endif
11
#endif
10
12
11
class FsTreeWalkerCB;
13
class FsTreeWalkerCB;
12
14
15
/**
16
 * Class implementing a unix directory recursive walk.
17
 *
18
 * A user-defined function object is called for every file or
19
 * directory. Patterns to be ignored can be set before starting the
20
 * walk. Options control whether we follow symlinks and whether we recurse
21
 * on subdirectories.
22
 */
13
class FsTreeWalker {
23
class FsTreeWalker {
14
 public:
24
 public:
15
    enum CbFlag {FtwRegular, FtwDirEnter, FtwDirReturn};
25
    enum CbFlag {FtwRegular, FtwDirEnter, FtwDirReturn};
16
    enum Status {FtwOk=0, FtwError=1, FtwStop=2, 
26
    enum Status {FtwOk=0, FtwError=1, FtwStop=2, 
17
         FtwStatAll = FtwError|FtwStop};
27
         FtwStatAll = FtwError|FtwStop};
18
    enum Options {FtwOptNone = 0, FtwNoRecurse = 1, FtwFollow = 2};
28
    enum Options {FtwOptNone = 0, FtwNoRecurse = 1, FtwFollow = 2};
19
29
20
    FsTreeWalker(Options opts = FtwOptNone);
30
    FsTreeWalker(Options opts = FtwOptNone);
21
    ~FsTreeWalker();
31
    ~FsTreeWalker();
32
    /** 
33
     * Begin file system walk.
34
     * @param dir is not checked against the ignored patterns (this is 
35
     *     a feature and must not change.
36
     * @param cb the function object that will be called back for every 
37
     *    file-system object (called both at entry and exit for directories).
38
     */
22
    Status walk(const std::string &dir, FsTreeWalkerCB& cb);
39
    Status walk(const string &dir, FsTreeWalkerCB& cb);
40
    /** Get explanation for error */
23
    std::string getReason();
41
    string getReason();
24
    int getErrCnt();
42
    int getErrCnt();
43
    /**
44
     * Add a pattern to the list of things (file or dir) to be ignored
45
     * (ie: #* , *~)
46
     */
25
    bool addSkippedName(const std::string &pattern); // Add a pattern
47
    bool addSkippedName(const string &pattern); 
26
                           // for directory
48
    /** Set the ignored patterns list */
27
                           // entries (file
49
    bool setSkippedNames(const list<string> &patlist);
28
                           // or dir) to be
50
    /** Clear the ignored patterns list */
29
                           // ignored (ie:
51
    void clearSkippedNames();
30
                           // #* , *~)
31
    void clearSkippedNames(); // Clear all patterns
32
52
33
 private:
53
 private:
34
    class Internal;
54
    class Internal;
35
    Internal *data;
55
    Internal *data;
36
};
56
};