72 using entry = child_list::value_type;
108 template<
typename Filter>
144 node * hit =
nullptr;
148 hit = where->second.get();
226 template<
typename Filter>
248 template<
typename Filter>
258 #ifdef FILETREE_DEBUG
259 static void display(std::string
const &
name,
260 node const * n,
unsigned indent = 0);
306 virtual void at_file(std::string
const & filename) {};
356 template<
typename Filter = file_tree::no_filter>
357 void add(std::string
const &
path, Filter & filter) {
360 #ifdef FILETREE_DEBUG
361 node::display(
"ROOT",&
_root,0);
378 template<
class InIter,
class Filter = file_tree::no_filter>
379 void add(InIter start, InIter end, Filter & filter) {
380 for ( ; start != end;
add(*start++,filter)) {}
unsigned intermediate_insert(path_t &abs_path, Filter &filter)
Recursively insert files within a path into the node.
void traverse(traverser &action) const
Traverse the node recursively, performing an action at each node encountered.
unsigned files() const
Get the number of files in the file_tree
unsigned insert(path_t &abs_path, Filter &filter)
Recursively insert files within a path into the node.
virtual void enter_dir(std::string const &dirname)
Do something (or nohting) on entering a directory.
node * ancestral_candidate_for_real_path(path_t const &cur_path, path_t const &real_path)
Ancestor probe for symbolic links.
node * _parent
Pointer to the parent node, or nullptr
node _root
The root node of the file_tree.
std::map< std::string, node_ptr > child_list
Type of sequence of children of a node.
virtual void leave_dir(std::string const &dirname)
Do something (or nohting) on leaving a directory.
Type representing the null filter for selecting files.
child_list::value_type entry
Type of an element in a child_list.
node const * _cur_dir
Pointer the node representing the latest directory that traversal has reached.
Type of a node in a file_tree.
unsigned terminal_insert(path_t &abs_path, Filter &filter)
Recursively insert files within a path into the node.
bool operator()(std::string const &) const
The null filter returns true for every filename.
node::child_list child_list
Type of a sequence of sibling nodes in a file_tree
virtual ~traverser()=default
Destructor.
A base for classes employed to traverse a file_tree.
Encapsulates a set of directory/file trees.
node * root()
Get a pointer to the root node of the node.
node * parent() const
Get a pointer to the parent of this node, which may be nullptr
node(child_list_ptr children)
Explicitly construct a node with a given child_list
bool is_dir() const
Say whether the node represents a directory.
A utility class to prevent copying of containing class.
node * find(std::string const &key)
Test whether this node contains a given key.
node::node_ptr node_ptr
Type of a pointer to a node
void add(std::string const &path, Filter &filter)
Add files from a path to the file_tree.
void operator()(entry const &entry)
Apply the traverser function-wise to an element of a file_tree.
std::shared_ptr< node > node_ptr
Type of a pointer to a node.
node(node *parent=nullptr)
Private default constructor.
chew_mode::name const name
An exemplar chew_mode::name
void traverse(traverser &action)
Traverse the file_tree.
node::entry entry
Type of an element in a child_list.
std::shared_ptr< child_list > _children
Pointer to the immediate children of the node, or nullptr
path_t _cur_path
The absolute path of the object that traversal has reached.
node * guardian(std::string const &key) const
Test whether the parent of this node contains a given key.
virtual void at_file(std::string const &filename)
Do something (or nothing) on reaching a file.
file_tree()
Default constructor.
bool is_file() const
Say whether the node represents a file.
std::string abs_path(std::string const &filename)
Get the absolute pathname for a filename.
std::string real_path(std::string const &relname)
Get the absolute real pathname of a file or directory name.
std::shared_ptr< child_list > child_list_ptr
Type of a pointer to a child_list
unsigned _files
The number of files in the file_tree.
void add(InIter start, InIter end, Filter &filter)
Add files from a path to the file_tree.