PMT Renovated main-branch
Partition Manager Tool is a fast, reliable, and feature-rich CLI application for Android devices that enables advanced partition operations such as backup, flashing, erasing, information retrieval, and more.
Loading...
Searching...
No Matches
Helper::BasicUniqueFD< Closer > Class Template Reference

A class that helps with easy file descriptor management. More...

#include <management.hpp>

Public Member Functions

 BasicUniqueFD ()=default
 Default constructor, initializes local class variables.
 
 BasicUniqueFD (const BasicUniqueFD &)=delete
 A class that claims the unique property cannot be copied.
 
 BasicUniqueFD (BasicUniqueFD &&other) noexcept
 Move constructor.
 
 BasicUniqueFD (const std::filesystem::path &path, int flags)
 Constructor that opens the file.
 
 BasicUniqueFD (const std::filesystem::path &path, int flags, mode_t mode)
 Constructor that opens the file with mode.
 
 BasicUniqueFD (int fd)
 A constructor that takes over the management of an existing file descriptor.
 
 ~BasicUniqueFD ()
 The destructor that closes the file descriptor.
 
BasicUniqueFDoperator= (const BasicUniqueFD &)=delete
 A class that claims the unique property cannot be copied.
 
BasicUniqueFDoperator= (BasicUniqueFD &&other) noexcept
 Mover = operator.
 
BasicUniqueFD's function declarations.

In-class declarations of functions that work with file descriptors.

int fd ()
 Get file descriptor.
 
int fd () const
 Get file descriptor.
 
int flags ()
 Get open() flags.
 
int flags () const
 Get open() flags.
 
std::optional< mode_t > mode ()
 It returns std::nullopt if no mode information is stored!
 
std::optional< mode_t > mode () const
 It returns std::nullopt if no mode information is stored!
 
std::filesystem::path path ()
 Get file path.
 
std::filesystem::path path () const
 Get file path.
 
BasicUniqueFDopen (bool withMode=false)
 Open.
 
BasicUniqueFDopen (const std::filesystem::path &path, int flags)
 Open input file.
 
BasicUniqueFDopen (const std::filesystem::path &path, int flags, mode_t mode)
 Open input file with mode.
 
bool reOpen (bool withMode=false)
 Class-specific function that reopens the file.
 
void close () noexcept
 
ssize_t read (void *buf, size_t count) const
 
ssize_t write (const void *buf, size_t count)
 
off_t lseek (off_t offset, int whence)
 
int fsync ()
 
template<typename... Args>
int fcntl (int op, Args... args)
 
template<typename... Args>
int ioctl (unsigned long cmd, Args... args)
 
int dup ()
 
int dup2 (int newfd)
 
BasicUniqueFD's operator declarations.

Definitions of operators required for int-style behavior.

bool operator! () const noexcept
 
 operator bool () const noexcept
 
int operator() () noexcept
 
int operator() () const noexcept
 
template<typename T >
requires std::is_integral_v<T>
bool operator< (T fd) const noexcept
 
template<typename T >
requires std::is_integral_v<T>
bool operator> (T fd) const noexcept
 
template<typename T >
requires std::is_integral_v<T>
bool operator<= (T fd) const noexcept
 
template<typename T >
requires std::is_integral_v<T>
bool operator>= (T fd) const noexcept
 
template<typename T >
requires std::is_integral_v<T>
bool operator== (T fd) const noexcept
 
template<typename T >
requires std::is_integral_v<T>
bool operator!= (T fd) const noexcept
 

Static Public Member Functions

static BasicUniqueFD getOwnership (int fd)
 An alternative to Helper::BasicUniqueFD(int fd)
 

Public Attributes

bool syncOnClose = true
 Turn on/off synchronization before closing (by object).
 

Detailed Description

template<typename Closer = Helper::Closer>
requires IsCloser<Closer, int>
class Helper::BasicUniqueFD< Closer >

A class that helps with easy file descriptor management.

auto sfd = BasicUniqueFD("file.txt", O_RDONLY);
// ... operations
BasicUniqueFD()=default
Default constructor, initializes local class variables.
Template Parameters
CloserCloser class. Helper::Closer used by default.
See also
Helper::IsCloser
Helper::IsCloserWithOperator
Helper::Closer

Constructor & Destructor Documentation

◆ BasicUniqueFD() [1/3]

template<typename Closer = Helper::Closer>
Helper::BasicUniqueFD< Closer >::BasicUniqueFD ( const std::filesystem::path path,
int  flags 
)
inline

Constructor that opens the file.

Parameters
pathFile path.
flagsOpen flags.
See also
open() flags

◆ BasicUniqueFD() [2/3]

template<typename Closer = Helper::Closer>
Helper::BasicUniqueFD< Closer >::BasicUniqueFD ( const std::filesystem::path path,
int  flags,
mode_t  mode 
)
inline

Constructor that opens the file with mode.

Parameters
pathFile path.
flagsOpen flags.
modeMode.
See also
open() flags
mode flags

◆ BasicUniqueFD() [3/3]

template<typename Closer = Helper::Closer>
Helper::BasicUniqueFD< Closer >::BasicUniqueFD ( int  fd)
inlineexplicit

A constructor that takes over the management of an existing file descriptor.

Parameters
fdFile descriptor.
See also
Helper::BasicUniqueFD::getOwnership

Member Function Documentation

◆ getOwnership()

template<typename Closer = Helper::Closer>
static BasicUniqueFD Helper::BasicUniqueFD< Closer >::getOwnership ( int  fd)
inlinestatic

An alternative to Helper::BasicUniqueFD(int fd)

Parameters
fdFile descriptor.
Returns
A BasicUniqueFD object that holds fd.

◆ open() [1/3]

template<typename Closer = Helper::Closer>
BasicUniqueFD & Helper::BasicUniqueFD< Closer >::open ( bool  withMode = false)
inline

Open.

Parameters
withModeOpen with mode or not.
Returns
*this

◆ open() [2/3]

template<typename Closer = Helper::Closer>
BasicUniqueFD & Helper::BasicUniqueFD< Closer >::open ( const std::filesystem::path path,
int  flags 
)
inline

Open input file.

Parameters
pathFile path.
flagsOpen flags.
Returns
*this
See also
open() flags

◆ open() [3/3]

template<typename Closer = Helper::Closer>
BasicUniqueFD & Helper::BasicUniqueFD< Closer >::open ( const std::filesystem::path path,
int  flags,
mode_t  mode 
)
inline

Open input file with mode.

Parameters
pathFile path.
flagsOpen flags.
modeMode.
Returns
*this
See also
open() flags
mode flags

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