~ubuntu-branches/ubuntu/wily/bombono-dvd/wily

« back to all changes in this revision

Viewing changes to libs/boost-lib/boost/filesystem/v3/operations.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-04 11:46:25 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101104114625-8xfdhvhpsm51i0nu
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  boost/filesystem/operations.hpp  ---------------------------------------------------//
 
2
 
 
3
//  Copyright Beman Dawes 2002-2009
 
4
//  Copyright Jan Langer 2002
 
5
//  Copyright Dietmar Kuehl 2001                                        
 
6
//  Copyright Vladimir Prus 2002
 
7
   
 
8
//  Distributed under the Boost Software License, Version 1.0.
 
9
//  See http://www.boost.org/LICENSE_1_0.txt
 
10
 
 
11
//  Library home page: http://www.boost.org/libs/filesystem
 
12
 
 
13
//--------------------------------------------------------------------------------------//
 
14
 
 
15
#ifndef BOOST_FILESYSTEM3_OPERATIONS_HPP
 
16
#define BOOST_FILESYSTEM3_OPERATIONS_HPP
 
17
 
 
18
#include <boost/config.hpp>
 
19
 
 
20
# if defined( BOOST_NO_STD_WSTRING )
 
21
#   error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
 
22
# endif
 
23
 
 
24
#include <boost/filesystem/v3/config.hpp>
 
25
#include <boost/filesystem/v3/path.hpp>
 
26
 
 
27
#include <boost/detail/scoped_enum_emulation.hpp>
 
28
#include <boost/system/error_code.hpp>
 
29
#include <boost/system/system_error.hpp>
 
30
#include <boost/shared_ptr.hpp>
 
31
#include <boost/utility/enable_if.hpp>
 
32
#include <boost/type_traits/is_same.hpp>
 
33
#include <boost/iterator.hpp>
 
34
#include <boost/cstdint.hpp>
 
35
#include <boost/assert.hpp>
 
36
 
 
37
#include <string>
 
38
#include <utility> // for pair
 
39
#include <ctime>
 
40
#include <vector>
 
41
#include <stack>
 
42
 
 
43
#ifdef BOOST_WINDOWS_API
 
44
#  include <fstream>
 
45
#endif
 
46
 
 
47
#include <boost/config/abi_prefix.hpp> // must be the last #include
 
48
 
 
49
//--------------------------------------------------------------------------------------//
 
50
 
 
51
namespace boost
 
