The class is simple wrapper around a directory/file tree structure. It is typically used in applications that needs to keep track of file changes in a root directory.
More...
#include <idirectory.h>
|
| IDirectory ()=default |
| Default constructor.
|
| IDirectory (const IDirectory &source) |
| Copy constructor.
|
| IDirectory (const std::string &dir_path) |
| Constructor by supplying a full path to a directory.
|
virtual | ~IDirectory ()=default |
| Destructor.
|
std::string | Name () const |
| Returns the name of the directory without path.
|
void | Directory (const std::string &dir) |
| Sets the directory.
|
const std::string & | Directory () const |
| Returns the directory.
|
void | Modified (uint64_t ns1970) |
| Sets the last modified time.
|
uint64_t | Modified () const |
| Return last change time for the directory.
|
void | Level (size_t level) |
| Set the directory level.
|
size_t | Level () const |
| Returns the relative directory depth level.
|
const DirectoryList & | Directories () const |
| Returns the sub-directory list.
|
const FileList & | Files () const |
| Returns a list files in the directory.
|
const FilterList & | ExcludeList () const |
| Returns a list of name filters.
|
FilterList & | ExcludeList () |
| Returns a list of name filters.
|
std::string | ExcludeListToString () const |
| Converts a list into a text string.
|
void | StringToExcludeList (const std::string &text) |
| Convert a string into a exclude list.ยง
|
const FilterList & | IncludeList () const |
| Returns a list of name filters.
|
FilterList & | IncludeList () |
| Returns a list of name filters.
|
std::string | IncludeListToString () const |
| Converts a list into a text string.
|
void | StringToIncludeList (const std::string &text) |
| Convert a string into a include list.
|
virtual bool | ScanDirectory () |
| Scan the directory amd updated file and sub-directory lists.
|
const std::string & | LastError () const |
| Returns last error text.
|
|
bool | IncludeFile (const std::string &name) const |
| Checks if the name is matching anything in the include list.
|
bool | ExcludeFile (const std::string &name) const |
| Checks if the name is matching anything in the exclude list.
|
The class is intended to be used in application that needs to track changes of directories and files. It has a companion IFile class that is a wrapper around a file.
Typical usage is to create an IDirectory and attach it to a root directory. Then call the ScanDirectory() function to get a list of all directories. If not all files are wanted, it is possible to set both include and exclude filters.
◆ IDirectory()
util::log::IDirectory::IDirectory |
( |
const std::string & | dir_path | ) |
|
|
explicit |
Constructor by supplying a full path to a directory.
- Parameters
-
dir_path | Full path to the directory. |
◆ Directories()
const DirectoryList & util::log::IDirectory::Directories |
( |
| ) |
const |
|
inlinenodiscard |
Returns a list of sub-directories. Note that it returns a reference to an internal list.
- Returns
- List of directories.
◆ Directory() [1/2]
const std::string & util::log::IDirectory::Directory |
( |
| ) |
const |
|
inlinenodiscard |
Return the full path to the parent directory.
- Returns
- Full path to the parent directory.
◆ Directory() [2/2]
void util::log::IDirectory::Directory |
( |
const std::string & | dir | ) |
|
Sets the directory.
- Parameters
-
dir | Full path to the parent directory. |
◆ ExcludeFile()
bool util::log::IDirectory::ExcludeFile |
( |
const std::string & | name | ) |
const |
|
nodiscardprotected |
Returns true if the name matching any filter in the exclude list.
- Parameters
-
- Returns
- True if matching any filter else false.
◆ ExcludeList() [1/2]
FilterList & util::log::IDirectory::ExcludeList |
( |
| ) |
|
|
inlinenodiscard |
Returns a list if name filters. Names that match any of the filter will be excluded from the list of files. The non-const function is used when the filter list should be changed.
- Returns
- List of name filters.
◆ ExcludeList() [2/2]
const FilterList & util::log::IDirectory::ExcludeList |
( |
| ) |
const |
|
inlinenodiscard |
Returns a list if name filters. Names that match any of the filter will be excluded from the list of files.
- Returns
- List of name filters.
◆ ExcludeListToString()
std::string util::log::IDirectory::ExcludeListToString |
( |
| ) |
const |
|
nodiscard |
Returns the exclude list as a string. The function is used when exporting the list to a configuration file.
- Returns
- A string describing the list.
◆ Files()
const FileList & util::log::IDirectory::Files |
( |
| ) |
const |
|
inlinenodiscard |
Returns a sorted list of files in the directory.
- Returns
◆ IncludeFile()
bool util::log::IDirectory::IncludeFile |
( |
const std::string & | name | ) |
const |
|
nodiscardprotected |
Returns true if the name matching any filter in the include list.
- Parameters
-
- Returns
- True if matching any filter else false.
◆ IncludeList() [1/2]
FilterList & util::log::IDirectory::IncludeList |
( |
| ) |
|
|
inlinenodiscard |
Returns a list if name filters. Names that match any of the filter will be included in the list of files. The non-const function is used when the filter list should be changed.
- Returns
- List of name filters.
◆ IncludeList() [2/2]
const FilterList & util::log::IDirectory::IncludeList |
( |
| ) |
const |
|
inlinenodiscard |
Returns a list if name filters. Names that match any of the filter will be included in the list of files.
- Returns
- List of name filters.
◆ IncludeListToString()
std::string util::log::IDirectory::IncludeListToString |
( |
| ) |
const |
|
nodiscard |
Returns the include list as a string. The function is used when exporting the list to a configuration file.
- Returns
- A string describing the list.
◆ LastError()
const std::string & util::log::IDirectory::LastError |
( |
| ) |
const |
|
inlinenodiscard |
Returns the last error text.
- Returns
- The last error text.
◆ Level() [1/2]
size_t util::log::IDirectory::Level |
( |
| ) |
const |
|
inlinenodiscard |
Returns the relative directory depth.
- Returns
- Relative directory depth.
◆ Level() [2/2]
void util::log::IDirectory::Level |
( |
size_t | level | ) |
|
|
inline |
Sets the relative directory deep to the root directory. See also the ScanDirectory() function. It is default set to 0.
- Parameters
-
level | Relative directory deep level. |
◆ Modified() [1/2]
uint64_t util::log::IDirectory::Modified |
( |
| ) |
const |
|
inlinenodiscard |
Returns the last change time of the directory. This indicate adding or deleting of files.
- Returns
- Nano-seconds since 1970-01-01 (UTC)
◆ Modified() [2/2]
void util::log::IDirectory::Modified |
( |
uint64_t | ns1970 | ) |
|
|
inline |
Sets the last modified time. Note that the user should normally not use this function.
- Parameters
-
ns1970 | Nano-seconds since 1970 (UTC) |
◆ Name()
std::string util::log::IDirectory::Name |
( |
| ) |
const |
|
nodiscard |
Returns the name of the directory without its path a.k.a the stem.
- Returns
- Name of the directory
◆ ScanDirectory()
virtual bool util::log::IDirectory::ScanDirectory |
( |
| ) |
|
|
virtual |
The function scans the directory and update its sub-directory and file lists. The top-most directory i.e. the root directory level is set to 0 while its sub-directories level are set to 1.
- Returns
- True if the scan was successful.
◆ StringToExcludeList()
void util::log::IDirectory::StringToExcludeList |
( |
const std::string & | text | ) |
|
Convert a string into an exclude list
- Parameters
-
◆ StringToIncludeList()
void util::log::IDirectory::StringToIncludeList |
( |
const std::string & | text | ) |
|
Convert a string into an exclude list
- Parameters
-
The documentation for this class was generated from the following file: