UTILLib 2.0
Common C++ library with utilities.
Loading...
Searching...
No Matches
util::log::IDirectory Class Reference

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>

Public Member Functions

 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 DirectoryListDirectories () const
 Returns the sub-directory list.
const FileListFiles () const
 Returns a list files in the directory.
const FilterListExcludeList () const
 Returns a list of name filters.
FilterListExcludeList ()
 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 FilterListIncludeList () const
 Returns a list of name filters.
FilterListIncludeList ()
 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.

Protected Member Functions

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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ IDirectory()

util::log::IDirectory::IDirectory ( const std::string & dir_path)
explicit

Constructor by supplying a full path to a directory.

Parameters
dir_pathFull path to the directory.

Member Function Documentation

◆ 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
dirFull 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
nameName to test.
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
nameName to test.
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
levelRelative 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
ns1970Nano-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
textThe input string

◆ StringToIncludeList()

void util::log::IDirectory::StringToIncludeList ( const std::string & text)

Convert a string into an exclude list

Parameters
textThe input string

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