123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- #ifndef BOOST_FILESYSTEM_FILE_STATUS_HPP
- #define BOOST_FILESYSTEM_FILE_STATUS_HPP
- #include <boost/filesystem/config.hpp>
- #include <boost/detail/bitmask.hpp>
- #include <boost/filesystem/detail/header.hpp>
- namespace boost {
- namespace filesystem {
- enum file_type
- {
- status_error,
- file_not_found,
- regular_file,
- directory_file,
-
- symlink_file,
- block_file,
- character_file,
- fifo_file,
- socket_file,
- reparse_file,
- type_unknown
-
- };
- enum perms
- {
- no_perms = 0,
-
-
-
- owner_read = 0400,
- owner_write = 0200,
- owner_exe = 0100,
- owner_all = 0700,
- group_read = 040,
- group_write = 020,
- group_exe = 010,
- group_all = 070,
- others_read = 04,
- others_write = 02,
- others_exe = 01,
- others_all = 07,
- all_all = 0777,
-
- set_uid_on_exe = 04000,
- set_gid_on_exe = 02000,
- sticky_bit = 01000,
-
-
-
-
-
- perms_mask = 07777,
- perms_not_known = 0xFFFF,
-
- add_perms = 0x1000,
- remove_perms = 0x2000,
-
-
-
- symlink_perms = 0x4000,
-
- _detail_extend_perms_32_1 = 0x7fffffff,
- _detail_extend_perms_32_2 = -0x7fffffff - 1
- };
- BOOST_BITMASK(perms)
- class file_status
- {
- public:
- BOOST_CONSTEXPR file_status() noexcept :
- m_value(status_error),
- m_perms(perms_not_known)
- {
- }
- explicit BOOST_CONSTEXPR file_status(file_type v) noexcept :
- m_value(v),
- m_perms(perms_not_known)
- {
- }
- BOOST_CONSTEXPR file_status(file_type v, perms prms) noexcept :
- m_value(v),
- m_perms(prms)
- {
- }
- BOOST_CONSTEXPR file_status(file_status const& rhs) noexcept :
- m_value(rhs.m_value),
- m_perms(rhs.m_perms)
- {
- }
- BOOST_CXX14_CONSTEXPR file_status& operator=(file_status const& rhs) noexcept
- {
- m_value = rhs.m_value;
- m_perms = rhs.m_perms;
- return *this;
- }
-
- BOOST_CONSTEXPR file_status(file_status&& rhs) noexcept :
- m_value(static_cast< file_type&& >(rhs.m_value)),
- m_perms(static_cast< perms&& >(rhs.m_perms))
- {
- }
- BOOST_CXX14_CONSTEXPR file_status& operator=(file_status&& rhs) noexcept
- {
- m_value = static_cast< file_type&& >(rhs.m_value);
- m_perms = static_cast< perms&& >(rhs.m_perms);
- return *this;
- }
-
- BOOST_CONSTEXPR file_type type() const noexcept { return m_value; }
- BOOST_CONSTEXPR perms permissions() const noexcept { return m_perms; }
-
- BOOST_CXX14_CONSTEXPR void type(file_type v) noexcept { m_value = v; }
- BOOST_CXX14_CONSTEXPR void permissions(perms prms) noexcept { m_perms = prms; }
- BOOST_CONSTEXPR bool operator==(file_status const& rhs) const noexcept
- {
- return type() == rhs.type() && permissions() == rhs.permissions();
- }
- BOOST_CONSTEXPR bool operator!=(file_status const& rhs) const noexcept
- {
- return !(*this == rhs);
- }
- private:
- file_type m_value;
- perms m_perms;
- };
- inline BOOST_CONSTEXPR bool type_present(file_status f) noexcept
- {
- return f.type() != filesystem::status_error;
- }
- inline BOOST_CONSTEXPR bool permissions_present(file_status f) noexcept
- {
- return f.permissions() != filesystem::perms_not_known;
- }
- inline BOOST_CONSTEXPR bool status_known(file_status f) noexcept
- {
- return filesystem::type_present(f) && filesystem::permissions_present(f);
- }
- inline BOOST_CONSTEXPR bool exists(file_status f) noexcept
- {
- return f.type() != filesystem::status_error && f.type() != filesystem::file_not_found;
- }
- inline BOOST_CONSTEXPR bool is_regular_file(file_status f) noexcept
- {
- return f.type() == filesystem::regular_file;
- }
- inline BOOST_CONSTEXPR bool is_directory(file_status f) noexcept
- {
- return f.type() == filesystem::directory_file;
- }
- inline BOOST_CONSTEXPR bool is_symlink(file_status f) noexcept
- {
- return f.type() == filesystem::symlink_file;
- }
- inline BOOST_CONSTEXPR bool is_block_file(file_status f) noexcept
- {
- return f.type() == filesystem::block_file;
- }
- inline BOOST_CONSTEXPR bool is_character_file(file_status f) noexcept
- {
- return f.type() == filesystem::character_file;
- }
- inline BOOST_CONSTEXPR bool is_fifo(file_status f) noexcept
- {
- return f.type() == filesystem::fifo_file;
- }
- inline BOOST_CONSTEXPR bool is_socket(file_status f) noexcept
- {
- return f.type() == filesystem::socket_file;
- }
- inline BOOST_CONSTEXPR bool is_reparse_file(file_status f) noexcept
- {
- return f.type() == filesystem::reparse_file;
- }
- inline BOOST_CONSTEXPR bool is_other(file_status f) noexcept
- {
- return filesystem::exists(f) && !filesystem::is_regular_file(f) && !filesystem::is_directory(f) && !filesystem::is_symlink(f);
- }
- }
- }
- #include <boost/filesystem/detail/footer.hpp>
- #endif
|