lfilesystem  0.0.1
C++ filesystem library
limes::files::Permissions Class Referencefinal

This class encapsulates the standard library's permissions bitmask type, and provides some higher-level object oriented features for working with permissions. More...

#include <lfilesystem_Permissions.h>

Public Member Functions

 Permissions (const Permissions &)=default
 
 Permissions (Permissions &&)=default
 
Permissionsoperator= (const Permissions &)=default
 
Permissionsoperator= (FSPerms p) noexcept
 Assigns a new permissions bitmask to this object. More...
 
Permissionsoperator= (Permissions &&)=default
 
std::string toString () const
 Returns a string representation of these permissions of the form rwxrwxrwx , where the first three characters represent the owner scope, the next three the group scope, and the final three the others scope. More...
 
Constructors
 Permissions ()=default
 Creates a Permissions object holding the value FSPerms::none . More...
 
 Permissions (FSPerms p) noexcept
 Creates a Permissions object holding the specified permissions value. More...
 
Conversion to standard permissions type
 operator FSPerms () const noexcept
 Implicitly converts this Permissions object to the standard library permissions bitmask it holds. More...
 
FSPerms getStdPerms () const noexcept
 Returns the standard library permissions bitmask this object holds. More...
 
Equality comparisons
bool operator== (const Permissions &other) const noexcept
 Compares permissions for equality. More...
 
bool operator== (FSPerms p) const noexcept
 Compares permissions for equality. More...
 
Permissions queries
bool isUnknownOrEmpty () const noexcept
 Returns true if this permissions object holds the values FSPerms::none or FSPerms::unknown . More...
 
bool hasRead (Scope s=Scope::All) const noexcept
 Returns true if these permissions include read access for the specified scope. More...
 
bool hasWrite (Scope s=Scope::All) const noexcept
 Returns true if these permissions include write access for the specified scope. More...
 
bool hasExecute (Scope s=Scope::All) const noexcept
 Returns true if these permissions include execution access for the specified scope. More...
 
bool hasAll (Scope s=Scope::All) const noexcept
 Returns true if these permissions include read, write, and execution access for the specified scope. More...
 
bool hasStickyBit () const noexcept
 Returns true if these permissions have the sticky bit set. More...
 
Adding permissions
Permissions withRead (Scope s=Scope::All) const noexcept
 Returns a new permissions object that adds read access in the specified scope to this object's existing permissions. More...
 
Permissions withWrite (Scope s=Scope::All) const noexcept
 Returns a new permissions object that adds write access in the specified scope to this object's existing permissions. More...
 
Permissions withExecute (Scope s=Scope::All) const noexcept
 Returns a new permissions object that adds execution access in the specified scope to this object's existing permissions. More...
 
Permissions withAll (Scope s=Scope::All) const noexcept
 Returns a new permissions object that adds read, write, and execution access in the specified scope to this object's existing permissions. More...
 
Permissions withStickyBit () const noexcept
 Returns a new permissions object that adds the sticky bit to this object's existing permissions. More...
 

Static Public Member Functions

static Permissions all () noexcept
 Returns a Permissions object with read, write, and execution access for all computer users. More...
 
static Permissions fromString (const std::string_view &string) noexcept
 This function parses a string in the format returned by toString() . More...
 
static Permissions groupAll () noexcept
 Returns a Permissions object with read, write, and execution access for the file owner's user group. More...
 
static Permissions othersAll () noexcept
 Returns a Permissions object with read, write, and execution access for all users not in the file owner's user group. More...
 
static Permissions ownerAll () noexcept
 Returns a Permissions object with read, write, and execution access for the file owner. More...
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, const Permissions &value)
 Writes a Permissions object's string representation to the output stream. More...
 

Detailed Description

This class encapsulates the standard library's permissions bitmask type, and provides some higher-level object oriented features for working with permissions.

This class is incredibly light, as it holds only a single integral value, so don't be afraid to copy them around.

Definition at line 45 of file lfilesystem_Permissions.h.

Constructor & Destructor Documentation

◆ Permissions() [1/2]

limes::files::Permissions::Permissions ( )
default

Creates a Permissions object holding the value FSPerms::none .

◆ Permissions() [2/2]

limes::files::Permissions::Permissions ( FSPerms  p)
noexcept

Creates a Permissions object holding the specified permissions value.

Member Function Documentation

◆ all()

static Permissions limes::files::Permissions::all ( )
staticnoexcept

Returns a Permissions object with read, write, and execution access for all computer users.

◆ fromString()

static Permissions limes::files::Permissions::fromString ( const std::string_view &  string)
staticnoexcept

This function parses a string in the format returned by toString() .

See that function for a detailed description of the input string.

If the input string is not 9 characters long, this will return a Permissions object holding the unknown value. For each set of three characters, this function simply checks for the presence of r, w, and x characters in the expected positions; other incorrect or invalid inputs will not throw errors.

