]> git.lyx.org Git - lyx.git/blob - boost/boost/filesystem/operations.hpp
Boost 1.31.0
[lyx.git] / boost / boost / filesystem / operations.hpp
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
22 #include <string>
23 #include <ctime>
24
25 #include <boost/config/abi_prefix.hpp> // must be the last header
26
27 # ifdef BOOST_NO_STDC_NAMESPACE
28     namespace std { using ::time_t; }
29 # endif
30
31 //----------------------------------------------------------------------------//
32
33 namespace boost
34 {
35   namespace filesystem
36   {
37
38 //  query functions  ---------------------------------------------------------//
39
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 );
43
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
50
51 #   if !defined( BOOST_MSVC ) || BOOST_MSVC > 1300
52     inline bool is_empty( const path & ph ) { return _is_empty( ph ); }
53 #   endif
54
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 );
57
58 //  operations  --------------------------------------------------------------//
59
60     BOOST_FILESYSTEM_DECL void create_directory( const path & directory_ph );
61
62     BOOST_FILESYSTEM_DECL bool remove( const path & ph );
63     BOOST_FILESYSTEM_DECL unsigned long remove_all( const path & ph );
64
65     BOOST_FILESYSTEM_DECL void rename( const path & from_path,
66                  const path & to_path );
67
68     BOOST_FILESYSTEM_DECL void copy_file( const path & from_file_ph,
69                     const path & to_file_ph );
70
71     BOOST_FILESYSTEM_DECL path current_path();
72     BOOST_FILESYSTEM_DECL const path & initial_path();
73
74     BOOST_FILESYSTEM_DECL path system_complete( const path & ph );
75     BOOST_FILESYSTEM_DECL path complete( const path & ph, const path & base = initial_path() );
76
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
80     namespace detail
81     {
82       class dir_itr_imp;
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 );
90     } // namespace detail
91
92 //  directory_iterator  ------------------------------------------------------//
93
94     class directory_iterator
95       : public boost::iterator_facade<
96       directory_iterator,
97       path,
98       boost::single_pass_traversal_tag >
99     {
100     public:
101       directory_iterator(){}  // creates the "end" iterator
102       explicit directory_iterator( const path & p )
103         { detail::dir_itr_init( m_imp, p ); }
104
105 /*
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
109       {
110         path pv;
111         explicit path_proxy( const path & p ) : pv(p) {}
112         path operator*() const { return pv; }
113       };
114
115       path_proxy operator++(int)
116       {
117         path_proxy pp( m_deref() );
118         ++*this;
119         return pp;
120       }
121 */
122
123     private:
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 ); }
128       void increment()
129         { detail::dir_itr_increment( m_imp ); }
130       bool equal( const directory_iterator & rhs ) const
131         { return m_imp == rhs.m_imp; }
132     };
133   } // namespace filesystem
134 } // namespace boost
135
136
137 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
138 #endif // BOOST_FILESYSTEM_DIRECTORY_HPP