From d087e393bf48bf4bb7d190bbc7ab0f6ea4feb65e Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Mon, 13 Jun 2005 14:14:16 +0000 Subject: [PATCH] change status_flag to status_flags [SVN r29552] --- example/simple_ls.cpp | 12 ++++++-- include/boost/filesystem/config.hpp | 8 ++++++ include/boost/filesystem/operations.hpp | 38 ++++++++++++------------- src/operations.cpp | 16 +++++------ 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/example/simple_ls.cpp b/example/simple_ls.cpp index 0523e0d..c3245f2 100644 --- a/example/simple_ls.cpp +++ b/example/simple_ls.cpp @@ -10,12 +10,14 @@ #include "boost/filesystem/operations.hpp" #include "boost/filesystem/path.hpp" +#include "boost/progress.hpp" #include namespace fs = boost::filesystem; int main( int argc, char* argv[] ) { + boost::progress_timer t( std::clog ); fs::path full_path( fs::initial_path() ); @@ -46,12 +48,18 @@ int main( int argc, char* argv[] ) { try { - if ( fs::is_directory( *dir_itr ) ) +#if 1 + fs::status_flag flags( fs::status( *dir_itr ) ); +#else + fs::status_flag flags( fs::file_flag ); +#endif + + if ( (flags & fs::directory_flag) == fs::directory_flag ) { ++dir_count; std::cout << dir_itr->leaf() << " [directory]\n"; } - else if ( fs::is_file( *dir_itr ) ) + else if ( (flags & fs::file_flag) == fs::file_flag ) { ++file_count; std::cout << dir_itr->leaf() << "\n"; diff --git a/include/boost/filesystem/config.hpp b/include/boost/filesystem/config.hpp index cad29bb..b04dbfa 100644 --- a/include/boost/filesystem/config.hpp +++ b/include/boost/filesystem/config.hpp @@ -39,6 +39,14 @@ # define BOOST_WINDOWS_PATH # endif +// BOOST_FILESYSTEM_STATUS_CACHE enables status_flags cache in +// basic_directory_iterator -----------------------------------------------// + +// TODO: find out how Linux, others, enable dirent::d_type. __USE_BSD???? +# if defined(BOOST_WINDOWS_API) || defined(__APPLE__) +# define BOOST_FILESYSTEM_STATUS_CACHE +# endif + // narrow support only for badly broken compilers or libraries -------------// # if defined(BOOST_NO_STD_WSTRING) || defined(BOOST_NO_SFINAE) || defined(BOOST_NO_STD_LOCALE) diff --git a/include/boost/filesystem/operations.hpp b/include/boost/filesystem/operations.hpp index b488cbc..262b91f 100644 --- a/include/boost/filesystem/operations.hpp +++ b/include/boost/filesystem/operations.hpp @@ -56,12 +56,12 @@ namespace boost { template class basic_directory_iterator; - typedef char status_flag; - static const status_flag error_flag = 1; - static const status_flag not_found_flag = 2; - static const status_flag directory_flag = 4; - static const status_flag file_flag = 8; - static const status_flag symlink_flag = 16; + typedef char status_flags; + static const status_flags error_flag = 1; + static const status_flags not_found_flag = 2; + static const status_flags directory_flag = 4; + static const status_flags file_flag = 8; + static const status_flags symlink_flag = 16; namespace detail { @@ -82,13 +82,13 @@ namespace detail }; - BOOST_FILESYSTEM_DECL boost::filesystem::status_flag + BOOST_FILESYSTEM_DECL boost::filesystem::status_flags status_api( const std::string & ph, boost::filesystem::system_error_type * ec = 0 ); BOOST_FILESYSTEM_DECL bool symbolic_link_exists_api( const std::string & ); // deprecated # ifndef BOOST_WINDOWS_API - BOOST_FILESYSTEM_DECL boost::filesystem::status_flag + BOOST_FILESYSTEM_DECL boost::filesystem::status_flags symlink_status_api( const std::string & ph, boost::filesystem::system_error_type * ec = 0 ); # endif @@ -123,7 +123,7 @@ namespace detail # if !defined(BOOST_FILESYSTEM_NARROW_ONLY) - BOOST_FILESYSTEM_DECL boost::filesystem::status_flag + BOOST_FILESYSTEM_DECL boost::filesystem::status_flags status_api( const std::wstring & ph, boost::filesystem::system_error_type * ec = 0 ); BOOST_FILESYSTEM_DECL query_pair @@ -168,11 +168,11 @@ namespace detail // query functions ---------------------------------------------------------// - BOOST_FS_FUNC(status_flag) + BOOST_FS_FUNC(status_flags) status( const Path & ph, system_error_type * ec = 0 ) { return detail::status_api( ph.external_file_string(), ec ); } - BOOST_FS_FUNC(status_flag) + BOOST_FS_FUNC(status_flags) symlink_status( const Path & ph, system_error_type * ec = 0 ) # ifdef BOOST_WINDOWS_API { return detail::status_api( ph.external_file_string(), ec ); } @@ -186,7 +186,7 @@ namespace detail BOOST_FS_FUNC(bool) exists( const Path & ph ) { system_error_type ec; - status_flag sf( detail::status_api( ph.external_file_string(), &ec ) ); + status_flags sf( detail::status_api( ph.external_file_string(), &ec ) ); if ( sf == error_flag ) boost::throw_exception( basic_filesystem_error( "boost::filesystem::exists", ph, ec ) ); @@ -196,7 +196,7 @@ namespace detail BOOST_FS_FUNC(bool) is_directory( const Path & ph ) { system_error_type ec; - status_flag sf( detail::status_api( ph.external_file_string(), &ec ) ); + status_flags sf( detail::status_api( ph.external_file_string(), &ec ) ); if ( sf == error_flag ) boost::throw_exception( basic_filesystem_error( "boost::filesystem::is_directory", ph, ec ) ); @@ -206,7 +206,7 @@ namespace detail BOOST_FS_FUNC(bool) is_file( const Path & ph ) { system_error_type ec; - status_flag sf( detail::status_api( ph.external_file_string(), &ec ) ); + status_flags sf( detail::status_api( ph.external_file_string(), &ec ) ); if ( sf == error_flag ) boost::throw_exception( basic_filesystem_error( "boost::filesystem::is_file", ph, ec ) ); @@ -219,7 +219,7 @@ namespace detail return false; # else system_error_type ec; - status_flag sf( detail::symlink_status_api( ph.external_file_string(), &ec ) ); + status_flags sf( detail::symlink_status_api( ph.external_file_string(), &ec ) ); if ( sf == error_flag ) boost::throw_exception( basic_filesystem_error( "boost::filesystem::is_symlink", ph, ec ) ); @@ -428,14 +428,14 @@ namespace detail // "do-the-right-thing" overloads ---------------------------------------// - inline status_flag status( const path & ph, system_error_type * ec = 0 ) + inline status_flags status( const path & ph, system_error_type * ec = 0 ) { return status( ph, ec ); } - inline status_flag status( const wpath & ph, system_error_type * ec = 0 ) + inline status_flags status( const wpath & ph, system_error_type * ec = 0 ) { return status( ph, ec ); } - inline status_flag symlink_status( const path & ph, system_error_type * ec = 0 ) + inline status_flags symlink_status( const path & ph, system_error_type * ec = 0 ) { return symlink_status( ph, ec ); } - inline status_flag symlink_status( const wpath & ph, system_error_type * ec = 0 ) + inline status_flags symlink_status( const wpath & ph, system_error_type * ec = 0 ) { return symlink_status( ph, ec ); } inline bool exists( const path & ph ) { return exists( ph ); } diff --git a/src/operations.cpp b/src/operations.cpp index f0e9f63..9ddc996 100644 --- a/src/operations.cpp +++ b/src/operations.cpp @@ -140,7 +140,7 @@ namespace # endif // ifndef BOOST_FILESYSTEM_NARROW_ONLY template< class String > - fs::status_flag status_template( const String & ph, + fs::status_flags status_template( const String & ph, boost::filesystem::system_error_type * ec ) { DWORD attr( get_file_attributes( ph.c_str() ) ); @@ -414,7 +414,7 @@ namespace remove_template( const String & ph ) { fs::system_error_type ec; - fs::status_flag sf( fs::detail::status_api( ph, &ec ) ); + fs::status_flags sf( fs::detail::status_api( ph, &ec ) ); if ( sf == fs::error_flag ) return ec; if ( (sf & fs::directory_flag) != 0 ) { @@ -486,14 +486,14 @@ namespace boost # ifdef BOOST_WINDOWS_API - BOOST_FILESYSTEM_DECL fs::status_flag + BOOST_FILESYSTEM_DECL fs::status_flags status_api( const std::string & ph, boost::filesystem::system_error_type * ec ) { return status_template( ph, ec ); } # ifndef BOOST_FILESYSTEM_NARROW_ONLY - BOOST_FILESYSTEM_DECL fs::status_flag + BOOST_FILESYSTEM_DECL fs::status_flags status_api( const std::wstring & ph, boost::filesystem::system_error_type * ec ) { return status_template( ph, ec ); } @@ -767,7 +767,7 @@ namespace boost # else // BOOST_POSIX_API - BOOST_FILESYSTEM_DECL boost::filesystem::status_flag + BOOST_FILESYSTEM_DECL boost::filesystem::status_flags status_api( const std::string & ph, boost::filesystem::system_error_type * ec ) { @@ -778,13 +778,13 @@ namespace boost return ( (errno == ENOENT) || (errno == ENOTDIR) ) ? fs::not_found_flag : fs::error_flag; } - fs::status_flag result(0); + fs::status_flags result(0); if ( S_ISDIR( path_stat.st_mode ) ) result |= fs::directory_flag; if ( S_ISREG( path_stat.st_mode ) ) result |= fs::file_flag; return result; } - BOOST_FILESYSTEM_DECL boost::filesystem::status_flag + BOOST_FILESYSTEM_DECL boost::filesystem::status_flags symlink_status_api( const std::string & ph, boost::filesystem::system_error_type * ec ) { @@ -796,7 +796,7 @@ namespace boost ? fs::not_found_flag : fs::error_flag; } if ( S_ISLNK( path_stat.st_mode ) ) return fs::symlink_flag; - fs::status_flag result(0); + fs::status_flags result(0); if ( S_ISDIR( path_stat.st_mode ) ) result |= fs::directory_flag; if ( S_ISREG( path_stat.st_mode ) ) result |= fs::file_flag; return result;