E-MailRelay
Classes | Public Member Functions | Static Public Member Functions | List of all members
G::DirectoryList Class Reference

A iterator similar to G::DirectoryIterator but doing all file i/o in one go and providing a sorted result. More...

#include <gdirectory.h>

Classes

struct  Item
 A directory-entry item for G::DirectoryList. More...
 

Public Member Functions

 DirectoryList ()
 Default constructor for an empty list. More...
 
std::size_t readAll (const Path &dir)
 An initialiser that is to be used after default construction. More...
 
std::size_t readType (const Path &dir, std::string_view suffix, unsigned int limit=0U)
 An initialiser that is to be used after default construction. More...
 
std::size_t readDirectories (const Path &dir, unsigned int limit=0U)
 An initialiser that reads all sub-directories. More...
 
bool empty () const noexcept
 Returns true if empty. More...
 
bool more ()
 Returns true if more and advances by one. More...
 
bool isDir () const
 Returns true if the current item is a directory. More...
 
bool isLink () const
 Returns true if the current item is a symlink. More...
 
Path filePath () const
 Returns the current path. More...
 
std::string fileName () const
 Returns the current filename. More...
 

Static Public Member Functions

static void readAll (const Path &dir, std::vector< Item > &out)
 A static overload returning by reference a collection of Items, sorted by name. More...
 

Detailed Description

A iterator similar to G::DirectoryIterator but doing all file i/o in one go and providing a sorted result.

This can be useful when temporarily adopting additional process privileges to read a directory.

Definition at line 149 of file gdirectory.h.

Constructor & Destructor Documentation

◆ DirectoryList()

G::DirectoryList::DirectoryList ( )
default

Default constructor for an empty list.

Initialise with one of the three read methods to do all the file i/o in one go.

Member Function Documentation

◆ empty()

bool G::DirectoryList::empty ( ) const
noexcept

Returns true if empty.

Definition at line 124 of file gdirectory.cpp.

◆ fileName()

std::string G::DirectoryList::fileName ( ) const

Returns the current filename.

Definition at line 163 of file gdirectory.cpp.

◆ filePath()

G::Path G::DirectoryList::filePath ( ) const

Returns the current path.

Definition at line 158 of file gdirectory.cpp.

◆ isDir()

bool G::DirectoryList::isDir ( ) const

Returns true if the current item is a directory.

Definition at line 153 of file gdirectory.cpp.

◆ isLink()

bool G::DirectoryList::isLink ( ) const

Returns true if the current item is a symlink.

Definition at line 147 of file gdirectory.cpp.

◆ more()

bool G::DirectoryList::more ( )

Returns true if more and advances by one.

Definition at line 130 of file gdirectory.cpp.

◆ readAll() [1/2]

std::size_t G::DirectoryList::readAll ( const Path dir)

An initialiser that is to be used after default construction.

Reads all files in the directory.

Definition at line 82 of file gdirectory.cpp.

◆ readAll() [2/2]

void G::DirectoryList::readAll ( const Path dir,
std::vector< Item > &  out 
)
static

A static overload returning by reference a collection of Items, sorted by name.

Definition at line 74 of file gdirectory.cpp.

◆ readDirectories()

std::size_t G::DirectoryList::readDirectories ( const Path dir,
unsigned int  limit = 0U 
)

An initialiser that reads all sub-directories.

Definition at line 88 of file gdirectory.cpp.

◆ readType()

std::size_t G::DirectoryList::readType ( const Path dir,
std::string_view  suffix,
unsigned int  limit = 0U 
)

An initialiser that is to be used after default construction.

Reads all files that have the given suffix (unsorted).

Definition at line 94 of file gdirectory.cpp.


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