Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arene::base::filesystem::directory_handle Class Reference

Class to wrap a directory handle. More...

Public Types

enum class  unlink_type : std::uint8_t { directory , other }
 Flag type to indicate what is being unlinked. More...
 

Public Member Functions

 directory_handle () noexcept
 Construct a directory handle that doesn't refer to a directory.
 
 directory_handle (directory_handle &&source) noexcept
 Transfer ownership of a directory handle from source to *this.
 
 directory_handle (directory_handle const &)=delete
 Not copyable.
 
 directory_handle (file_handle source_handle)
 Obtain a directory handle from a file handle to the directory.
 
 ~directory_handle ()
 Close the directory handle.
 
auto create_file (null_terminated_string_view const relative_name) const noexcept -> result< file_handle, error_code >
 Create a file with the specified name relative to the directory referenced by *this and return a read-write handle to the new file. Fails if a file with the specified name already exists.
 
auto create_file (null_terminated_string_view relative_name, create_flags flags) const noexcept -> result< file_handle, error_code >
 Create a file or open an existing file with the specified name relative to the directory referenced by *this and return a read-write handle to the new file. The behaviour when there is already a file with the specified name is specified by the flags parameter.
 
auto create_subdirectory (null_terminated_string_view const dir_name) const noexcept -> result< void, error_code >
 Create a directory as a subdirectory of the directory referenced by *this, with the given name.
 
auto create_temporary_file () const noexcept -> result< file_handle, error_code >
 Create a temporary file with no name (or a transient random name) in the directory referenced by *this and return a read-write handle to the new file. Fails if a temporary file could not be created.
 
auto get_file_stats (null_terminated_string_view const relative_name) const noexcept -> result< struct stat, error_code >
 Get the file stats for the directory entry with the specified name relative to the directory referenced by *this.
 
auto next_entry () noexcept -> result< null_terminated_string_view, error_code >
 Advance to the next directory entry and return it. Ignores "." and ".." entries. Returns an ERANGE error if there are no more entries.
 
auto open_file (null_terminated_string_view const relative_name) const noexcept -> result< file_handle, error_code >
 Open a read-only handle to the file with the specified name relative to the directory referenced by *this.
 
auto open_file (null_terminated_string_view const relative_name, open_flags const flags) const noexcept -> result< file_handle, error_code >
 Open a handle to the file with the specified name relative to the directory referenced by *this, with permissions specified by the flags.
 
auto open_subdirectory (null_terminated_string_view const relative_name) const noexcept -> result< directory_handle, error_code >
 Open a handle to the directory with the specified name relative to the directory referenced by *this.
 
auto operator= (directory_handle &&source) noexcept -> directory_handle &
 Transfer ownership of a directory handle from source to *this. Closes any previous directory handle owned by *this.
 
auto operator= (directory_handle const &) -> directory_handle &=delete
 Not copyable.
 
auto rename (null_terminated_string_view const old_name, null_terminated_string_view const new_name) const noexcept -> result< void, error_code >
 Rename a file or directory from its existing name relative to the directory referenced by *this to the specified new name relative to the directory referenced by *this.
 
auto rewind () noexcept -> result< void, error_code >
 Rewind the directory handle to the start of the directory.
 
auto unlink_entry (null_terminated_string_view const relative_name, unlink_type const type) const noexcept -> result< void, error_code >
 Remove a directory entry with the specified name relative to the directory referenced by *this.
 
auto valid () const noexcept -> bool
 Check if the handle has a valid value.
 

Static Public Member Functions

static auto open (null_terminated_string_view const path) noexcept -> result< directory_handle, error_code >
 Open a handle to the directory with the specified absolute path or path relative to the current working directory.
 

Detailed Description

Class to wrap a directory handle.

Member Enumeration Documentation

◆ unlink_type

Flag type to indicate what is being unlinked.

Enumerator
directory 

A directory is being unlinked.

other 

Something that is not a directory is being unlinked.

Constructor & Destructor Documentation

◆ directory_handle() [1/4]

arene::base::filesystem::directory_handle::directory_handle ( )
inlinenoexcept

Construct a directory handle that doesn't refer to a directory.

◆ directory_handle() [2/4]

arene::base::filesystem::directory_handle::directory_handle ( file_handle source_handle)
explicit

Obtain a directory handle from a file handle to the directory.

Parameters
source_handleThe file handle for the directory
Exceptions
std::system_errorif an error occurs

◆ ~directory_handle()

arene::base::filesystem::directory_handle::~directory_handle ( )

Close the directory handle.

◆ directory_handle() [3/4]

arene::base::filesystem::directory_handle::directory_handle ( directory_handle && source)
inlinenoexcept

Transfer ownership of a directory handle from source to *this.

Parameters
sourceThe handle to transfer ownership from

◆ directory_handle() [4/4]

arene::base::filesystem::directory_handle::directory_handle ( directory_handle const & )
delete

Not copyable.

Member Function Documentation

◆ create_file() [1/2]

auto arene::base::filesystem::directory_handle::create_file ( null_terminated_string_view const relative_name) const -> result<file_handle, error_code>
noexcept

Create a file with the specified name relative to the directory referenced by *this and return a read-write handle to the new file. Fails if a file with the specified name already exists.

Parameters
relative_nameThe name of the file to create
Returns
A result holding a handle to the file if the file could be created, otherwise a result holding an error_code identifying the cause for the failure.

◆ create_file() [2/2]

auto arene::base::filesystem::directory_handle::create_file ( null_terminated_string_view relative_name,
create_flags flags ) const -> result<file_handle, error_code>
noexcept

Create a file or open an existing file with the specified name relative to the directory referenced by *this and return a read-write handle to the new file. The behaviour when there is already a file with the specified name is specified by the flags parameter.

