libcommonc++  0.7
FileTraverser Class Referenceabstract

A depth- or breadth-first file traverser. More...

#include <FileTraverser.h++>

Inheritance diagram for FileTraverser:

Public Member Functions

 FileTraverser (const String &basePath, bool depthFirst=true)
 Construct a new FileTraverser rooted at the given base path. More...
 
virtual ~FileTraverser ()
 Destructor. More...
 
void setPrunePattern (const RegExp &pattern)
 Set a prune pattern for the traverser. More...
 
bool traverse ()
 Traverse the file tree. More...
 

Protected Member Functions

virtual bool processFile (const FileName &name, bool isDir, uint_t depth)=0
 Process the next file or directory encountered. More...
 
virtual bool handleError (const FileName &name, const IOException &ex)
 Handle an exception during traversal. More...
 

Detailed Description

A depth- or breadth-first file traverser.

This is an abstract class; subclasses must implement the processFile() function to process each file and directory encountered during the traversal.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ FileTraverser()

FileTraverser ( const String basePath,
bool  depthFirst = true 
)

Construct a new FileTraverser rooted at the given base path.

Parameters
basePathThe base path at which traversal will begin.
depthFirstIf true, traversal will be depth-first; otherwise it will be breadth-first.

◆ ~FileTraverser()

~FileTraverser ( )
virtual

Destructor.

Member Function Documentation

◆ handleError()

bool handleError ( const FileName name,
const IOException ex 
)
protectedvirtual

Handle an exception during traversal.

The method should return true if traversal should continue, false otherwise. The default implementation is a no-op that simply returns false.

Parameters
nameThe filename for which the error occurred.
exThe exception indicating the error.
Returns
true if traversal should continue, false otherwise.

◆ processFile()

virtual bool processFile ( const FileName name,
bool  isDir,
uint_t  depth 
)
protectedpure virtual

Process the next file or directory encountered.

Parameters
nameThe filename.
isDirA flag indicating whether the file is a directory.
depthThe current traversal depth.
Returns
true if traversal should continue, false otherwise.

◆ setPrunePattern()

void setPrunePattern ( const RegExp pattern)
inline

Set a prune pattern for the traverser.

Any file or directory whose name matches the given pattern will be skipped during traversal. Setting a null pattern disables pruning.

Parameters
patternThe prune pattern.

◆ traverse()

bool traverse ( )

Traverse the file tree.

Returns
true if the traversal completed successfully, false otherwise.

The documentation for this class was generated from the following files: