[857] | 1 | // boost/filesystem/directory.hpp ------------------------------------------//
|
---|
| 2 |
|
---|
| 3 | // Copyright © 2002, 2003 Beman Dawes
|
---|
| 4 | // Copyright © 2002 Jan Langer
|
---|
| 5 | // Copyright © 2001 Dietmar Kühl
|
---|
| 6 | //
|
---|
| 7 | // Use, modification, and distribution is subject to the Boost Software
|
---|
| 8 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
|
---|
| 9 | // at http://www.boost.org/LICENSE_1_0.txt)
|
---|
| 10 |
|
---|
| 11 | // See library home page at http://www.boost.org/libs/filesystem
|
---|
| 12 |
|
---|
| 13 | //----------------------------------------------------------------------------//
|
---|
| 14 |
|
---|
| 15 | #ifndef BOOST_FILESYSTEM_DIRECTORY_HPP
|
---|
| 16 | #define BOOST_FILESYSTEM_DIRECTORY_HPP
|
---|
| 17 |
|
---|
| 18 | #include <boost/filesystem/path.hpp> // includes <boost/filesystem/config.hpp>
|
---|
| 19 | #include <boost/shared_ptr.hpp>
|
---|
| 20 | #include <boost/iterator.hpp>
|
---|
| 21 | #include <boost/cstdint.hpp>
|
---|
| 22 |
|
---|
| 23 | #include <string>
|
---|
| 24 | #include <ctime>
|
---|
| 25 |
|
---|
| 26 | #include <boost/config/abi_prefix.hpp> // must be the last header
|
---|
| 27 |
|
---|
| 28 | # ifdef BOOST_NO_STDC_NAMESPACE
|
---|
| 29 | namespace std { using ::time_t; }
|
---|
| 30 | # endif
|
---|
| 31 |
|
---|
| 32 | //----------------------------------------------------------------------------//
|
---|
| 33 |
|
---|
| 34 | namespace boost
|
---|
| 35 | {
|
---|
| 36 | namespace filesystem
|
---|
| 37 | {
|
---|
| 38 |
|
---|
| 39 | // query functions ---------------------------------------------------------//
|
---|
| 40 |
|
---|
| 41 | BOOST_FILESYSTEM_DECL bool exists( const path & ph );
|
---|
| 42 | BOOST_FILESYSTEM_DECL bool symbolic_link_exists( const path & ph );
|
---|
| 43 | BOOST_FILESYSTEM_DECL bool is_directory( const path & ph );
|
---|
| 44 |
|
---|
| 45 | // VC++ 7.0 and earlier has a serious namespace bug that causes a clash
|
---|
| 46 | // between boost::filesystem::is_empty and the unrelated type trait
|
---|
| 47 | // boost::is_empty. The workaround for those who must use broken versions
|
---|
| 48 | // of VC++ is to use the function _is_empty. All others should use the
|
---|
| 49 | // correct is_empty name.
|
---|
| 50 | BOOST_FILESYSTEM_DECL bool _is_empty( const path & ph ); // deprecated
|
---|
| 51 |
|
---|
| 52 | # if !defined( BOOST_MSVC ) || BOOST_MSVC > 1300
|
---|
| 53 | inline bool is_empty( const path & ph ) { return _is_empty( ph ); }
|
---|
| 54 | # endif
|
---|
| 55 |
|
---|
| 56 | BOOST_FILESYSTEM_DECL bool equivalent( const path & ph1, const path & ph2 );
|
---|
| 57 | BOOST_FILESYSTEM_DECL boost::intmax_t file_size( const path & ph );
|
---|
| 58 | BOOST_FILESYSTEM_DECL std::time_t last_write_time( const path & ph );
|
---|
| 59 | BOOST_FILESYSTEM_DECL void last_write_time( const path & ph, const std::time_t new_time );
|
---|
| 60 |
|
---|
| 61 | // operations --------------------------------------------------------------//
|
---|
| 62 |
|
---|
| 63 | BOOST_FILESYSTEM_DECL bool create_directory( const path & directory_ph );
|
---|
| 64 |
|
---|
| 65 | BOOST_FILESYSTEM_DECL bool remove( const path & ph );
|
---|
| 66 | BOOST_FILESYSTEM_DECL unsigned long remove_all( const path & ph );
|
---|
| 67 |
|
---|
| 68 | BOOST_FILESYSTEM_DECL void rename( const path & from_path,
|
---|
| 69 | const path & to_path );
|
---|
| 70 |
|
---|
| 71 | BOOST_FILESYSTEM_DECL void copy_file( const path & from_file_ph,
|
---|
| 72 | const path & to_file_ph );
|
---|
| 73 |
|
---|
| 74 | BOOST_FILESYSTEM_DECL path current_path();
|
---|
| 75 | BOOST_FILESYSTEM_DECL const path & initial_path();
|
---|
| 76 |
|
---|
| 77 | BOOST_FILESYSTEM_DECL path system_complete( const path & ph );
|
---|
| 78 | BOOST_FILESYSTEM_DECL path complete( const path & ph, const path & base = initial_path() );
|
---|
| 79 |
|
---|
| 80 | // test helper -------------------------------------------------------------//
|
---|
| 81 |
|
---|
| 82 | // not part of the documented interface because false positives are possible;
|
---|
| 83 | // there is no law that says that an OS that has large stat.st_size
|
---|
| 84 | // actually supports large file sizes.
|
---|
| 85 | BOOST_FILESYSTEM_DECL bool possible_large_file_size_support();
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | // directory_iterator helpers ----------------------------------------------//
|
---|
| 89 | // forwarding functions avoid need for BOOST_FILESYSTEM_DECL for class
|
---|
| 90 | // directory_iterator, and so avoid iterator_facade DLL template problems
|
---|
| 91 | namespace detail
|
---|
| 92 | {
|
---|
| 93 | class dir_itr_imp;
|
---|
| 94 | // shared_ptr provides shallow-copy semantics required for InputIterators
|
---|
| 95 | typedef boost::shared_ptr< dir_itr_imp > dir_itr_imp_ptr;
|
---|
| 96 | BOOST_FILESYSTEM_DECL void dir_itr_init( dir_itr_imp_ptr & m_imp,
|
---|
| 97 | const path & dir_path );
|
---|
| 98 | BOOST_FILESYSTEM_DECL path & dir_itr_dereference(
|
---|
| 99 | const dir_itr_imp_ptr & m_imp );
|
---|
| 100 | BOOST_FILESYSTEM_DECL void dir_itr_increment( dir_itr_imp_ptr & m_imp );
|
---|
| 101 | } // namespace detail
|
---|
| 102 |
|
---|
| 103 | // directory_iterator ------------------------------------------------------//
|
---|
| 104 |
|
---|
| 105 | class directory_iterator
|
---|
| 106 | : public boost::iterator_facade<
|
---|
| 107 | directory_iterator,
|
---|
| 108 | path,
|
---|
| 109 | boost::single_pass_traversal_tag >
|
---|
| 110 | {
|
---|
| 111 | public:
|
---|
| 112 | directory_iterator(){} // creates the "end" iterator
|
---|
| 113 | explicit directory_iterator( const path & p )
|
---|
| 114 | { detail::dir_itr_init( m_imp, p ); }
|
---|
| 115 |
|
---|
| 116 | /*
|
---|
| 117 | The *r++ requirement doesn't appear to apply to the new single_pass_traversal category
|
---|
| 118 | Thus I'm leaving the proxy out pending confirmation from the N1477 authors
|
---|
| 119 | struct path_proxy // allows *r++ to work, as required by 24.1.1
|
---|
| 120 | {
|
---|
| 121 | path pv;
|
---|
| 122 | explicit path_proxy( const path & p ) : pv(p) {}
|
---|
| 123 | path operator*() const { return pv; }
|
---|
| 124 | };
|
---|
| 125 |
|
---|
| 126 | path_proxy operator++(int)
|
---|
| 127 | {
|
---|
| 128 | path_proxy pp( m_deref() );
|
---|
| 129 | ++*this;
|
---|
| 130 | return pp;
|
---|
| 131 | }
|
---|
| 132 | */
|
---|
| 133 |
|
---|
| 134 | private:
|
---|
| 135 | detail::dir_itr_imp_ptr m_imp;
|
---|
| 136 | friend class boost::iterator_core_access;
|
---|
| 137 | reference dereference() const
|
---|
| 138 | { return detail::dir_itr_dereference( m_imp ); }
|
---|
| 139 | void increment()
|
---|
| 140 | { detail::dir_itr_increment( m_imp ); }
|
---|
| 141 | bool equal( const directory_iterator & rhs ) const
|
---|
| 142 | { return m_imp == rhs.m_imp; }
|
---|
| 143 | };
|
---|
| 144 | } // namespace filesystem
|
---|
| 145 | } // namespace boost
|
---|
| 146 |
|
---|
| 147 |
|
---|
| 148 | #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
|
---|
| 149 | #endif // BOOST_FILESYSTEM_DIRECTORY_HPP
|
---|