Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:51

0001 //  boost/filesystem/file_status.hpp  --------------------------------------------------//
0002 
0003 //  Copyright Beman Dawes 2002-2009
0004 //  Copyright Jan Langer 2002
0005 //  Copyright Dietmar Kuehl 2001
0006 //  Copyright Vladimir Prus 2002
0007 //  Copyright Andrey Semashev 2019
0008 
0009 //  Distributed under the Boost Software License, Version 1.0.
0010 //  See http://www.boost.org/LICENSE_1_0.txt
0011 
0012 //  Library home page: http://www.boost.org/libs/filesystem
0013 
0014 //--------------------------------------------------------------------------------------//
0015 
0016 #ifndef BOOST_FILESYSTEM_FILE_STATUS_HPP
0017 #define BOOST_FILESYSTEM_FILE_STATUS_HPP
0018 
0019 #include <boost/filesystem/config.hpp>
0020 #include <boost/detail/bitmask.hpp>
0021 
0022 #include <boost/filesystem/detail/header.hpp> // must be the last #include
0023 
0024 //--------------------------------------------------------------------------------------//
0025 
0026 namespace boost {
0027 namespace filesystem {
0028 
0029 //--------------------------------------------------------------------------------------//
0030 //                                     file_type                                        //
0031 //--------------------------------------------------------------------------------------//
0032 
0033 enum file_type
0034 {
0035     status_error,
0036 #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
0037     status_unknown = status_error,
0038 #endif
0039     file_not_found,
0040     regular_file,
0041     directory_file,
0042     // the following may not apply to some operating systems or file systems
0043     symlink_file,
0044     block_file,
0045     character_file,
0046     fifo_file,
0047     socket_file,
0048     reparse_file, // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink
0049     type_unknown  // file does exist, but isn't one of the above types or
0050                   // we don't have strong enough permission to find its type
0051 };
0052 
0053 //--------------------------------------------------------------------------------------//
0054 //                                       perms                                          //
0055 //--------------------------------------------------------------------------------------//
0056 
0057 enum perms
0058 {
0059     no_perms = 0, // file_not_found is no_perms rather than perms_not_known
0060 
0061     // POSIX equivalent macros given in comments.
0062     // Values are from POSIX and are given in octal per the POSIX standard.
0063 
0064     // permission bits
0065 
0066     owner_read = 0400,  // S_IRUSR, Read permission, owner
0067     owner_write = 0200, // S_IWUSR, Write permission, owner
0068     owner_exe = 0100,   // S_IXUSR, Execute/search permission, owner
0069     owner_all = 0700,   // S_IRWXU, Read, write, execute/search by owner
0070 
0071     group_read = 040,  // S_IRGRP, Read permission, group
0072     group_write = 020, // S_IWGRP, Write permission, group
0073     group_exe = 010,   // S_IXGRP, Execute/search permission, group
0074     group_all = 070,   // S_IRWXG, Read, write, execute/search by group
0075 
0076     others_read = 04,  // S_IROTH, Read permission, others
0077     others_write = 02, // S_IWOTH, Write permission, others
0078     others_exe = 01,   // S_IXOTH, Execute/search permission, others
0079     others_all = 07,   // S_IRWXO, Read, write, execute/search by others
0080 
0081     all_all = 0777, // owner_all|group_all|others_all
0082 
0083     // other POSIX bits
0084 
0085     set_uid_on_exe = 04000, // S_ISUID, Set-user-ID on execution
0086     set_gid_on_exe = 02000, // S_ISGID, Set-group-ID on execution
0087     sticky_bit = 01000,     // S_ISVTX,
0088                             // (POSIX XSI) On directories, restricted deletion flag
0089                             // (V7) 'sticky bit': save swapped text even after use
0090                             // (SunOS) On non-directories: don't cache this file
0091                             // (SVID-v4.2) On directories: restricted deletion flag
0092                             // Also see http://en.wikipedia.org/wiki/Sticky_bit
0093 
0094     perms_mask = 07777, // all_all|set_uid_on_exe|set_gid_on_exe|sticky_bit
0095 
0096     perms_not_known = 0xFFFF, // present when directory_entry cache not loaded
0097 
0098     // options for permissions() function
0099 
0100     add_perms = 0x1000,    // adds the given permission bits to the current bits
0101     remove_perms = 0x2000, // removes the given permission bits from the current bits;
0102                            // choose add_perms or remove_perms, not both; if neither add_perms
0103                            // nor remove_perms is given, replace the current bits with
0104                            // the given bits.
0105 
0106     symlink_perms = 0x4000, // on POSIX, don't resolve symlinks; implied on Windows
0107 
0108     // BOOST_BITMASK op~ casts to int32_least_t, producing invalid enum values
0109     _detail_extend_perms_32_1 = 0x7fffffff,
0110     _detail_extend_perms_32_2 = -0x7fffffff - 1
0111 };
0112 
0113 BOOST_BITMASK(perms)
0114 
0115 //--------------------------------------------------------------------------------------//
0116 //                                    file_status                                       //
0117 //--------------------------------------------------------------------------------------//
0118 
0119 class file_status
0120 {
0121 public:
0122     BOOST_CONSTEXPR file_status() BOOST_NOEXCEPT :
0123         m_value(status_error),
0124         m_perms(perms_not_known)
0125     {
0126     }
0127     explicit BOOST_CONSTEXPR file_status(file_type v) BOOST_NOEXCEPT :
0128         m_value(v),
0129         m_perms(perms_not_known)
0130     {
0131     }
0132     BOOST_CONSTEXPR file_status(file_type v, perms prms) BOOST_NOEXCEPT :
0133         m_value(v),
0134         m_perms(prms)
0135     {
0136     }
0137 
0138     //  As of October 2015 the interaction between noexcept and =default is so troublesome
0139     //  for VC++, GCC, and probably other compilers, that =default is not used with noexcept
0140     //  functions. GCC is not even consistent for the same release on different platforms.
0141 
0142     BOOST_CONSTEXPR file_status(file_status const& rhs) BOOST_NOEXCEPT :
0143         m_value(rhs.m_value),
0144         m_perms(rhs.m_perms)
0145     {
0146     }
0147     BOOST_CXX14_CONSTEXPR file_status& operator=(file_status const& rhs) BOOST_NOEXCEPT
0148     {
0149         m_value = rhs.m_value;
0150         m_perms = rhs.m_perms;
0151         return *this;
0152     }
0153 
0154 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0155     // Note: std::move is not constexpr in C++11, that's why we're not using it here
0156     BOOST_CONSTEXPR file_status(file_status&& rhs) BOOST_NOEXCEPT :
0157         m_value(static_cast< file_type&& >(rhs.m_value)),
0158         m_perms(static_cast< perms&& >(rhs.m_perms))
0159     {
0160     }
0161     BOOST_CXX14_CONSTEXPR file_status& operator=(file_status&& rhs) BOOST_NOEXCEPT
0162     {
0163         m_value = static_cast< file_type&& >(rhs.m_value);
0164         m_perms = static_cast< perms&& >(rhs.m_perms);
0165         return *this;
0166     }
0167 #endif
0168 
0169     // observers
0170     BOOST_CONSTEXPR file_type type() const BOOST_NOEXCEPT { return m_value; }
0171     BOOST_CONSTEXPR perms permissions() const BOOST_NOEXCEPT { return m_perms; }
0172 
0173     // modifiers
0174     BOOST_CXX14_CONSTEXPR void type(file_type v) BOOST_NOEXCEPT { m_value = v; }
0175     BOOST_CXX14_CONSTEXPR void permissions(perms prms) BOOST_NOEXCEPT { m_perms = prms; }
0176 
0177     BOOST_CONSTEXPR bool operator==(file_status const& rhs) const BOOST_NOEXCEPT
0178     {
0179         return type() == rhs.type() && permissions() == rhs.permissions();
0180     }
0181     BOOST_CONSTEXPR bool operator!=(file_status const& rhs) const BOOST_NOEXCEPT
0182     {
0183         return !(*this == rhs);
0184     }
0185 
0186 private:
0187     file_type m_value;
0188     perms m_perms;
0189 };
0190 
0191 inline BOOST_CONSTEXPR bool type_present(file_status f) BOOST_NOEXCEPT
0192 {
0193     return f.type() != filesystem::status_error;
0194 }
0195 
0196 inline BOOST_CONSTEXPR bool permissions_present(file_status f) BOOST_NOEXCEPT
0197 {
0198     return f.permissions() != filesystem::perms_not_known;
0199 }
0200 
0201 inline BOOST_CONSTEXPR bool status_known(file_status f) BOOST_NOEXCEPT
0202 {
0203     return filesystem::type_present(f) && filesystem::permissions_present(f);
0204 }
0205 
0206 inline BOOST_CONSTEXPR bool exists(file_status f) BOOST_NOEXCEPT
0207 {
0208     return f.type() != filesystem::status_error && f.type() != filesystem::file_not_found;
0209 }
0210 
0211 inline BOOST_CONSTEXPR bool is_regular_file(file_status f) BOOST_NOEXCEPT
0212 {
0213     return f.type() == filesystem::regular_file;
0214 }
0215 
0216 inline BOOST_CONSTEXPR bool is_directory(file_status f) BOOST_NOEXCEPT
0217 {
0218     return f.type() == filesystem::directory_file;
0219 }
0220 
0221 inline BOOST_CONSTEXPR bool is_symlink(file_status f) BOOST_NOEXCEPT
0222 {
0223     return f.type() == filesystem::symlink_file;
0224 }
0225 
0226 inline BOOST_CONSTEXPR bool is_block_file(file_status f) BOOST_NOEXCEPT
0227 {
0228     return f.type() == filesystem::block_file;
0229 }
0230 
0231 inline BOOST_CONSTEXPR bool is_character_file(file_status f) BOOST_NOEXCEPT
0232 {
0233     return f.type() == filesystem::character_file;
0234 }
0235 
0236 inline BOOST_CONSTEXPR bool is_fifo(file_status f) BOOST_NOEXCEPT
0237 {
0238     return f.type() == filesystem::fifo_file;
0239 }
0240 
0241 inline BOOST_CONSTEXPR bool is_socket(file_status f) BOOST_NOEXCEPT
0242 {
0243     return f.type() == filesystem::socket_file;
0244 }
0245 
0246 inline BOOST_CONSTEXPR bool is_reparse_file(file_status f) BOOST_NOEXCEPT
0247 {
0248     return f.type() == filesystem::reparse_file;
0249 }
0250 
0251 inline BOOST_CONSTEXPR bool is_other(file_status f) BOOST_NOEXCEPT
0252 {
0253     return filesystem::exists(f) && !filesystem::is_regular_file(f) && !filesystem::is_directory(f) && !filesystem::is_symlink(f);
0254 }
0255 
0256 #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
0257 BOOST_FILESYSTEM_DETAIL_DEPRECATED("Use is_regular_file() instead")
0258 inline bool is_regular(file_status f) BOOST_NOEXCEPT
0259 {
0260     return filesystem::is_regular_file(f);
0261 }
0262 #endif
0263 
0264 } // namespace filesystem
0265 } // namespace boost
0266 
0267 #include <boost/filesystem/detail/footer.hpp> // pops abi_prefix.hpp pragmas
0268 
0269 #endif // BOOST_FILESYSTEM_FILE_STATUS_HPP