52
{
 
53
  namespace filesystem3
 
54
  {
 
55
 
 
56
//--------------------------------------------------------------------------------------//
 
57
//                                                                                      //
 
58
//                            support classes and enums                                 //
 
59
//                                                                                      //
 
60
//--------------------------------------------------------------------------------------//
 
61
 
 
62
  enum file_type
 
63
  { 
 
64
    status_error,
 
65
#   ifndef BOOST_FILESYSTEM_NO_DEPRECATED
 
66
    status_unknown = status_error,
 
67
#   endif
 
68
    file_not_found,
 
69
    regular_file,
 
70
    directory_file,
 
71
    // the following will never be reported by some operating or file systems
 
72
    symlink_file,
 
73
    block_file,
 
74
    character_file,
 
75
    fifo_file,
 
76
    socket_file,
 
77
    type_unknown // file does exist, but isn't one of the above types or
 
78
                 // we don't have strong enough permission to find its type
 
79
  };
 
80
 
 
81
  class BOOST_FILESYSTEM_DECL file_status
 
82
  {
 
83
  public:
 
84
    explicit file_status(file_type v = status_error) : m_value(v) {}
 
85
 
 
86
    void type(file_type v)    { m_value = v; }
 
87
    file_type type() const    { return m_value; }
 
88
 
 
89
    bool operator==(const file_status& rhs) const { return type() == rhs.type(); }
 
90
    bool operator!=(const file_status& rhs) const { return !(*this == rhs); }
 
91
 
 
92
  private:
 
93
    // the internal representation is unspecified so that additional state
 
94
    // information such as permissions can be added in the future; this
 
95
    // implementation just uses file_type as the internal representation
 
96
 
 
97
    file_type m_value;
 
98
  };
 
99
 
 
100
  inline bool status_known(file_status f) { return f.type() != status_error; }
 
101
  inline bool exists(file_status f)       { return f.type() != status_error
 
102
                                                && f.type() != file_not_found; }
 
103
  inline bool is_regular_file(file_status f){ return f.type() == regular_file; }
 
104
  inline bool is_directory(file_status f) { return f.type() == directory_file; }
 
105
  inline bool is_symlink(file_status f)   { return f.type() == symlink_file; }
 
106
  inline bool is_other(file_status f)     { return exists(f) && !is_regular_file(f)
 
107
                                                && !is_directory(f) && !is_symlink(f); }
 
108
 
 
109
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
 
110
  inline bool is_regular(file_status f)   { return f.type() == regular_file; }
 
111
# endif
 
112
 
 
113
  struct space_info
 
114
  {
 
115
    // all values are byte counts
 
116
    boost::uintmax_t capacity;
 
117
    boost::uintmax_t free;      // <= capacity
 
118
    boost::uintmax_t available; // <= free
 
119
  };
 
120
 
 
121
  BOOST_SCOPED_ENUM_START(copy_option)
 
122
    {fail_if_exists, overwrite_if_exists};
 
123
  BOOST_SCOPED_ENUM_END
 
124
 
 
125
//--------------------------------------------------------------------------------------//
 
126
//                             implementation details                                   //
 
127
//--------------------------------------------------------------------------------------//
 
128
 
 
129
  namespace detail
 
130
  {
 
131
    BOOST_FILESYSTEM_DECL
 
132
    file_status status(const path&p, system::error_code* ec=0);
 
133
    BOOST_FILESYSTEM_DECL
 
134
    file_status symlink_status(const path& p, system::error_code* ec=0);
 
135
    BOOST_FILESYSTEM_DECL
 
136
    bool is_empty(const path& p, system::error_code* ec=0);
 
137
    BOOST_FILESYSTEM_DECL
 
138
    path initial_path(system::error_code* ec=0);
 
139
    BOOST_FILESYSTEM_DECL
 
140
    void copy(const path& from, const path& to, system::error_code* ec=0);
 
141
    BOOST_FILESYSTEM_DECL
 
142
    void copy_directory(const path& from, const path& to, system::error_code* ec=0);
 
143
    BOOST_FILESYSTEM_DECL
 
144
    void copy_file(const path& from, const path& to,
 
145
                    BOOST_SCOPED_ENUM(copy_option) option,  // See ticket #2925
 
146
                    system::error_code* ec=0);
 
147
    BOOST_FILESYSTEM_DECL
 
148
    void copy_symlink(const path& from, const path& to, system::error_code* ec=0);
 
149
    BOOST_FILESYSTEM_DECL
 
150
    bool create_directories(const path& p, system::error_code* ec=0);
 
151
    BOOST_FILESYSTEM_DECL
 
152
    bool create_directory(const path& p, system::error_code* ec=0);
 
153
    BOOST_FILESYSTEM_DECL
 
154
    void create_directory_symlink(const path& to, const path& from,
 
155
                                   system::error_code* ec=0);
 
156
    BOOST_FILESYSTEM_DECL
 
157
    void create_hard_link(const path& to, const path& from, system::error_code* ec=0);
 
158
    BOOST_FILESYSTEM_DECL
 
159
    void create_symlink(const path& to, const path& from, system::error_code* ec=0);
 
160
    BOOST_FILESYSTEM_DECL
 
161
    path current_path(system::error_code* ec=0);
 
162
    BOOST_FILESYSTEM_DECL
 
163
    void current_path(const path& p, system::error_code* ec=0);
 
164
    BOOST_FILESYSTEM_DECL
 
165
    bool equivalent(const path& p1, const path& p2, system::error_code* ec=0);
 
166
    BOOST_FILESYSTEM_DECL
 
167
    boost::uintmax_t file_size(const path& p, system::error_code* ec=0);
 
168
    BOOST_FILESYSTEM_DECL
 
169
    boost::uintmax_t hard_link_count(const path& p, system::error_code* ec=0);
 
170
    BOOST_FILESYSTEM_DECL
 
171
    std::time_t last_write_time(const path& p, system::error_code* ec=0);
 
172
    BOOST_FILESYSTEM_DECL
 
173
    void last_write_time(const path& p, const std::time_t new_time,
 
174
                     system::error_code* ec=0);
 
175
    BOOST_FILESYSTEM_DECL
 
176
    path read_symlink(const path& p, system::error_code* ec=0);
 
177
    BOOST_FILESYSTEM_DECL
 
178
      // For standardization, if the committee doesn't like "remove", consider "eliminate"
 
179
    bool remove(const path& p, system::error_code* ec=0);
 
180
    BOOST_FILESYSTEM_DECL
 
181
    boost::uintmax_t remove_all(const path& p, system::error_code* ec=0);
 
182
    BOOST_FILESYSTEM_DECL
 
183
    void rename(const path& old_p, const path& new_p, system::error_code* ec=0);
 
184
    BOOST_FILESYSTEM_DECL
 
185
    void resize_file(const path& p, uintmax_t size, system::error_code* ec=0);
 
186
    BOOST_FILESYSTEM_DECL
 
187
    space_info space(const path& p, system::error_code* ec=0); 
 
188
    BOOST_FILESYSTEM_DECL
 
189
    path system_complete(const path& p, system::error_code* ec=0);
 
190
    BOOST_FILESYSTEM_DECL
 
191
    path unique_path(const path& p, system::error_code* ec=0);
 
192
  }  // namespace detail
 
193
 
 
194
//--------------------------------------------------------------------------------------//
 
195
//                                                                                      //
 
196
//                             status query functions                                   //
 
197
//                                                                                      //
 
198
//--------------------------------------------------------------------------------------//
 
199
 
 
200
  inline
 
201
  file_status status(const path& p)    {return detail::status(p);}
 
202
  inline 
 
203
  file_status status(const path& p, system::error_code& ec)
 
204
                                       {return detail::status(p, &ec);}
 
205
  inline 
 
206
  file_status symlink_status(const path& p) {return detail::symlink_status(p);}
 
207
  inline
 
208
  file_status symlink_status(const path& p, system::error_code& ec)
 
209
                                       {return detail::symlink_status(p, &ec);}
 
210
  inline 
 
211
  bool exists(const path& p)           {return exists(detail::status(p));}
 
212
  inline 
 
213
  bool exists(const path& p, system::error_code& ec)
 
214
                                       {return exists(detail::status(p, &ec));}
 
215
  inline 
 
216
  bool is_directory(const path& p)     {return is_directory(detail::status(p));}
 
217
  inline 
 
218
  bool is_directory(const path& p, system::error_code& ec)
 
219
                                       {return is_directory(detail::status(p, &ec));}
 
220
  inline 
 
221
  bool is_regular_file(const path& p)  {return is_regular_file(detail::status(p));}
 
222
  inline 
 
223
  bool is_regular_file(const path& p, system::error_code& ec)
 
224
                                       {return is_regular_file(detail::status(p, &ec));}
 
225
  inline 
 
226
  bool is_other(const path& p)         {return is_other(detail::status(p));}
 
227
  inline 
 
228
  bool is_other(const path& p, system::error_code& ec)
 
229
                                       {return is_other(detail::status(p, &ec));}
 
230
  inline
 
231
  bool is_symlink(const path& p)       {return is_symlink(detail::symlink_status(p));}
 
232
  inline 
 
233
  bool is_symlink(const path& p, system::error_code& ec)
 
234
                                       {return is_symlink(detail::symlink_status(p, &ec));}
 
235
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
 
236
  inline
 
237
  bool is_regular(const path& p)       {return is_regular(detail::status(p));}
 
238
  inline
 
239
  bool is_regular(const path& p, system::error_code& ec)
 
240
                                       {return is_regular(detail::status(p, &ec));}
 
241
# endif
 
242
 
 
243
  inline
 
244
  bool is_empty(const path& p)         {return detail::is_empty(p);}
 
245
  inline
 
246
  bool is_empty(const path& p, system::error_code& ec)
 
247
                                       {return detail::is_empty(p, &ec);}
 
248
 
 
249
//--------------------------------------------------------------------------------------//
 
250
//                                                                                      //
 
251
//                             operational functions                                    //
 
252
//                  in alphabetical order, unless otherwise noted                       //
 
253
//                                                                                      //
 
254
//--------------------------------------------------------------------------------------//
 
255
 
 
256
  //  forward declarations
 
257
  path current_path();  // fwd declaration
 
258
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
 
259
  path initial_path();
 
260
# endif
 
261
 
 
262
  BOOST_FILESYSTEM_DECL
 
263
  path absolute(const path& p, const path& base=current_path());
 
264
  //  If base.is_absolute(), throws nothing. Thus no need for ec argument
 
265
 
 
266
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
 
267
  inline
 
268
  path complete(const path& p)
 
269
  {
 
270
    return absolute(p, initial_path());
 
271
  }
 
272
 
 
273
  inline
 
274
  path complete(const path& p, const path& base)
 
275
  {
 
276
    return absolute(p, base);
 
277
  }
 
278
# endif
 
279
 
 
280
  inline
 
281
  void copy(const path& from, const path& to) {detail::copy(from, to);}
 
282
 
 
283
  inline
 
284
  void copy(const path& from, const path& to, system::error_code& ec) 
 
285
                                       {detail::copy(from, to, &ec);}
 
286
  inline
 
287
  void copy_directory(const path& from, const path& to)
 
288
                                       {detail::copy_directory(from, to);}
 
289
  inline
 
290
  void copy_directory(const path& from, const path& to, system::error_code& ec)
 
291
                                       {detail::copy_directory(from, to, &ec);}
 
292
  inline
 
293
  void copy_file(const path& from, const path& to,   // See ticket #2925
 
294
                 BOOST_SCOPED_ENUM(copy_option) option)
 
295
                                       {detail::copy_file(from, to, option);}
 
296
  inline
 
297
  void copy_file(const path& from, const path& to)
 
298
                                       {detail::copy_file(from, to, copy_option::fail_if_exists);}
 
299
  inline
 
300
  void copy_file(const path& from, const path& to,   // See ticket #2925
 
301
                 BOOST_SCOPED_ENUM(copy_option) option, system::error_code& ec)
 
302
                                       {detail::copy_file(from, to, option, &ec);}
 
303
  inline
 
304
  void copy_file(const path& from, const path& to, system::error_code& ec)
 
305
                                       {detail::copy_file(from, to, copy_option::fail_if_exists, &ec);}
 
306
  inline
 
307
  void copy_symlink(const path& from, const path& to) {detail::copy_symlink(from, to);}
 
308
 
 
309
  inline
 
310
  void copy_symlink(const path& from, const path& to, system::error_code& ec)
 
311
                                       {detail::copy_symlink(from, to, &ec);}
 
312
  inline
 
313
  bool create_directories(const path& p) {return detail::create_directories(p);}
 
314
 
 
315
  inline
 
316
  bool create_directories(const path& p, system::error_code& ec)
 
317
                                       {return detail::create_directories(p, &ec);}
 
318
  inline
 
319
  bool create_directory(const path& p) {return detail::create_directory(p);}
 
320
 
 
321
  inline
 
322
  bool create_directory(const path& p, system::error_code& ec)
 
323
                                       {return detail::create_directory(p, &ec);}
 
324
  inline
 
325
  void create_directory_symlink(const path& to, const path& from)
 
326
                                       {detail::create_directory_symlink(to, from);}
 
327
  inline
 
328
  void create_directory_symlink(const path& to, const path& from, system::error_code& ec)
 
329
                                       {detail::create_directory_symlink(to, from, &ec);}
 
330
  inline
 
331
  void create_hard_link(const path& to, const path& from) {detail::create_hard_link(to, from);}
 
332
 
 
333
  inline
 
334
  void create_hard_link(const path& to, const path& from, system::error_code& ec)
 
335
                                       {detail::create_hard_link(to, from, &ec);}
 
336
  inline
 
337
  void create_symlink(const path& to, const path& from) {detail::create_symlink(to, from);}
 
338
 
 
339
  inline
 
340
  void create_symlink(const path& to, const path& from, system::error_code& ec)
 
341
                                       {detail::create_symlink(to, from, &ec);}
 
342
  inline
 
343
  path current_path()                  {return detail::current_path();}
 
344
 
 
345
  inline
 
346
  path current_path(system::error_code& ec) {return detail::current_path(&ec);}
 
347
 
 
348
  inline
 
349
  void current_path(const path& p)     {detail::current_path(p);}
 
350
 
 
351
  inline
 
352
  void current_path(const path& p, system::error_code& ec) {detail::current_path(p, &ec);}
 
353
 
 
354
  inline
 
355
  bool equivalent(const path& p1, const path& p2) {return detail::equivalent(p1, p2);}
 
356
 
 
357
  inline
 
358
  bool equivalent(const path& p1, const path& p2, system::error_code& ec)
 
359
                                       {return detail::equivalent(p1, p2, &ec);}
 
360
  inline
 
361
  boost::uintmax_t file_size(const path& p) {return detail::file_size(p);}
 
362
 
 
363
  inline
 
364
  boost::uintmax_t file_size(const path& p, system::error_code& ec)
 
365
                                       {return detail::file_size(p, &ec);}
 
366
  inline
 
367
  boost::uintmax_t hard_link_count(const path& p) {return detail::hard_link_count(p);}
 
368
 
 
369
  inline
 
370
  boost::uintmax_t hard_link_count(const path& p, system::error_code& ec)
 
371
                                       {return detail::hard_link_count(p, &ec);}
 
372
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
 
373
  inline
 
374
  path initial_path()                  {return detail::initial_path();}
 
375
 
 
376
  inline
 
377
  path initial_path(system::error_code& ec) {return detail::initial_path(&ec);}
 
378
 
 
379
  template <class Path>
 
380
  path initial_path() {return initial_path();}
 
381
  template <class Path>
 
382
  path initial_path(system::error_code& ec) {return detail::initial_path(&ec);}
 
383
# endif
 
384
 
 
385
  inline
 
386
  std::time_t last_write_time(const path& p) {return detail::last_write_time(p);}
 
387
 
 
388
  inline
 
389
  std::time_t last_write_time(const path& p, system::error_code& ec)
 
390
                                       {return detail::last_write_time(p, &ec);}
 
391
  inline
 
392
  void last_write_time(const path& p, const std::time_t new_time)
 
393
                                       {detail::last_write_time(p, new_time);}
 
394
  inline
 
395
  void last_write_time(const path& p, const std::time_t new_time, system::error_code& ec)
 
396
                                       {detail::last_write_time(p, new_time, &ec);}
 
397
  inline
 
398
  path read_symlink(const path& p)     {return detail::read_symlink(p);}
 
399
 
 
400
  inline
 
401
  path read_symlink(const path& p, system::error_code& ec)
 
402
                                       {return detail::read_symlink(p, &ec);}
 
403
  inline
 
404
    // For standardization, if the committee doesn't like "remove", consider "eliminate"
 
405
  bool remove(const path& p)           {return detail::remove(p);}
 
406
 
 
407
  inline
 
408
  bool remove(const path& p, system::error_code& ec) {return detail::remove(p, &ec);}
 
409
 
 
410
  inline
 
411
  boost::uintmax_t remove_all(const path& p) {return detail::remove_all(p);}
 
412
    
 
413
  inline
 
414
  boost::uintmax_t remove_all(const path& p, system::error_code& ec)
 
415
                                       {return detail::remove_all(p, &ec);}
 
416
  inline
 
417
  void rename(const path& old_p, const path& new_p) {detail::rename(old_p, new_p);}
 
418
 
 
419
  inline
 
420
  void rename(const path& old_p, const path& new_p, system::error_code& ec)
 
421
                                       {detail::rename(old_p, new_p, &ec);}
 
422
  inline  // name suggested by Scott McMurray
 
423
  void resize_file(const path& p, uintmax_t size) {detail::resize_file(p, size);}
 
424
 
 
425
  inline
 
426
  void resize_file(const path& p, uintmax_t size, system::error_code& ec)
 
427
                                       {detail::resize_file(p, size, &ec);}
 
428
  inline
 
429
  space_info space(const path& p)      {return detail::space(p);} 
 
430
 
 
431
  inline
 
432
  space_info space(const path& p, system::error_code& ec) {return detail::space(p, &ec);} 
 
433
 
 
434
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
 
435
  inline bool symbolic_link_exists(const path& p)
 
436
                                       { return is_symlink(symlink_status(p)); }
 
437
# endif
 
438
 
 
439
  inline
 
440
  path system_complete(const path& p)  {return detail::system_complete(p);}
 
441
 
 
442
  inline
 
443
  path system_complete(const path& p, system::error_code& ec)
 
444
                                       {return detail::system_complete(p, &ec);}
 
445
  inline
 
446
  path unique_path(const path& p="%%%%-%%%%-%%%%-%%%%")
 
447
                                       { return detail::unique_path(p); }
 
448
  inline
 
449
  path unique_path(const path& p, system::error_code& ec)
 
450
                                       { return detail::unique_path(p, &ec); }
 
451
 
 
452
//--------------------------------------------------------------------------------------//
 
453
//                                                                                      //
 
454
//                                 directory_entry                                      //
 
455
//                                                                                      //
 
456
//--------------------------------------------------------------------------------------//
 
457
 
 
458
//  GCC has a problem with a member function named path within a namespace or 
 
459
//  sub-namespace that also has a class named path. The workaround is to always
 
460
//  fully qualify the name path when it refers to the class name.
 
461
 
 
462
class BOOST_FILESYSTEM_DECL directory_entry
 
463
{
 
464
public:
 
465
 
 
466
  // compiler generated copy constructor, copy assignment, and destructor apply
 
467
 
 
468
  directory_entry() {}
 
469
  explicit directory_entry(const boost::filesystem::path& p,
 
470
    file_status st = file_status(), file_status symlink_st=file_status())
 
471
    : m_path(p), m_status(st), m_symlink_status(symlink_st)
 
472
    {}
 
473
 
 
474
  void assign(const boost::filesystem::path& p,
 
475
    file_status st = file_status(), file_status symlink_st = file_status())
 
476
    { m_path = p; m_status = st; m_symlink_status = symlink_st; }
 
477
 
 
478
  void replace_filename(const boost::filesystem::path& p,
 
479
    file_status st = file_status(), file_status symlink_st = file_status())
 
480
  {
 
481
    m_path.remove_filename();
 
482
    m_path /= p;
 
483
    m_status = st;
 
484
    m_symlink_status = symlink_st;
 
485
  }
 
486
 
 
487
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
 
488
  void replace_leaf(const boost::filesystem::path& p,
 
489
    file_status st, file_status symlink_st)
 
490
      { replace_filename(p, st, symlink_st); }
 
491
# endif
 
492
 
 
493
  const boost::filesystem::path&  path() const               {return m_path;}
 
494
  file_status   status() const                               {return m_get_status();}
 
495
  file_status   status(system::error_code& ec) const         {return m_get_status(&ec);}
 
496
  file_status   symlink_status() const                       {return m_get_symlink_status();}
 
497
  file_status   symlink_status(system::error_code& ec) const {return m_get_symlink_status(&ec);}
 
498
 
 
499
  bool operator==(const directory_entry& rhs) {return m_path == rhs.m_path;} 
 
500
  bool operator!=(const directory_entry& rhs) {return m_path != rhs.m_path;} 
 
501
  bool operator< (const directory_entry& rhs) {return m_path < rhs.m_path;} 
 
502
  bool operator<=(const directory_entry& rhs) {return m_path <= rhs.m_path;} 
 
503
  bool operator> (const directory_entry& rhs) {return m_path > rhs.m_path;} 
 
504
  bool operator>=(const directory_entry& rhs) {return m_path >= rhs.m_path;} 
 
505
 
 
506
private:
 
507
  boost::filesystem::path   m_path;
 
508
  mutable file_status       m_status;           // stat()-like
 
509
  mutable file_status       m_symlink_status;   // lstat()-like
 
510
 
 
511
  file_status m_get_status(system::error_code* ec=0) const;
 
512
  file_status m_get_symlink_status(system::error_code* ec=0) const;
 
513
}; // directory_entry
 
514
 
 
515
//--------------------------------------------------------------------------------------//
 
516
//                                                                                      //
 
517
//                            directory_iterator helpers                                //
 
518
//                                                                                      //
 
519
//--------------------------------------------------------------------------------------//
 
520
 
 
521
class directory_iterator;
 
522
 
 
523
namespace detail
 
524
{
 
525
  BOOST_FILESYSTEM_DECL
 
526
    system::error_code dir_itr_close(// never throws()
 
527
    void *& handle
 
528
#   if     defined(BOOST_POSIX_API)
 
529
    , void *& buffer
 
530
#   endif
 
531
  ); 
 
532
 
 
533
  struct dir_itr_imp
 
534
  {
 
535
    directory_entry  dir_entry;
 
536
    void*            handle;
 
537
 
 
538
#   ifdef BOOST_POSIX_API
 
539
    void*            buffer;  // see dir_itr_increment implementation
 
540
#   endif
 
541
 
 
542
    dir_itr_imp() : handle(0)
 
543
#   ifdef BOOST_POSIX_API
 
544
      , buffer(0)
 
545
#   endif
 
546
    {}
 
547
 
 
548
    ~dir_itr_imp() // never throws
 
549
    {
 
550
      dir_itr_close(handle
 
551
#       if defined(BOOST_POSIX_API)
 
552
         , buffer
 
553
#       endif
 
554
    );
 
555
    }
 
556
  };
 
557
 
 
558
  // see path::iterator: comment below
 
559
  BOOST_FILESYSTEM_DECL void directory_iterator_construct(directory_iterator& it,
 
560
    const path& p, system::error_code* ec);
 
561
  BOOST_FILESYSTEM_DECL void directory_iterator_increment(directory_iterator& it,
 
562
    system::error_code* ec);
 
563
 
 
564
}  // namespace detail
 
565
 
 
566
//--------------------------------------------------------------------------------------//
 
567
//                                                                                      //
 
568
//                                directory_iterator                                    //
 
569
//                                                                                      //
 
570
//--------------------------------------------------------------------------------------//
 
571
 
 
572
  class directory_iterator
 
573
    : public boost::iterator_facade< directory_iterator,
 
574
                                     directory_entry,
 
575
                                     boost::single_pass_traversal_tag >
 
576
  {
 
577
  public:
 
578
 
 
579
    directory_iterator(){}  // creates the "end" iterator
 
580
 
 
581
    // iterator_facade derived classes don't seem to like implementations in
 
582
    // separate translation unit dll's, so forward to detail functions
 
583
    explicit directory_iterator(const path& p)
 
584
        : m_imp(new detail::dir_itr_imp)
 
585
          { detail::directory_iterator_construct(*this, p, 0); }
 
586
 
 
587
    directory_iterator(const path& p, system::error_code& ec)
 
588
        : m_imp(new detail::dir_itr_imp)
 
589
          { detail::directory_iterator_construct(*this, p, &ec); }
 
590
 
 
591
   ~directory_iterator() {} // never throws
 
592
 
 
593
    directory_iterator& increment(system::error_code& ec)
 
594
    { 
 
595
      detail::directory_iterator_increment(*this, &ec);
 
596
      return *this;
 
597
    }
 
598
 
 
599
  private:
 
600
    friend struct detail::dir_itr_imp;
 
601
    friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_construct(directory_iterator& it,
 
602
      const path& p, system::error_code* ec);
 
603
    friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_increment(directory_iterator& it,
 
604
      system::error_code* ec);
 
605
 
 
606
    // shared_ptr provides shallow-copy semantics required for InputIterators.
 
607
    // m_imp.get()==0 indicates the end iterator.
 
608
    boost::shared_ptr< detail::dir_itr_imp >  m_imp;
 
609
 
 
610
    friend class boost::iterator_core_access;
 
611
 
 
612
    boost::iterator_facade<
 
613
      directory_iterator,
 
614
      directory_entry,
 
615
      boost::single_pass_traversal_tag >::reference dereference() const 
 
616
    {
 
617
      BOOST_ASSERT(m_imp.get() && "attempt to dereference end iterator");
 
618
      return m_imp->dir_entry;
 
619
    }
 
620
 
 
621
    void increment() { detail::directory_iterator_increment(*this, 0); }
 
622
 
 
623
    bool equal(const directory_iterator& rhs) const
 
624
      { return m_imp == rhs.m_imp; }
 
625
  };
 
626
 
 
627
//--------------------------------------------------------------------------------------//
 
628
//                                                                                      //
 
629
//                      recursive_directory_iterator helpers                            //
 
630
//                                                                                      //
 
631
//--------------------------------------------------------------------------------------//
 
632
 
 
633
  namespace detail
 
634
  {
 
635
    struct recur_dir_itr_imp
 
636
    {
 
637
      typedef directory_iterator element_type;
 
638
      std::stack< element_type, std::vector< element_type > > m_stack;
 
639
      int  m_level;
 
640
      bool m_no_push_request;
 
641
 
 
642
      recur_dir_itr_imp() : m_level(0), m_no_push_request(false) {}
 
643
 
 
644
      void increment(system::error_code* ec);  // ec == 0 means throw on error
 
645
 
 
646
      void pop();
 
647
 
 
648
    };
 
649
 
 
650
    //  Implementation is inline to avoid dynamic linking difficulties with m_stack:
 
651
    //  Microsoft warning C4251, m_stack needs to have dll-interface to be used by
 
652
    //  clients of struct 'boost::filesystem::detail::recur_dir_itr_imp'
 
653
 
 
654
    inline
 
655
    void recur_dir_itr_imp::increment(system::error_code* ec)
 
656
    // ec == 0 means throw on error
 
657
    {
 
658
      if (m_no_push_request)
 
659
        { m_no_push_request = false; }
 
660
      else if (is_directory(m_stack.top()->status()))
 
661
      {
 
662
        if (ec == 0)
 
663
          m_stack.push(directory_iterator(m_stack.top()->path()));
 
664
        else
 
665
        {
 
666
          m_stack.push(directory_iterator(m_stack.top()->path(), *ec));
 
667
          if (*ec) return;
 
668
        }
 
669
        if (m_stack.top() != directory_iterator())
 
670
        {
 
671
          ++m_level;
 
672
          return;
 
673
        }
 
674
        m_stack.pop();
 
675
      }
 
676
 
 
677
      while (!m_stack.empty() && ++m_stack.top() == directory_iterator())
 
678
      {
 
679
        m_stack.pop();
 
680
        --m_level;
 
681
      }
 
682
    }
 
683
 
 
684
    inline
 
685
    void recur_dir_itr_imp::pop()
 
686
    {
 
687
      BOOST_ASSERT(m_level > 0 && "pop() on recursive_directory_iterator with level < 1");
 
688
 
 
689
      do
 
690
      {
 
691
        m_stack.pop();
 
692
        --m_level;
 
693
      }
 
694
      while (!m_stack.empty() && ++m_stack.top() == directory_iterator());
 
695
    }
 
696
  } // namespace detail
 
697
 
 
698
//--------------------------------------------------------------------------------------//
 
699
//                                                                                      //
 
700
//                           recursive_directory_iterator                               //
 
701
//                                                                                      //
 
702
//--------------------------------------------------------------------------------------//
 
703
 
 
704
  class recursive_directory_iterator
 
705
    : public boost::iterator_facade<
 
706
        recursive_directory_iterator,
 
707
        directory_entry,
 
708
        boost::single_pass_traversal_tag >
 
709
  {
 
710
  public:
 
711
 
 
712
    recursive_directory_iterator(){}  // creates the "end" iterator
 
713
 
 
714
    explicit recursive_directory_iterator(const path& dir_path)
 
715
      : m_imp(new detail::recur_dir_itr_imp)
 
716
    {
 
717
      m_imp->m_stack.push(directory_iterator(dir_path));
 
718
      if (m_imp->m_stack.top() == directory_iterator())
 
719
        { m_imp.reset (); }
 
720
    }
 
721
 
 
722
    recursive_directory_iterator(const path& dir_path,
 
723
      system::error_code & ec)
 
724
    : m_imp(new detail::recur_dir_itr_imp)
 
725
    {
 
726
      m_imp->m_stack.push(directory_iterator(dir_path, ec));
 
727
      if (m_imp->m_stack.top() == directory_iterator())
 
728
        { m_imp.reset (); }
 
729
    }
 
730
 
 
731
    recursive_directory_iterator& increment(system::error_code* ec)
 
732
    {
 
733
      BOOST_ASSERT(m_imp.get() && "increment() on end recursive_directory_iterator");
 
734
      m_imp->increment(ec);
 
735
      return *this;
 
736
    }
 
737
 
 
738
    int level() const
 
739
    { 
 
740
      BOOST_ASSERT(m_imp.get() && "level() on end recursive_directory_iterator");
 
741
      return m_imp->m_level;
 
742
    }
 
743
 
 
744
    bool no_push_request() const
 
745
    {
 
746
      BOOST_ASSERT(m_imp.get() && "no_push_request() on end recursive_directory_iterator");
 
747
      return m_imp->m_no_push_request;
 
748
    }
 
749
 
 
750
    void pop()
 
751
    { 
 
752
      BOOST_ASSERT(m_imp.get() && "pop() on end recursive_directory_iterator");
 
753
      m_imp->pop();
 
754
      if (m_imp->m_stack.empty()) m_imp.reset(); // done, so make end iterator
 
755
    }
 
756
 
 
757
    void no_push()
 
758
    {
 
759
      BOOST_ASSERT(m_imp.get() && "no_push() on end recursive_directory_iterator");
 
760
      m_imp->m_no_push_request = true;
 
761
    }
 
762
 
 
763
    file_status status() const
 
764
    {
 
765
      BOOST_ASSERT(m_imp.get()
 
766
        && "status() on end recursive_directory_iterator");
 
767
      return m_imp->m_stack.top()->status();
 
768
    }
 
769
 
 
770
    file_status symlink_status() const
 
771
    {
 
772
      BOOST_ASSERT(m_imp.get()
 
773
        && "symlink_status() on end recursive_directory_iterator");
 
774
      return m_imp->m_stack.top()->symlink_status();
 
775
    }
 
776
 
 
777
  private:
 
778
 
 
779
    // shared_ptr provides shallow-copy semantics required for InputIterators.
 
780
    // m_imp.get()==0 indicates the end iterator.
 
781
    boost::shared_ptr< detail::recur_dir_itr_imp >  m_imp;
 
782
 
 
783
    friend class boost::iterator_core_access;
 
784
 
 
785
    boost::iterator_facade< 
 
786
      recursive_directory_iterator,
 
787
      directory_entry,
 
788
      boost::single_pass_traversal_tag >::reference
 
789
    dereference() const 
 
790
    {
 
791
      BOOST_ASSERT(m_imp.get() && "dereference of end recursive_directory_iterator");
 
792
      return *m_imp->m_stack.top();
 
793
    }
 
794
 
 
795
    void increment()
 
796
    { 
 
797
      BOOST_ASSERT(m_imp.get() && "increment of end recursive_directory_iterator");
 
798
      m_imp->increment(0);
 
799
      if (m_imp->m_stack.empty()) m_imp.reset(); // done, so make end iterator
 
800
    }
 
801
 
 
802
    bool equal(const recursive_directory_iterator& rhs) const
 
803
      { return m_imp == rhs.m_imp; }
 
804
 
 
805
  };
 
806
 
 
807
# if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
 
808
  typedef recursive_directory_iterator wrecursive_directory_iterator;
 
809
# endif
 
810
 
 
811
//--------------------------------------------------------------------------------------//
 
812
//                                                                                      //
 
813
//                            class filesystem_error                                    //
 
814
//                                                                                      //
 
815
//--------------------------------------------------------------------------------------//
 
816
  
 
817
  class BOOST_SYMBOL_VISIBLE filesystem_error : public system::system_error
 
818
  {
 
819
  // see http://www.boost.org/more/error_handling.html for design rationale
 
820
 
 
821
  // all functions are inline to avoid issues with crossing dll boundaries
 
822
 
 
823
  public:
 
824
    // compiler generates copy constructor and copy assignment
 
825
 
 
826
    filesystem_error(
 
827
      const std::string & what_arg, system::error_code ec)
 
828
      : system::system_error(ec, what_arg)
 
829
    {
 
830
      try
 
831
      {
 
832
        m_imp_ptr.reset(new m_imp);
 
833
      }
 
834
      catch (...) { m_imp_ptr.reset(); }
 
835
    }
 
836
 
 
837
    filesystem_error(
 
838
      const std::string & what_arg, const path& path1_arg,
 
839
      system::error_code ec)
 
840
      : system::system_error(ec, what_arg)
 
841
    {
 
842
      try
 
843
      {
 
844
        m_imp_ptr.reset(new m_imp);
 
845
        m_imp_ptr->m_path1 = path1_arg;
 
846
      }
 
847
      catch (...) { m_imp_ptr.reset(); }
 
848
    }
 
849
    
 
850
    filesystem_error(
 
851
      const std::string & what_arg, const path& path1_arg,
 
852
      const path& path2_arg, system::error_code ec)
 
853
      : system::system_error(ec, what_arg)
 
854
    {
 
855
      try
 
856
      {
 
857
        m_imp_ptr.reset(new m_imp);
 
858
        m_imp_ptr->m_path1 = path1_arg;
 
859
        m_imp_ptr->m_path2 = path2_arg;
 
860
      }
 
861
      catch (...) { m_imp_ptr.reset(); }
 
862
    }
 
863
 
 
864
    ~filesystem_error() throw() {}
 
865
 
 
866
    const path& path1() const
 
867
    {
 
868
      static const path empty_path;
 
869
      return m_imp_ptr.get() ? m_imp_ptr->m_path1 : empty_path ;
 
870
    }
 
871
    const path& path2() const
 
872
    {
 
873
      static const path empty_path;
 
874
      return m_imp_ptr.get() ? m_imp_ptr->m_path2 : empty_path ;
 
875
    }
 
876
 
 
877
    const char* what() const throw()
 
878
    {
 
879
      if (!m_imp_ptr.get())
 
880
        return system::system_error::what();
 
881
 
 
882
      try
 
883
      {
 
884
        if (m_imp_ptr->m_what.empty())
 
885
        {
 
886
          m_imp_ptr->m_what = system::system_error::what();
 
887
          if (!m_imp_ptr->m_path1.empty())
 
888
          {
 
889
            m_imp_ptr->m_what += ": \"";
 
890
            m_imp_ptr->m_what += m_imp_ptr->m_path1.string();
 
891
            m_imp_ptr->m_what += "\"";
 
892
          }
 
893
          if (!m_imp_ptr->m_path2.empty())
 
894
          {
 
895
            m_imp_ptr->m_what += ", \"";
 
896
            m_imp_ptr->m_what += m_imp_ptr->m_path2.string();
 
897
            m_imp_ptr->m_what += "\"";
 
898
          }
 
899
        }
 
900
        return m_imp_ptr->m_what.c_str();
 
901
      }
 
902
      catch (...)
 
903
      {
 
904
        return system::system_error::what();
 
905
      }
 
906
    }
 
907
 
 
908
  private:
 
909
    struct m_imp
 
910
    {
 
911
      path         m_path1; // may be empty()
 
912
      path         m_path2; // may be empty()
 
913
      std::string  m_what;  // not built until needed
 
914
    };
 
915
    boost::shared_ptr<m_imp> m_imp_ptr;
 
916
  };
 
917
 
 
918
//  test helper  -----------------------------------------------------------------------//
 
919
 
 
920
//  Not part of the documented interface since false positives are possible;
 
921
//  there is no law that says that an OS that has large stat.st_size
 
922
//  actually supports large file sizes.
 
923
 
 
924
  namespace detail
 
925
  {
 
926
    BOOST_FILESYSTEM_DECL bool possible_large_file_size_support();
 
927
  }
 
928
 
 
929
  } // namespace filesystem3
 
930
} // namespace boost
 
