lfilesystem  0.0.1
C++ filesystem library
lfilesystem_Permissions.h
Go to the documentation of this file.
1 /*
2  * ======================================================================================
3  * __ ____ __ __ ____ ___
4  * ( ) (_ _)( \/ )( ___)/ __)
5  * )(__ _)(_ ) ( )__) \__ \
6  * (____)(____)(_/\/\_)(____)(___/
7  *
8  * This file is part of the Limes open source library and is licensed under the terms of the GNU Public License.
9  *
10  * Commercial licenses are available; contact the maintainers at ben.the.vining@gmail.com to inquire for details.
11  *
12  * ======================================================================================
13  */
14 
15 #pragma once
16 
17 #include <filesystem>
18 #include <string>
19 #include <string_view>
20 #include <ostream>
21 #include "lfilesystem/lfilesystem_Export.h"
22 
28 namespace limes::files
29 {
30 
34 using FSPerms = std::filesystem::perms;
35 
45 class LFILE_EXPORT Permissions final
46 {
47 public:
50 
52  Permissions() = default;
53 
55  Permissions (FSPerms p) noexcept; // cppcheck-suppress noExplicitConstructor
56 
58 
61 
67  operator FSPerms() const noexcept;
68 
72  [[nodiscard]] FSPerms getStdPerms() const noexcept;
73 
75 
76  Permissions (const Permissions&) = default;
77  Permissions& operator= (const Permissions&) = default;
78 
79  Permissions (Permissions&&) = default;
80  Permissions& operator= (Permissions&&) = default;
81 
83  Permissions& operator= (FSPerms p) noexcept;
84 
87 
89  bool operator== (const Permissions& other) const noexcept;
90  bool operator== (FSPerms p) const noexcept;
91 
93 
99  enum class LFILE_EXPORT Scope
100  {
104  All
105  };
106 
109 
113  bool isUnknownOrEmpty() const noexcept;
114 
118  bool hasRead (Scope s = Scope::All) const noexcept;
119 
123  bool hasWrite (Scope s = Scope::All) const noexcept;
124 
128  bool hasExecute (Scope s = Scope::All) const noexcept;
129 
135  bool hasAll (Scope s = Scope::All) const noexcept;
136 
147  bool hasStickyBit() const noexcept;
148 
150 
153 
159  [[nodiscard]] Permissions withRead (Scope s = Scope::All) const noexcept;
160 
166  [[nodiscard]] Permissions withWrite (Scope s = Scope::All) const noexcept;
167 
173  [[nodiscard]] Permissions withExecute (Scope s = Scope::All) const noexcept;
174 
182  [[nodiscard]] Permissions withAll (Scope s = Scope::All) const noexcept;
183 
195  [[nodiscard]] Permissions withStickyBit() const noexcept;
196 
198 
214  [[nodiscard]] std::string toString() const;
215 
229  [[nodiscard]] static Permissions fromString (const std::string_view& string) noexcept;
230 
232  [[nodiscard]] static Permissions ownerAll() noexcept;
233 
237  [[nodiscard]] static Permissions groupAll() noexcept;
238 
244  [[nodiscard]] static Permissions othersAll() noexcept;
245 
248  [[nodiscard]] static Permissions all() noexcept;
249 
250 private:
251  FSPerms perms { FSPerms::none };
252 };
253 
259 std::ostream& operator<< (std::ostream& os, const Permissions& value);
260 
261 } // namespace limes::files
This class encapsulates the standard library's permissions bitmask type, and provides some higher-lev...
Permissions(FSPerms p) noexcept
Creates a Permissions object holding the specified permissions value.
Permissions()=default
Creates a Permissions object holding the value FSPerms::none .
bool isUnknownOrEmpty() const noexcept
Returns true if this permissions object holds the values FSPerms::none or FSPerms::unknown .
std::filesystem::perms FSPerms
A typedef for the standard library permissions type.
Owner
This scope includes only the owner of the file.
Others
This scope includes all users outside the file's user group.
Group
This scope includes the file's user group.
Filesystem utilities.