You can check if this function succeeded by calling isUnknownOrEmpty() on the returned Permissions object.

See also
toString()

◆ getStdPerms()

FSPerms limes::files::Permissions::getStdPerms ( ) const
noexcept

Returns the standard library permissions bitmask this object holds.

Todo:
test coverage

◆ groupAll()

static Permissions limes::files::Permissions::groupAll ( )
staticnoexcept

Returns a Permissions object with read, write, and execution access for the file owner's user group.

◆ hasAll()

bool limes::files::Permissions::hasAll ( Scope  s = Scope::All) const
noexcept

Returns true if these permissions include read, write, and execution access for the specified scope.

See also
withAll()

◆ hasExecute()

bool limes::files::Permissions::hasExecute ( Scope  s = Scope::All) const
noexcept

Returns true if these permissions include execution access for the specified scope.

See also
withExecute()

◆ hasRead()

bool limes::files::Permissions::hasRead ( Scope  s = Scope::All) const
noexcept

Returns true if these permissions include read access for the specified scope.

See also
withRead()

◆ hasStickyBit()

bool limes::files::Permissions::hasStickyBit ( ) const
noexcept

Returns true if these permissions have the sticky bit set.

This bit's effect is implementation-defined, but POSIX XSI specifies that when set on a directory, only file owners may delete files even if the directory is writeable to others (used with /tmp ).

See also
withStickyBit()
Todo:
test coverage

◆ hasWrite()

bool limes::files::Permissions::hasWrite ( Scope  s = Scope::All) const
noexcept

Returns true if these permissions include write access for the specified scope.

See also
withWrite()

◆ isUnknownOrEmpty()

bool limes::files::Permissions::isUnknownOrEmpty ( ) const
noexcept

Returns true if this permissions object holds the values FSPerms::none or FSPerms::unknown .

◆ operator FSPerms()

limes::files::Permissions::operator FSPerms ( ) const
noexcept

Implicitly converts this Permissions object to the standard library permissions bitmask it holds.

See also
getStdPerms()

◆ operator=()

Permissions& limes::files::Permissions::operator= ( FSPerms  p)
noexcept

Assigns a new permissions bitmask to this object.

◆ operator==() [1/2]

bool limes::files::Permissions::operator== ( const Permissions other) const
noexcept

Compares permissions for equality.

◆ operator==() [2/2]

bool limes::files::Permissions::operator== ( FSPerms  p) const
noexcept

Compares permissions for equality.

◆ othersAll()

static Permissions limes::files::Permissions::othersAll ( )
staticnoexcept

Returns a Permissions object with read, write, and execution access for all users not in the file owner's user group.

Todo:
test coverage

◆ ownerAll()

static Permissions limes::files::Permissions::ownerAll ( )
staticnoexcept

Returns a Permissions object with read, write, and execution access for the file owner.

◆ toString()

std::string limes::files::Permissions::toString ( ) const

Returns a string representation of these permissions of the form rwxrwxrwx , where the first three characters represent the owner scope, the next three the group scope, and the final three the others scope.

Each set of three characters consists of rwx , representing "read", "write", and "execute", and these characters will be replaced with a - if that permission is not present scope.

For example, if the only permissions set are read and write permission for the file owner, this function will return rw----— . If all other users can read the file, but not write to it, this function will return rw-r–r– . A file with all permissions set globally will return rwxrwxrwx .

See also
fromString()
Todo:
test coverage for unknown/empty case

◆ withAll()

Permissions limes::files::Permissions::withAll ( Scope  s = Scope::All) const
noexcept

Returns a new permissions object that adds read, write, and execution access in the specified scope to this object's existing permissions.

See also
hasAll()
Todo:
test coverage

◆ withExecute()

Permissions limes::files::Permissions::withExecute ( Scope  s = Scope::All) const
noexcept

Returns a new permissions object that adds execution access in the specified scope to this object's existing permissions.

See also
hasExecute()

◆ withRead()

Permissions limes::files::Permissions::withRead ( Scope  s = Scope::All) const
noexcept

Returns a new permissions object that adds read access in the specified scope to this object's existing permissions.

See also
hasRead()

◆ withStickyBit()

Permissions limes::files::Permissions::withStickyBit ( ) const
noexcept

Returns a new permissions object that adds the sticky bit to this object's existing permissions.

This bit's effect is implementation-defined, but POSIX XSI specifies that when set on a directory, only file owners may delete files even if the directory is writeable to others (used with /tmp ).

See also
hasStickyBit()
Todo:
test coverage

◆ withWrite()

Permissions limes::files::Permissions::withWrite ( Scope  s = Scope::All) const
noexcept

Returns a new permissions object that adds write access in the specified scope to this object's existing permissions.

See also
hasWrite()

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