VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
G::FileTree Class Reference

A class for walking files in a directory tree, with repositioning. More...

#include <gfiletree.h>

Public Member Functions

 FileTree ()
 Default contructor for an empty tree.
 
 FileTree (const G::Path &root, DirectoryTreeCallback *ignore=0)
 Constructor for the tree rooted at the given path. More...
 
void reroot (const G::Path &root)
 Resets the root, as if newly constructed.
 
G::Path root () const
 Returns the current root, as passed to the constructor or reroot(). More...
 
bool moved () const
 Returns true after construction, reroot(), first(), last() or a successful reposition(). More...
 
G::Path current () const
 Returns the current path.
 
G::Path next ()
 Moves to the next file in the tree, depth first, and returns the path. More...
 
bool reposition (const G::Path &path)
 Repositions the iterator within the current tree, at or after the given position. More...
 
int reposition (const G::Path &path, int)
 An overload that distinguishes the repositioning failure reason as (1) out-of-tree or (2) off-the-end. More...
 
bool last ()
 Repositions to the last position (so that next() will soon go off the end), or to the root() if currently reversed. More...
 
bool first ()
 Repositions to the root() position, or to the last position if currently reversed(). More...
 
void reverse (bool=true)
 Iterate in reverse, and reposition() to at-or-before rather than at-or-after. More...
 
bool reversed () const
 Returns true if currently reverse()d.
 
void swap (FileTree &other)
 Swaps this and other.
 

Detailed Description

A class for walking files in a directory tree, with repositioning.

The implementation uses G::DirectoryTree, transparently stepping over directories.

The iteration model is:

while( tree.next() != G::Path() )
{
if( fn( tree.current() ) )
tree.reposition(...) ;
}

Definition at line 50 of file gfiletree.h.

Constructor & Destructor Documentation

G::FileTree::FileTree ( const G::Path root,
DirectoryTreeCallback ignore = 0 
)
explicit

Constructor for the tree rooted at the given path.

(The optional ignore callback does not need to ignore directories; the FileTree class does that anyways.)

Definition at line 33 of file gfiletree.cpp.

Member Function Documentation

bool G::FileTree::first ( )

Repositions to the root() position, or to the last position if currently reversed().

Returns true if the current path changes. This re-examines the file-system, so the new position may be unexpectedly 'greater than' the previous position.

Definition at line 150 of file gfiletree.cpp.

bool G::FileTree::last ( )

Repositions to the last position (so that next() will soon go off the end), or to the root() if currently reversed.

Returns true if the current path changes. This re-examines the file-system, so the new position may be unexpectedly 'less than' the previous position.

Definition at line 134 of file gfiletree.cpp.

bool G::FileTree::moved ( ) const

Returns true after construction, reroot(), first(), last() or a successful reposition().

The moved() state is reset by next().

Definition at line 174 of file gfiletree.cpp.

G::Path G::FileTree::next ( )

Moves to the next file in the tree, depth first, and returns the path.

Returns the empty path if off the end or if default constructed. However, in the moved() state the first call to next() just returns current() and resets the moved() state. It is okay to call next() if currently off the end.

Definition at line 73 of file gfiletree.cpp.

bool G::FileTree::reposition ( const G::Path path)

Repositions the iterator within the current tree, at or after the given position.

The path does not have to represent an existing file or directory.

The given path should normally start with the root(). If the root is a relative path then the reposition() path should also be relative.

Returns false if there are no files at or after the required position or if the position is outside the tree, without changing the current iterator position.

Definition at line 92 of file gfiletree.cpp.

int G::FileTree::reposition ( const G::Path path,
int   
)

An overload that distinguishes the repositioning failure reason as (1) out-of-tree or (2) off-the-end.

Returns zero on success.

Definition at line 98 of file gfiletree.cpp.

void G::FileTree::reverse ( bool  in_reverse = true)

Iterate in reverse, and reposition() to at-or-before rather than at-or-after.

Definition at line 164 of file gfiletree.cpp.

G::Path G::FileTree::root ( ) const

Returns the current root, as passed to the constructor or reroot().

Returns the empty string if default constructed.

Definition at line 63 of file gfiletree.cpp.


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