FileTraverser Class Reference

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

#include <FileTraverser.h++>

Collaboration diagram for FileTraverser:

Collaboration graph
[legend]

List of all members.

Public Member Functions

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

Protected Member Functions

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


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 ( const String basePath,
bool  depthFirst = true 
)

Construct a new FileTraverser rooted at the given base path.

Parameters:
basePath The base path at which traversal will begin.
depthFirst If true, traversal will be depth-first; otherwise it will be breadth-first.

~FileTraverser (  )  throw () [virtual]

Destructor.


Member Function Documentation

bool handleError ( const FileName name,
const IOException ex 
) [protected, virtual]

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:
name The filename for which the error occurred.
ex The exception indicating the error.
Returns:
true if traversal should continue, false otherwise.

virtual bool processFile ( const FileName name,
bool  isDir,
uint_t  depth 
) [protected, pure virtual]

Process the next file or directory encountered.

Parameters:
name The filename.
isDir A flag indicating whether the file is a directory.
depth The current traversal depth.
Returns:
true if traversal should continue, false otherwise.

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:
pattern The prune pattern.

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:

Generated on Sat Apr 17 23:03:08 2010 for libcommonc++ by  doxygen 1.5.9