35 m_root(root.collapsed()) ,
36 m_p(m_root,false,callback) ,
40 while( m_p != end && (*m_p).m_is_dir )
47 swap( m_moved , other.m_moved ) ;
48 swap( m_root , other.m_root ) ;
49 swap( m_p , other.m_p ) ;
50 swap( m_callback , other.m_callback ) ;
59 while( m_p != end && (*m_p).m_is_dir )
85 while( m_p != end && (*m_p).m_is_dir )
94 int rc = reposition( path , 0 ) ;
101 if( relative_path ==
G::Path() )
105 if( parts.size() == 1U && parts.at(0U) ==
"." )
110 size_t i = 0U ;
for( ; i < parts.size() ; i++ )
112 const std::string & part = parts.at(i) ;
113 G_DEBUG(
"G::FileTree::reposition: part: [" << part <<
"]" ) ;
114 if( p != end && (*p).m_is_dir && p.down( part ,
true ) )
120 if( p != end && i < parts.size() )
123 while( p != end && (*p).m_is_dir )
140 while( p != end && (*p).m_is_dir )
143 bool changed = m_p != p ;
145 m_p.reverse( is_reversed ) ;
155 while( p != end && (*p).m_is_dir )
158 bool changed = m_p != p ;
166 m_p.reverse( in_reverse ) ;
171 return m_p.reversed() ;
A class for walking files in a directory tree, with repositioning.
A directory tree iterator for sorted, depth-first traversal of files and directories.
FileTree()
Default contructor for an empty tree.
std::vector< std::string > StringArray
A std::vector of std::strings.
void reroot(const G::Path &root)
Resets the root, as if newly constructed.
bool reposition(const G::Path &path)
Repositions the iterator within the current tree, at or after the given position. ...
void reverse(bool=true)
Iterate in reverse, and reposition() to at-or-before rather than at-or-after.
void swap(FileTree &other)
Swaps this and other.
static Path difference(const Path &p1, const Path &p2)
Returns the relative path from p1 to p2.
bool reversed() const
Returns true if currently reverse()d.
G::Path current() const
Returns the current path.
StringArray split() const
Spits the path into a list of component parts (ignoring "." parts unless the whole path is "...
bool moved() const
Returns true after construction, reroot(), first(), last() or a successful reposition().
Path collapsed() const
Returns the path with "foo/.." and "." parts removed, so far as is possible without changing the mean...
void swap(DirectoryTree &other)
Swaps this and other.
bool first()
Repositions to the root() position, or to the last position if currently reversed().
bool reversed() const
Returns the current reversal state.
G::Path next()
Moves to the next file in the tree, depth first, and returns the path.
G::Path root() const
Returns the current root, as passed to the constructor or reroot().
A callback interface to allow G::DirectoryTree to ignore paths.
A Path object represents a file system path.
bool last()
Repositions to the last position (so that next() will soon go off the end), or to the root() if curre...