1 // boost/filesystem/directory.hpp ------------------------------------------//
3 // Copyright © 2002, 2003 Beman Dawes
4 // Copyright © 2002 Jan Langer
5 // Copyright © 2001 Dietmar Kühl
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)
11 // See library home page at http://www.boost.org/libs/filesystem
13 //----------------------------------------------------------------------------//
15 #ifndef BOOST_FILESYSTEM_DIRECTORY_HPP
16 #define BOOST_FILESYSTEM_DIRECTORY_HPP
18 #include <boost/filesystem/path.hpp> // includes <boost/filesystem/config.hpp>
19 #include <boost/shared_ptr.hpp>
20 #include <boost/iterator.hpp>
25 #include <boost/config/abi_prefix.hpp> // must be the last header
27 # ifdef BOOST_NO_STDC_NAMESPACE
28 namespace std { using ::time_t; }
31 //----------------------------------------------------------------------------//
38 // query functions ---------------------------------------------------------//
40 BOOST_FILESYSTEM_DECL bool exists( const path & ph );
41 BOOST_FILESYSTEM_DECL bool symbolic_link_exists( const path & ph );
42 BOOST_FILESYSTEM_DECL bool is_directory( const path & ph );
44 // VC++ 7.0 and earlier has a serious namespace bug that causes a clash
45 // between boost::filesystem::is_empty and the unrelated type trait
46 // boost::is_empty. The workaround for those who must use broken versions
47 // of VC++ is to use the function _is_empty. All others should use the
48 // correct is_empty name.
49 BOOST_FILESYSTEM_DECL bool _is_empty( const path & ph ); // deprecated
51 # if !defined( BOOST_MSVC ) || BOOST_MSVC > 1300
52 inline bool is_empty( const path & ph ) { return _is_empty( ph ); }
55 BOOST_FILESYSTEM_DECL std::time_t last_write_time( const path & ph );
56 BOOST_FILESYSTEM_DECL void last_write_time( const path & ph, const std::time_t new_time );
58 // operations --------------------------------------------------------------//
60 BOOST_FILESYSTEM_DECL void create_directory( const path & directory_ph );
62 BOOST_FILESYSTEM_DECL bool remove( const path & ph );
63 BOOST_FILESYSTEM_DECL unsigned long remove_all( const path & ph );
65 BOOST_FILESYSTEM_DECL void rename( const path & from_path,
66 const path & to_path );
68 BOOST_FILESYSTEM_DECL void copy_file( const path & from_file_ph,
69 const path & to_file_ph );
71 BOOST_FILESYSTEM_DECL path current_path();
72 BOOST_FILESYSTEM_DECL const path & initial_path();
74 BOOST_FILESYSTEM_DECL path system_complete( const path & ph );
75 BOOST_FILESYSTEM_DECL path complete( const path & ph, const path & base = initial_path() );
77 // directory_iterator helpers ----------------------------------------------//
78 // forwarding functions avoid need for BOOST_FILESYSTEM_DECL for class
79 // directory_iterator, and so avoid iterator_facade DLL template problems
83 // shared_ptr provides shallow-copy semantics required for InputIterators
84 typedef boost::shared_ptr< dir_itr_imp > dir_itr_imp_ptr;
85 BOOST_FILESYSTEM_DECL void dir_itr_init( dir_itr_imp_ptr & m_imp,
86 const path & dir_path );
87 BOOST_FILESYSTEM_DECL path & dir_itr_dereference(
88 const dir_itr_imp_ptr & m_imp );
89 BOOST_FILESYSTEM_DECL void dir_itr_increment( dir_itr_imp_ptr & m_imp );
92 // directory_iterator ------------------------------------------------------//
94 class directory_iterator
95 : public boost::iterator_facade<
98 boost::single_pass_traversal_tag >
101 directory_iterator(){} // creates the "end" iterator
102 explicit directory_iterator( const path & p )
103 { detail::dir_itr_init( m_imp, p ); }
106 The *r++ requirement doesn't appear to apply to the new single_pass_traversal category
107 Thus I'm leaving the proxy out pending confirmation from the N1477 authors
108 struct path_proxy // allows *r++ to work, as required by 24.1.1
111 explicit path_proxy( const path & p ) : pv(p) {}
112 path operator*() const { return pv; }
115 path_proxy operator++(int)
117 path_proxy pp( m_deref() );
124 detail::dir_itr_imp_ptr m_imp;
125 friend class boost::iterator_core_access;
126 reference dereference() const
127 { return detail::dir_itr_dereference( m_imp ); }
129 { detail::dir_itr_increment( m_imp ); }
130 bool equal( const directory_iterator & rhs ) const
131 { return m_imp == rhs.m_imp; }
133 } // namespace filesystem
137 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
138 #endif // BOOST_FILESYSTEM_DIRECTORY_HPP