Files CCore/inc/DirTreeRun.h CCore/src/DirTreeRun.cpp
The class DirTreeRun can recursively iterate a directory content.
class DirTreeRun : NoCopy
{
....
public:
explicit DirTreeRun(StrLen root);
~DirTreeRun();
StrLen pathOfRoot(char buf[MaxPathLen+1]);
template <class Proc>
void apply(Proc &proc);
};
Constructor prepares the object, the argument is a root directory (the content of this directory to be iterated).
pathOfRoot() creates a full path of the root directory in the provided buffer and returns it.
apply() is the main working method. It takes a reference to a processing object. Methods of the object are called per each directory entry.
The class Proc must implement the following interface:
class Proc
{
public:
using DataType = ??? ;
DataType * dir(StrLen root);
DataType * dir(StrLen path,StrLen name,DataType *parent_data);
void file(StrLen path,StrLen name,DataType *parent_data);
void enddir(StrLen path,StrLen name,DataType *data);
};
During directory iteration an object of the type DataType is created per each directory.
The first method dir() is called for the root directory. The root is the root directory path. The method creates a data object for this directory and returns the pointer to it.
The second method dir() is called per each subdirectory. The path is the path of the parent directory and the name is the directory name. The parent_data is the pointer to the parent directory data object. The method creates a data object for this directory and returns the pointer to it.
The method file() is called per each file. The path is the path of the parent directory and the name is the file name. The parent_data is the pointer to the parent directory data object.
The method enddir() is called once the directory content is iterated. The path is the path of the parent directory and the name is the directory name. The data is the pointer to the directory data object.