xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::filesystem::StandardPathIterator Class Reference

An iterator that traverses all directories in a standard system search path. More...

#include <filesystem/StandardPathIterator.hpp>

Public Types

using value_type = std::filesystem::path
 The value type.
 
using difference_type = std::ptrdiff_t
 Dummy type for non-existend difference type.
 
using pointer = const std::filesystem::path *
 A pointer to a value.
 
using reference = const std::filesystem::path &
 A reference to a value.
 
using iterator_concept = std::input_iterator_tag
 The iterator concept.
 
using iterator_category = iterator_concept
 The iterator category, for use in pre-C++20 code.
 

Public Member Functions

constexpr StandardPathIterator () noexcept=default
 Default constructor.
 
 StandardPathIterator (StandardPath type)
 Constructor for a certain type of search path.
 
constexpr StandardPathIterator (std::default_sentinel_t) noexcept
 Constructor for a sentinel.
 
auto operator== (const StandardPathIterator &rhs) const noexcept -> bool
 Equality operator.
 
auto operator== (std::default_sentinel_t) const noexcept -> bool
 Comparison with a sentinel.
 
auto operator* () const noexcept -> const std::filesystem::path &
 Accesses the current directory.
 
auto operator-> () const noexcept -> const std::filesystem::path *
 Accesses the current directory.
 
auto operator++ () -> StandardPathIterator &
 Fetches the next directory in the search path.
 

Related Symbols

(Note that these are not member symbols.)

auto begin (StandardPathIterator iterator) -> StandardPathIterator
 Gets a begin iterator for a standard path iterator.
 
auto end (StandardPathIterator) -> std::default_sentinel_t
 Gets an end iterator for a standard path iterator.
 

Detailed Description

An iterator that traverses all directories in a standard system search path.

This is an iterator object that can be used to iterate of all of the standard locations for a certain type of file. Standard path iterators are input iterators and can be used in algorithms that take an input iterator. Standard path iterators also supply freestanding [begin()](xentara::utils::windows::wmi::begin(StandardPathIterator)) and [end()](xentara::utils::windows::wmi::end(StandardPathIterator)) functions, so they can be used in range-based for loops:

auto iterateOverPaths(xentara::utils::filesystem::StandardPathIterator iterator) -> auto
{
for (auto &&path : iterator)
{
...
}
}
An iterator that traverses all directories in a standard system search path.
Definition StandardPathIterator.hpp:58

Genarally, however, it is easier to use an xentara::utils::filesystem::StandardPath enum value in the for loop directly:

for (auto &&path : xentara::utils::filesystem::StandardPath::Data)
{
...
}
StandardPath
Standard system search paths.
Definition StandardPathIterator.hpp:26
@ Data
Search path for data files.
Definition Optional.hpp:19
See also
StandardPath

Member Typedef Documentation

◆ difference_type

Dummy type for non-existend difference type.

◆ iterator_category

The iterator category, for use in pre-C++20 code.

◆ iterator_concept

◆ pointer

◆ reference

◆ value_type

Constructor & Destructor Documentation

◆ StandardPathIterator() [1/3]

constexpr xentara::utils::filesystem::StandardPathIterator::StandardPathIterator ( )
constexprdefaultnoexcept

Default constructor.

This constructor constructs a dummy itertor that does not iterate over any files.

Default constructed iterator compare equal to exhaused iterator, so they can be used as sentinels in algorithms that require the iterator and sentinel to be of the same type.

◆ StandardPathIterator() [2/3]

xentara::utils::filesystem::StandardPathIterator::StandardPathIterator ( StandardPath  type)

Constructor for a certain type of search path.

This constructor constructs an iterator pointing to the first directory in the given search path.

◆ StandardPathIterator() [3/3]

constexpr xentara::utils::filesystem::StandardPathIterator::StandardPathIterator ( std::default_sentinel_t  )
constexprnoexcept

Constructor for a sentinel.

This constructor constructs an object that compares equal to exhaused iterators, so it can be used as a sentinel in algorithms that require the iterator and sentinel to be of the same type.

This constructor is identical to the default constructor.

Member Function Documentation

◆ operator*()

auto xentara::utils::filesystem::StandardPathIterator::operator* ( ) const -> const std::filesystem::path &
noexcept

Accesses the current directory.

Precondition
Must not be called on an exhaused iterator

◆ operator++()

auto xentara::utils::filesystem::StandardPathIterator::operator++ ( ) -> StandardPathIterator &

Fetches the next directory in the search path.

Precondition
Must not be called on an exhaused iterator

◆ operator->()

auto xentara::utils::filesystem::StandardPathIterator::operator-> ( ) const -> const std::filesystem::path *
noexcept

Accesses the current directory.

Precondition
Must not be called on an exhaused iterator

◆ operator==() [1/2]

auto xentara::utils::filesystem::StandardPathIterator::operator== ( const StandardPathIterator rhs) const -> bool
noexcept

Equality operator.

A iterator only compares equal to itself, except exhaused iterators, that compare equal to all other exhaused iterators, including default constructed iterators. This allows using default constructed iterators as sentinels in algorithms that require the iterator and sentinel to be of the same type.

◆ operator==() [2/2]

auto xentara::utils::filesystem::StandardPathIterator::operator== ( std::default_sentinel_t  ) const -> bool
noexcept

Comparison with a sentinel.

Returns
Returns true if the iterator is exhaused, or false if it contains a valid directory.

Friends And Related Symbol Documentation

◆ begin()

auto begin ( StandardPathIterator  iterator) -> StandardPathIterator
related

Gets a begin iterator for a standard path iterator.

This function enables the use of StandardPathIterator in range-based for loops

Parameters
iteratorThe iterator to iterate over
Returns
Simply returns a copy of the iterator

◆ end()

auto end ( StandardPathIterator  ) -> std::default_sentinel_t
related

Gets an end iterator for a standard path iterator.

This function enables the use of StandardPathIterator in range-based for loops

Returns
The global default sentinel