Parameters
relative_nameThe name of the file to create
flagsThe creation flags
Returns
A result holding a handle to the file if the file could be created, otherwise a result holding an error_code identifying the cause for the failure.

◆ create_subdirectory()

auto arene::base::filesystem::directory_handle::create_subdirectory ( null_terminated_string_view const dir_name) const -> result<void, error_code>
noexcept

Create a directory as a subdirectory of the directory referenced by *this, with the given name.

Parameters
dir_nameThe name of the new directory to create
Returns
A result with a value if the directory was created, otherwise a result holding an error_code identifying the cause for the failure.

◆ create_temporary_file()

auto arene::base::filesystem::directory_handle::create_temporary_file ( ) const -> result<file_handle, error_code>
noexcept

Create a temporary file with no name (or a transient random name) in the directory referenced by *this and return a read-write handle to the new file. Fails if a temporary file could not be created.

Returns
A result holding a handle to the file if the file could be created, otherwise a result holding an error_code identifying the cause for the failure.

◆ get_file_stats()

auto arene::base::filesystem::directory_handle::get_file_stats ( null_terminated_string_view const relative_name) const -> result<struct stat, error_code>
noexcept

Get the file stats for the directory entry with the specified name relative to the directory referenced by *this.

Parameters
relative_nameThe name of the directory entry to check
Returns
The file stats for the directory entry, or nullopt if the directory entry doesn't exist
A result holding the file stats for the directory entry if they could be retrieved, otherwise a result holding an error_code identifying the cause for the failure.

◆ next_entry()

auto arene::base::filesystem::directory_handle::next_entry ( ) -> result<null_terminated_string_view, error_code>
noexcept

Advance to the next directory entry and return it. Ignores "." and ".." entries. Returns an ERANGE error if there are no more entries.

Returns
A result holding the name of the next entry on success, otherwise a result holding an error indicating the cause of failure. An error of ERANGE indicates that the end of the directory has been reached.

◆ open()

auto arene::base::filesystem::directory_handle::open ( null_terminated_string_view const path) -> result<directory_handle, error_code>
staticnoexcept

Open a handle to the directory with the specified absolute path or path relative to the current working directory.

Parameters
pathThe path of the directory to retrieve the handle for
Returns
A directory_handle for the directory, or nullopt if the directory doesn't exist
A result holding a handle to the directory if the directory could be opened, otherwise a result holding an error_code identifying the cause for the failure.

◆ open_file() [1/2]

auto arene::base::filesystem::directory_handle::open_file ( null_terminated_string_view const relative_name) const -> result<file_handle, error_code>
noexcept

Open a read-only handle to the file with the specified name relative to the directory referenced by *this.

Parameters
relative_nameThe name of the file to open
Returns
A result holding a handle to the file if the file could be opened, otherwise a result holding an error_code identifying the cause for the failure.

◆ open_file() [2/2]

auto arene::base::filesystem::directory_handle::open_file ( null_terminated_string_view const relative_name,
open_flags const flags ) const -> result<file_handle, error_code>
noexcept

Open a handle to the file with the specified name relative to the directory referenced by *this, with permissions specified by the flags.

Parameters
relative_nameThe name of the file to open
flagsThe flags to use for opening the file
Returns
A result holding a handle to the file if the file could be opened, otherwise a result holding an error_code identifying the cause for the failure.

◆ open_subdirectory()

auto arene::base::filesystem::directory_handle::open_subdirectory ( null_terminated_string_view const relative_name) const -> result<directory_handle, error_code>
noexcept

Open a handle to the directory with the specified name relative to the directory referenced by *this.

Parameters
relative_nameThe name of the directory to retrieve the handle for
Returns
A result holding a handle to the subdirectory if the directory could be opened, otherwise a result holding an error_code identifying the cause for the failure.

◆ operator=() [1/2]

auto arene::base::filesystem::directory_handle::operator= ( directory_handle && source) -> directory_handle&
noexcept

Transfer ownership of a directory handle from source to *this. Closes any previous directory handle owned by *this.

Parameters
sourceThe handle to transfer ownership from

◆ operator=() [2/2]

auto arene::base::filesystem::directory_handle::operator= ( directory_handle const & ) -> directory_handle &=delete
delete

Not copyable.

◆ rename()

auto arene::base::filesystem::directory_handle::rename ( null_terminated_string_view const old_name,
null_terminated_string_view const new_name ) const -> result<void, error_code>
noexcept

Rename a file or directory from its existing name relative to the directory referenced by *this to the specified new name relative to the directory referenced by *this.

Parameters
old_nameThe existing name of the file or directory
new_nameThe desired name of the file or directory
Returns
A result holding a value if the file or directory could be renamed, otherwise a result holding an error_code identifying the cause for the failure.

◆ rewind()

auto arene::base::filesystem::directory_handle::rewind ( ) -> result<void, error_code>
noexcept

Rewind the directory handle to the start of the directory.

Returns
A result holding a value on success, otherwise a result holding an error indicating the cause of failure.

◆ unlink_entry()

auto arene::base::filesystem::directory_handle::unlink_entry ( null_terminated_string_view const relative_name,
unlink_type const type ) const -> result<void, error_code>
noexcept

Remove a directory entry with the specified name relative to the directory referenced by *this.

Parameters
relative_nameThe name of the directory entry to check
typeA flag indicating if the directory entry is thought to be a directory (unlink_type::directory), or not (unlink_type::other)
Returns
A result with a value if the directory entry was removed, otherwise a result holding an error_code identifying the cause for the failure.

◆ valid()

auto arene::base::filesystem::directory_handle::valid ( ) const -> bool
inlinenoexcept

Check if the handle has a valid value.

Returns
true if the handle is valid, false otherwise

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