931
 
 
932
//----------------------------------------------------------------------------//
 
933
 
 
934
namespace boost
 
935
{
 
936
  namespace filesystem
 
937
  {
 
938
    using filesystem3::absolute;
 
939
    using filesystem3::block_file;
 
940
    using filesystem3::character_file;
 
941
    using filesystem3::copy_file;
 
942
    using filesystem3::copy_option;
 
943
    using filesystem3::copy_symlink;
 
944
    using filesystem3::create_directories;
 
945
    using filesystem3::create_directory;
 
946
    using filesystem3::create_hard_link;
 
947
    using filesystem3::create_symlink;
 
948
    using filesystem3::current_path;
 
949
    using filesystem3::directory_entry;
 
950
    using filesystem3::directory_file;
 
951
    using filesystem3::directory_iterator;
 
952
    using filesystem3::equivalent;
 
953
    using filesystem3::exists;
 
954
    using filesystem3::fifo_file;
 
955
    using filesystem3::file_not_found;
 
956
    using filesystem3::file_size;
 
957
    using filesystem3::file_status;
 
958
    using filesystem3::file_type;
 
959
    using filesystem3::filesystem_error;
 
960
    using filesystem3::hard_link_count;
 
961
    using filesystem3::is_directory;
 
962
    using filesystem3::is_directory;
 
963
    using filesystem3::is_empty;
 
964
    using filesystem3::is_other;
 
965
    using filesystem3::is_regular_file;
 
966
    using filesystem3::is_symlink;
 
967
    using filesystem3::last_write_time;
 
968
    using filesystem3::read_symlink;
 
969
    using filesystem3::recursive_directory_iterator;
 
970
    using filesystem3::regular_file;
 
971
    using filesystem3::remove;
 
972
    using filesystem3::remove_all;
 
973
    using filesystem3::rename;
 
974
    using filesystem3::resize_file;
 
975
    using filesystem3::socket_file;
 
976
    using filesystem3::space;
 
977
    using filesystem3::space_info;
 
978
    using filesystem3::status;
 
979
    using filesystem3::status_error;
 
980
    using filesystem3::status_known;
 
981
    using filesystem3::symlink_file;
 
982
    using filesystem3::symlink_status;
 
983
    using filesystem3::system_complete;
 
984
    using filesystem3::type_unknown;
 
985
    using filesystem3::unique_path;
 
986
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
 
987
    using filesystem3::initial_path;
 
988
    using filesystem3::is_regular;
 
989
    using filesystem3::status_unknown;
 
990
    using filesystem3::symbolic_link_exists;
 
991
    //using filesystem3::wdirectory_iterator;
 
992
    //using filesystem3::wdirectory_entry;
 
993
# endif
 
994
    namespace detail
 
995
    {
 
996
      using filesystem3::detail::possible_large_file_size_support;
 
997
    }
 
998
  }
 
999
}
 
1000
 
 
1001
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
 
1002
#endif // BOOST_FILESYSTEM3_OPERATIONS_HPP