BVB Source Codes

mars Show operations.hpp Source code

Return Download mars: download operations.hpp Source code - Download mars Source code - Type:.hpp
  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/config.hpp>
  25. #include <boost/filesystem/path.hpp>
  26.  
  27. #include <boost/detail/scoped_enum_emulation.hpp>
  28. #include <boost/detail/bitmask.hpp>
  29. #include <boost/system/error_code.hpp>
  30. #include <boost/system/system_error.hpp>
  31. #include <boost/shared_ptr.hpp>
  32. #include <boost/utility/enable_if.hpp>
  33. #include <boost/type_traits/is_same.hpp>
  34. #include <boost/cstdint.hpp>
  35. #include <boost/range/mutable_iterator.hpp>
  36. #include <boost/range/const_iterator.hpp>
  37. #include <boost/assert.hpp>
  38. #include <boost/core/no_exceptions_support.hpp>
  39. #include <string>
  40. #include <utility> // for pair
  41. #include <ctime>
  42. #include <vector>
  43. #include <stack>
  44.  
  45. #ifdef BOOST_WINDOWS_API
  46. #  include <fstream>
  47. #endif
  48.  
  49. #include <boost/config/abi_prefix.hpp> // must be the last #include
  50.  
  51. //--------------------------------------------------------------------------------------//
  52.  
  53. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost
  54. {
  55.   namespace filesystem
  56.   {
  57.  
  58.     //--------------------------------------------------------------------------------------//
  59.     //                                                                                      //
  60.     //                            class filesystem_error                                    //
  61.     //                                                                                      //
  62.     //--------------------------------------------------------------------------------------//
  63.  
  64.     class BOOST_SYMBOL_VISIBLE filesystem_error : public system::system_error
  65.     {
  66.       // see http://www.boost.org/more/error_handling.html for design rationale
  67.  
  68.       // all functions are inline to avoid issues with crossing dll boundaries
  69.  
  70.       // functions previously throw() are now BOOST_NOEXCEPT_OR_NOTHROW
  71.       // functions previously without throw() are now BOOST_NOEXCEPT
  72.  
  73.     public:
  74.       // compiler generates copy constructor and copy assignment
  75.  
  76.       filesystem_error(
  77.         const std::string & what_arg, system::error_code ec) BOOST_NOEXCEPT
  78.         : system::system_error(ec, what_arg)
  79.       {
  80.         BOOST_TRY
  81.         {
  82.           m_imp_ptr.reset(new m_imp);
  83.         }
  84.         BOOST_CATCH (...) { m_imp_ptr.reset(); }
  85.       } BOOST_CATCH_END
  86.  
  87.       filesystem_error(
  88.         const std::string & what_arg, const path& path1_arg,
  89.         system::error_code ec) BOOST_NOEXCEPT
  90.         : system::system_error(ec, what_arg)
  91.       {
  92.         BOOST_TRY
  93.         {
  94.           m_imp_ptr.reset(new m_imp);
  95.           m_imp_ptr->m_path1 = path1_arg;
  96.         }
  97.         BOOST_CATCH (...) { m_imp_ptr.reset(); } BOOST_CATCH_END
  98.       }
  99.  
  100.       filesystem_error(
  101.         const std::string & what_arg, const path& path1_arg,
  102.         const path& path2_arg, system::error_code ec) BOOST_NOEXCEPT
  103.         : system::system_error(ec, what_arg)
  104.       {
  105.         BOOST_TRY
  106.         {
  107.           m_imp_ptr.reset(new m_imp);
  108.           m_imp_ptr->m_path1 = path1_arg;
  109.           m_imp_ptr->m_path2 = path2_arg;
  110.         }
  111.         BOOST_CATCH (...) { m_imp_ptr.reset(); } BOOST_CATCH_END
  112.       }
  113.  
  114.       ~filesystem_error() BOOST_NOEXCEPT_OR_NOTHROW{}
  115.  
  116.         const path& path1() const BOOST_NOEXCEPT
  117.       {
  118.         static const path empty_path;
  119.         return m_imp_ptr.get() ? m_imp_ptr->m_path1 : empty_path;
  120.       }
  121.         const path& path2() const  BOOST_NOEXCEPT
  122.       {
  123.         static const path empty_path;
  124.         return m_imp_ptr.get() ? m_imp_ptr->m_path2 : empty_path;
  125.       }
  126.  
  127.         const char* what() const BOOST_NOEXCEPT_OR_NOTHROW
  128.       {
  129.         if (!m_imp_ptr.get())
  130.         return system::system_error::what();
  131.  
  132.         BOOST_TRY
  133.         {
  134.           if (m_imp_ptr->m_what.empty())
  135.           {
  136.             m_imp_ptr->m_what = system::system_error::what();
  137.             if (!m_imp_ptr->m_path1.empty())
  138.             {
  139.               m_imp_ptr->m_what += ": \"";
  140.               m_imp_ptr->m_what += m_imp_ptr->m_path1.string();
  141.               m_imp_ptr->m_what += "\"";
  142.             }
  143.             if (!m_imp_ptr->m_path2.empty())
  144.             {
  145.               m_imp_ptr->m_what += ", \"";
  146.               m_imp_ptr->m_what += m_imp_ptr->m_path2.string();
  147.               m_imp_ptr->m_what += "\"";
  148.             }
  149.           }
  150.           return m_imp_ptr->m_what.c_str();
  151.         }
  152.         BOOST_CATCH (...)
  153.         {
  154.           return system::system_error::what();
  155.         } BOOST_CATCH_END
  156.       }
  157.  
  158.     private:
  159.       struct m_imp
  160.       {
  161.         path         m_path1; // may be empty()
  162.         path         m_path2; // may be empty()
  163.         std::string  m_what;  // not built until needed
  164.       };
  165.       mars_boost::shared_ptr<m_imp> m_imp_ptr;
  166.     };
  167.  
  168. //--------------------------------------------------------------------------------------//
  169. //                                     file_type                                        //
  170. //--------------------------------------------------------------------------------------//
  171.  
  172.   enum file_type
  173.   {
  174.     status_error,
  175. #   ifndef BOOST_FILESYSTEM_NO_DEPRECATED
  176.     status_unknown = status_error,
  177. #   endif
  178.     file_not_found,
  179.     regular_file,
  180.     directory_file,
  181.     // the following may not apply to some operating systems or file systems
  182.     symlink_file,
  183.     block_file,
  184.     character_file,
  185.     fifo_file,
  186.     socket_file,
  187.     reparse_file,  // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink
  188.     type_unknown,  // file does exist, but isn't one of the above types or
  189.                    // we don't have strong enough permission to find its type
  190.  
  191.     _detail_directory_symlink  // internal use only; never exposed to users
  192.   };
  193.  
  194. //--------------------------------------------------------------------------------------//
  195. //                                       perms                                          //
  196. //--------------------------------------------------------------------------------------//
  197.  
  198.   enum perms
  199.   {
  200.     no_perms = 0,       // file_not_found is no_perms rather than perms_not_known
  201.  
  202.     // POSIX equivalent macros given in comments.
  203.     // Values are from POSIX and are given in octal per the POSIX standard.
  204.  
  205.     // permission bits
  206.    
  207.     owner_read = 0400,  // S_IRUSR, Read permission, owner
  208.     owner_write = 0200, // S_IWUSR, Write permission, owner
  209.     owner_exe = 0100,   // S_IXUSR, Execute/search permission, owner
  210.     owner_all = 0700,   // S_IRWXU, Read, write, execute/search by owner
  211.  
  212.     group_read = 040,   // S_IRGRP, Read permission, group
  213.     group_write = 020,  // S_IWGRP, Write permission, group
  214.     group_exe = 010,    // S_IXGRP, Execute/search permission, group
  215.     group_all = 070,    // S_IRWXG, Read, write, execute/search by group
  216.  
  217.     others_read = 04,   // S_IROTH, Read permission, others
  218.     others_write = 02,  // S_IWOTH, Write permission, others
  219.     others_exe = 01,    // S_IXOTH, Execute/search permission, others
  220.     others_all = 07,    // S_IRWXO, Read, write, execute/search by others
  221.  
  222.     all_all = 0777,     // owner_all|group_all|others_all
  223.  
  224.     // other POSIX bits
  225.  
  226.     set_uid_on_exe = 04000, // S_ISUID, Set-user-ID on execution
  227.     set_gid_on_exe = 02000, // S_ISGID, Set-group-ID on execution
  228.     sticky_bit     = 01000, // S_ISVTX,
  229.                             // (POSIX XSI) On directories, restricted deletion flag
  230.                             // (V7) 'sticky bit': save swapped text even after use
  231.                             // (SunOS) On non-directories: don't cache this file
  232.                             // (SVID-v4.2) On directories: restricted deletion flag
  233.                             // Also see http://en.wikipedia.org/wiki/Sticky_bit
  234.  
  235.     perms_mask = 07777,     // all_all|set_uid_on_exe|set_gid_on_exe|sticky_bit
  236.  
  237.     perms_not_known = 0xFFFF, // present when directory_entry cache not loaded
  238.  
  239.     // options for permissions() function
  240.  
  241.     add_perms = 0x1000,     // adds the given permission bits to the current bits
  242.     remove_perms = 0x2000,  // removes the given permission bits from the current bits;
  243.                             // choose add_perms or remove_perms, not both; if neither add_perms
  244.                             // nor remove_perms is given, replace the current bits with
  245.                             // the given bits.
  246.  
  247.     symlink_perms = 0x4000  // on POSIX, don't resolve symlinks; implied on Windows
  248.   };
  249.  
  250.   BOOST_BITMASK(perms)
  251.  
  252. //--------------------------------------------------------------------------------------//
  253. //                                    file_status                                       //
  254. //--------------------------------------------------------------------------------------//
  255.  
  256.   class BOOST_FILESYSTEM_DECL file_status
  257.   {
  258.   public:
  259.              file_status() BOOST_NOEXCEPT
  260.                : m_value(status_error), m_perms(perms_not_known) {}
  261.     explicit file_status(file_type v) BOOST_NOEXCEPT
  262.                : m_value(v), m_perms(perms_not_known)  {}
  263.              file_status(file_type v, perms prms) BOOST_NOEXCEPT
  264.                : m_value(v), m_perms(prms) {}
  265.  
  266.   //  As of October 2015 the interaction between noexcept and =default is so troublesome
  267.   //  for VC++, GCC, and probably other compilers, that =default is not used with noexcept
  268.   //  functions. GCC is not even consistent for the same release on different platforms.
  269.  
  270.     file_status(const file_status& rhs) BOOST_NOEXCEPT
  271.       : m_value(rhs.m_value), m_perms(rhs.m_perms) {}
  272.     file_status& operator=(const file_status& rhs) BOOST_NOEXCEPT
  273.     {
  274.       m_value = rhs.m_value;
  275.       m_perms = rhs.m_perms;
  276.       return *this;
  277.     }
  278.  
  279. # if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  280.     file_status(file_status&& rhs) BOOST_NOEXCEPT
  281.     {
  282.       m_value = std::move(rhs.m_value);
  283.       m_perms = std::move(rhs.m_perms);
  284.     }
  285.     file_status& operator=(file_status&& rhs) BOOST_NOEXCEPT
  286.     {
  287.       m_value = std::move(rhs.m_value);
  288.       m_perms = std::move(rhs.m_perms);
  289.       return *this;
  290.     }
  291. # endif
  292.  
  293.  
  294.     // observers
  295.     file_type  type() const BOOST_NOEXCEPT            { return m_value; }
  296.     perms      permissions() const BOOST_NOEXCEPT     { return m_perms; }
  297.  
  298.     // modifiers
  299.     void       type(file_type v) BOOST_NOEXCEPT       { m_value = v; }
  300.     void       permissions(perms prms) BOOST_NOEXCEPT { m_perms = prms; }
  301.  
  302.     bool operator==(const file_status& rhs) const BOOST_NOEXCEPT
  303.       { return type() == rhs.type() &&
  304.         permissions() == rhs.permissions(); }
  305.     bool operator!=(const file_status& rhs) const BOOST_NOEXCEPT
  306.       { return !(*this == rhs); }
  307.  
  308.   private:
  309.     file_type   m_value;
  310.     enum perms  m_perms;
  311.   };
  312.  
  313.   inline bool type_present(file_status f) BOOST_NOEXCEPT
  314.                                           { return f.type() != status_error; }
  315.   inline bool permissions_present(file_status f) BOOST_NOEXCEPT
  316.                                           {return f.permissions() != perms_not_known;}
  317.   inline bool status_known(file_status f) BOOST_NOEXCEPT
  318.                                           { return type_present(f) && permissions_present(f); }
  319.   inline bool exists(file_status f) BOOST_NOEXCEPT
  320.                                           { return f.type() != status_error
  321.                                                 && f.type() != file_not_found; }
  322.   inline bool is_regular_file(file_status f) BOOST_NOEXCEPT
  323.                                           { return f.type() == regular_file; }
  324.   inline bool is_directory(file_status f) BOOST_NOEXCEPT
  325.                                           { return f.type() == directory_file; }
  326.   inline bool is_symlink(file_status f) BOOST_NOEXCEPT
  327.                                           { return f.type() == symlink_file; }
  328.   inline bool is_other(file_status f) BOOST_NOEXCEPT
  329.                                           { return exists(f) && !is_regular_file(f)
  330.                                                 && !is_directory(f) && !is_symlink(f); }
  331.  
  332. # ifndef BOOST_FILESYSTEM_NO_DEPRECATED
  333.   inline bool is_regular(file_status f) BOOST_NOEXCEPT { return f.type() == regular_file; }
  334. # endif
  335.  
  336.   struct space_info
  337.   {
  338.     // all values are byte counts
  339.     mars_boost::uintmax_t capacity;
  340.     mars_boost::uintmax_t free;      // <= capacity
  341.     mars_boost::uintmax_t available; // <= free
  342.   };
  343.  
  344.   BOOST_SCOPED_ENUM_START(copy_option)
  345.     {none=0, fail_if_exists = none, overwrite_if_exists};
  346.   BOOST_SCOPED_ENUM_END
  347.  
  348. //--------------------------------------------------------------------------------------//
  349. //                             implementation details                                   //
  350. //--------------------------------------------------------------------------------------//
  351.  
  352.   namespace detail
  353.   {
  354.     //  We cannot pass a BOOST_SCOPED_ENUM to a compled function because it will result
  355.     //  in an undefined reference if the library is compled with -std=c++0x but the use
  356.     //  is compiled in C++03 mode, or visa versa. See tickets 6124, 6779, 10038.
  357.     enum copy_option {none=0, fail_if_exists = none, overwrite_if_exists};
  358.  
  359.     BOOST_FILESYSTEM_DECL
  360.     file_status status(const path&p, system::error_code* ec=0);
  361.     BOOST_FILESYSTEM_DECL
  362.     file_status symlink_status(const path& p, system::error_code* ec=0);
  363.     BOOST_FILESYSTEM_DECL
  364.     bool is_empty(const path& p, system::error_code* ec=0);
  365.     BOOST_FILESYSTEM_DECL
  366.     path initial_path(system::error_code* ec=0);
  367.     BOOST_FILESYSTEM_DECL
  368.     path canonical(const path& p, const path& base, system::error_code* ec=0);
  369.     BOOST_FILESYSTEM_DECL
  370.     void copy(const path& from, const path& to, system::error_code* ec=0);
  371.     BOOST_FILESYSTEM_DECL
  372.     void copy_directory(const path& from, const path& to, system::error_code* ec=0);
  373.     BOOST_FILESYSTEM_DECL
  374.     void copy_file(const path& from, const path& to,  // See ticket #2925
  375.                     detail::copy_option option, system::error_code* ec=0);
  376.     BOOST_FILESYSTEM_DECL
  377.     void copy_symlink(const path& existing_symlink, const path& new_symlink, system::error_code* ec=0);
  378.     BOOST_FILESYSTEM_DECL
  379.     bool create_directories(const path& p, system::error_code* ec=0);
  380.     BOOST_FILESYSTEM_DECL
  381.     bool create_directory(const path& p, system::error_code* ec=0);
  382.     BOOST_FILESYSTEM_DECL
  383.     void create_directory_symlink(const path& to, const path& from,
  384.                                   system::error_code* ec=0);
  385.     BOOST_FILESYSTEM_DECL
  386.     void create_hard_link(const path& to, const path& from, system::error_code* ec=0);
  387.     BOOST_FILESYSTEM_DECL
  388.     void create_symlink(const path& to, const path& from, system::error_code* ec=0);
  389.     BOOST_FILESYSTEM_DECL
  390.     path current_path(system::error_code* ec=0);
  391.     BOOST_FILESYSTEM_DECL
  392.     void current_path(const path& p, system::error_code* ec=0);
  393.     BOOST_FILESYSTEM_DECL
  394.     bool equivalent(const path& p1, const path& p2, system::error_code* ec=0);
  395.     BOOST_FILESYSTEM_DECL
  396.     mars_boost::uintmax_t file_size(const path& p, system::error_code* ec=0);
  397.     BOOST_FILESYSTEM_DECL
  398.     mars_boost::uintmax_t hard_link_count(const path& p, system::error_code* ec=0);
  399.     BOOST_FILESYSTEM_DECL
  400.     std::time_t last_write_time(const path& p, system::error_code* ec=0);
  401.     BOOST_FILESYSTEM_DECL
  402.     void last_write_time(const path& p, const std::time_t new_time,
  403.                          system::error_code* ec=0);
  404.     BOOST_FILESYSTEM_DECL
  405.     void permissions(const path& p, perms prms, system::error_code* ec=0);
  406.     BOOST_FILESYSTEM_DECL
  407.     path read_symlink(const path& p, system::error_code* ec=0);
  408.     BOOST_FILESYSTEM_DECL
  409.     path relative(const path& p, const path& base, system::error_code* ec = 0);
  410.     BOOST_FILESYSTEM_DECL
  411.     bool remove(const path& p, system::error_code* ec=0);
  412.     BOOST_FILESYSTEM_DECL
  413.     mars_boost::uintmax_t remove_all(const path& p, system::error_code* ec=0);
  414.     BOOST_FILESYSTEM_DECL
  415.     void rename(const path& old_p, const path& new_p, system::error_code* ec=0);
  416.     BOOST_FILESYSTEM_DECL
  417.     void resize_file(const path& p, uintmax_t size, system::error_code* ec=0);
  418.     BOOST_FILESYSTEM_DECL
  419.     space_info space(const path& p, system::error_code* ec=0);
  420.     BOOST_FILESYSTEM_DECL
  421.     path system_complete(const path& p, system::error_code* ec=0);
  422.     BOOST_FILESYSTEM_DECL
  423.     path temp_directory_path(system::error_code* ec=0);
  424.     BOOST_FILESYSTEM_DECL
  425.     path unique_path(const path& p, system::error_code* ec=0);
  426.     BOOST_FILESYSTEM_DECL
  427.     path weakly_canonical(const path& p, system::error_code* ec = 0);
  428.   }  // namespace detail            
  429.  
  430. //--------------------------------------------------------------------------------------//
  431. //                                                                                      //
  432. //                             status query functions                                   //
  433. //                                                                                      //
  434. //--------------------------------------------------------------------------------------//
  435.  
  436.   inline
  437.   file_status status(const path& p)    {return detail::status(p);}
  438.   inline
  439.   file_status status(const path& p, system::error_code& ec)
  440.                                        {return detail::status(p, &ec);}
  441.   inline
  442.   file_status symlink_status(const path& p) {return detail::symlink_status(p);}
  443.   inline
  444.   file_status symlink_status(const path& p, system::error_code& ec)
  445.                                        {return detail::symlink_status(p, &ec);}
  446.   inline
  447.   bool exists(const path& p)           {return exists(detail::status(p));}
  448.   inline
  449.   bool exists(const path& p, system::error_code& ec)
  450.                                        {return exists(detail::status(p, &ec));}
  451.   inline
  452.   bool is_directory(const path& p)     {return is_directory(detail::status(p));}
  453.   inline
  454.   bool is_directory(const path& p, system::error_code& ec)
  455.                                        {return is_directory(detail::status(p, &ec));}
  456.   inline
  457.   bool is_regular_file(const path& p)  {return is_regular_file(detail::status(p));}
  458.   inline
  459.   bool is_regular_file(const path& p, system::error_code& ec)
  460.                                        {return is_regular_file(detail::status(p, &ec));}
  461.   inline
  462.   bool is_other(const path& p)         {return is_other(detail::status(p));}
  463.   inline
  464.   bool is_other(const path& p, system::error_code& ec)
  465.                                        {return is_other(detail::status(p, &ec));}
  466.   inline
  467.   bool is_symlink(const path& p)       {return is_symlink(detail::symlink_status(p));}
  468.   inline
  469.   bool is_symlink(const path& p, system::error_code& ec)
  470.                                        {return is_symlink(detail::symlink_status(p, &ec));}
  471. # ifndef BOOST_FILESYSTEM_NO_DEPRECATED
  472.   inline
  473.   bool is_regular(const path& p)       {return is_regular(detail::status(p));}
  474.   inline
  475.   bool is_regular(const path& p, system::error_code& ec)
  476.                                        {return is_regular(detail::status(p, &ec));}
  477. # endif
  478.  
  479.   inline
  480.   bool is_empty(const path& p)         {return detail::is_empty(p);}
  481.   inline
  482.   bool is_empty(const path& p, system::error_code& ec)
  483.                                        {return detail::is_empty(p, &ec);}
  484.  
  485. //--------------------------------------------------------------------------------------//
  486. //                                                                                      //
  487. //                             operational functions                                    //
  488. //                  in alphabetical order, unless otherwise noted                       //
  489. //                                                                                      //
  490. //--------------------------------------------------------------------------------------//
  491.  
  492.   //  forward declarations
  493.   path current_path();  // fwd declaration
  494.   path initial_path();
  495.  
  496.   BOOST_FILESYSTEM_DECL
  497.   path absolute(const path& p, const path& base=current_path());
  498.   //  If base.is_absolute(), throws nothing. Thus no need for ec argument
  499.  
  500.   inline
  501.   path canonical(const path& p, const path& base=current_path())
  502.                                        {return detail::canonical(p, base);}
  503.   inline
  504.   path canonical(const path& p, system::error_code& ec)
  505.                                        {return detail::canonical(p, current_path(), &ec);}
  506.   inline
  507.   path canonical(const path& p, const path& base, system::error_code& ec)
  508.                                        {return detail::canonical(p, base, &ec);}
  509.  
  510. # ifndef BOOST_FILESYSTEM_NO_DEPRECATED
  511.   inline
  512.   path complete(const path& p)
  513.   {
  514.     return absolute(p, initial_path());
  515.   }
  516.  
  517.   inline
  518.   path complete(const path& p, const path& base)
  519.   {
  520.     return absolute(p, base);
  521.   }
  522. # endif
  523.  
  524.   inline
  525.   void copy(const path& from, const path& to) {detail::copy(from, to);}
  526.  
  527.   inline
  528.   void copy(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
  529.                                        {detail::copy(from, to, &ec);}
  530.   inline
  531.   void copy_directory(const path& from, const path& to)
  532.                                        {detail::copy_directory(from, to);}
  533.   inline
  534.   void copy_directory(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
  535.                                        {detail::copy_directory(from, to, &ec);}
  536.   inline
  537.   void copy_file(const path& from, const path& to,   // See ticket #2925
  538.                  BOOST_SCOPED_ENUM(copy_option) option)
  539.   {
  540.     detail::copy_file(from, to, static_cast<detail::copy_option>(option));
  541.   }
  542.   inline
  543.   void copy_file(const path& from, const path& to)
  544.   {
  545.     detail::copy_file(from, to, detail::fail_if_exists);
  546.   }
  547.   inline
  548.   void copy_file(const path& from, const path& to,   // See ticket #2925
  549.                  BOOST_SCOPED_ENUM(copy_option) option, system::error_code& ec) BOOST_NOEXCEPT
  550.   {
  551.     detail::copy_file(from, to, static_cast<detail::copy_option>(option), &ec);
  552.   }
  553.   inline
  554.   void copy_file(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
  555.   {
  556.     detail::copy_file(from, to, detail::fail_if_exists, &ec);
  557.   }
  558.   inline
  559.   void copy_symlink(const path& existing_symlink,
  560.                     const path& new_symlink) {detail::copy_symlink(existing_symlink, new_symlink);}
  561.  
  562.   inline
  563.   void copy_symlink(const path& existing_symlink, const path& new_symlink,
  564.                     system::error_code& ec) BOOST_NOEXCEPT
  565.                                        {detail::copy_symlink(existing_symlink, new_symlink, &ec);}
  566.   inline
  567.   bool create_directories(const path& p) {return detail::create_directories(p);}
  568.  
  569.   inline
  570.   bool create_directories(const path& p, system::error_code& ec) BOOST_NOEXCEPT
  571.                                        {return detail::create_directories(p, &ec);}
  572.   inline
  573.   bool create_directory(const path& p) {return detail::create_directory(p);}
  574.  
  575.   inline
  576.   bool create_directory(const path& p, system::error_code& ec) BOOST_NOEXCEPT
  577.                                        {return detail::create_directory(p, &ec);}
  578.   inline
  579.   void create_directory_symlink(const path& to, const path& from)
  580.                                        {detail::create_directory_symlink(to, from);}
  581.   inline
  582.   void create_directory_symlink(const path& to, const path& from, system::error_code& ec) BOOST_NOEXCEPT
  583.                                        {detail::create_directory_symlink(to, from, &ec);}
  584.   inline
  585.   void create_hard_link(const path& to, const path& new_hard_link) {detail::create_hard_link(to, new_hard_link);}
  586.  
  587.   inline
  588.   void create_hard_link(const path& to, const path& new_hard_link, system::error_code& ec) BOOST_NOEXCEPT
  589.                                        {detail::create_hard_link(to, new_hard_link, &ec);}
  590.   inline
  591.   void create_symlink(const path& to, const path& new_symlink) {detail::create_symlink(to, new_symlink);}
  592.  
  593.   inline
  594.   void create_symlink(const path& to, const path& new_symlink, system::error_code& ec) BOOST_NOEXCEPT
  595.                                        {detail::create_symlink(to, new_symlink, &ec);}
  596.   inline
  597.   path current_path()                  {return detail::current_path();}
  598.  
  599.   inline
  600.   path current_path(system::error_code& ec) BOOST_NOEXCEPT {return detail::current_path(&ec);}
  601.  
  602.   inline
  603.   void current_path(const path& p)     {detail::current_path(p);}
  604.  
  605.   inline
  606.   void current_path(const path& p, system::error_code& ec) BOOST_NOEXCEPT {detail::current_path(p, &ec);}
  607.  
  608.   inline
  609.   bool equivalent(const path& p1, const path& p2) {return detail::equivalent(p1, p2);}
  610.  
  611.   inline
  612.   bool equivalent(const path& p1, const path& p2, system::error_code& ec) BOOST_NOEXCEPT
  613.                                        {return detail::equivalent(p1, p2, &ec);}
  614.   inline
  615.   mars_boost::uintmax_t file_size(const path& p) {return detail::file_size(p);}
  616.  
  617.   inline
  618.   mars_boost::uintmax_t file_size(const path& p, system::error_code& ec) BOOST_NOEXCEPT
  619.                                        {return detail::file_size(p, &ec);}
  620.   inline
  621.   mars_boost::uintmax_t hard_link_count(const path& p) {return detail::hard_link_count(p);}
  622.  
  623.   inline
  624.   mars_boost::uintmax_t hard_link_count(const path& p, system::error_code& ec) BOOST_NOEXCEPT
  625.                                        {return detail::hard_link_count(p, &ec);}
  626.   inline
  627.   path initial_path()                  {return detail::initial_path();}
  628.  
  629.   inline
  630.   path initial_path(system::error_code& ec) {return detail::initial_path(&ec);}
  631.  
  632.   template <class Path>
  633.   path initial_path() {return initial_path();}
  634.   template <class Path>
  635.   path initial_path(system::error_code& ec) {return detail::initial_path(&ec);}
  636.  
  637.   inline
  638.   std::time_t last_write_time(const path& p) {return detail::last_write_time(p);}
  639.  
  640.   inline
  641.   std::time_t last_write_time(const path& p, system::error_code& ec) BOOST_NOEXCEPT
  642.                                        {return detail::last_write_time(p, &ec);}
  643.   inline
  644.   void last_write_time(const path& p, const std::time_t new_time)
  645.                                        {detail::last_write_time(p, new_time);}
  646.   inline
  647.   void last_write_time(const path& p, const std::time_t new_time,
  648.                        system::error_code& ec) BOOST_NOEXCEPT
  649.                                        {detail::last_write_time(p, new_time, &ec);}
  650.   inline
  651.   void permissions(const path& p, perms prms)
  652.                                        {detail::permissions(p, prms);}
  653.   inline
  654.   void permissions(const path& p, perms prms, system::error_code& ec) BOOST_NOEXCEPT
  655.                                        {detail::permissions(p, prms, &ec);}
  656.  
  657.   inline
  658.   path read_symlink(const path& p)     {return detail::read_symlink(p);}
  659.  
  660.   inline
  661.   path read_symlink(const path& p, system::error_code& ec)
  662.                                        {return detail::read_symlink(p, &ec);}
  663.   inline
  664.     // For standardization, if the committee doesn't like "remove", consider "eliminate"
  665.   bool remove(const path& p)           {return detail::remove(p);}
  666.  
  667.   inline
  668.   bool remove(const path& p, system::error_code& ec) BOOST_NOEXCEPT
  669.                                        {return detail::remove(p, &ec);}
  670.  
  671.   inline
  672.   mars_boost::uintmax_t remove_all(const path& p) {return detail::remove_all(p);}
  673.    
  674.   inline
  675.   mars_boost::uintmax_t remove_all(const path& p, system::error_code& ec) BOOST_NOEXCEPT
  676.                                        {return detail::remove_all(p, &ec);}
  677.   inline
  678.   void rename(const path& old_p, const path& new_p) {detail::rename(old_p, new_p);}
  679.  
  680.   inline
  681.   void rename(const path& old_p, const path& new_p, system::error_code& ec) BOOST_NOEXCEPT
  682.                                        {detail::rename(old_p, new_p, &ec);}
  683.   inline  // name suggested by Scott McMurray
  684.   void resize_file(const path& p, uintmax_t size) {detail::resize_file(p, size);}
  685.  
  686.   inline
  687.   void resize_file(const path& p, uintmax_t size, system::error_code& ec) BOOST_NOEXCEPT
  688.                                        {detail::resize_file(p, size, &ec);}
  689.   inline
  690.   path relative(const path& p, const path& base=current_path())
  691.                                        {return detail::relative(p, base);}
  692.   inline
  693.   path relative(const path& p, system::error_code& ec)
  694.                                        {return detail::relative(p, current_path(), &ec);}
  695.   inline
  696.   path relative(const path& p, const path& base, system::error_code& ec)
  697.                                        {return detail::relative(p, base, &ec);}
  698.   inline
  699.   space_info space(const path& p)      {return detail::space(p);}
  700.  
  701.   inline
  702.   space_info space(const path& p, system::error_code& ec) BOOST_NOEXCEPT
  703.                                        {return detail::space(p, &ec);}
  704.  
  705. # ifndef BOOST_FILESYSTEM_NO_DEPRECATED
  706.   inline bool symbolic_link_exists(const path& p)
  707.                                        { return is_symlink(symlink_status(p)); }
  708. # endif
  709.  
  710.   inline
  711.   path system_complete(const path& p)  {return detail::system_complete(p);}
  712.  
  713.   inline
  714.   path system_complete(const path& p, system::error_code& ec)
  715.                                        {return detail::system_complete(p, &ec);}
  716.   inline
  717.   path temp_directory_path()           {return detail::temp_directory_path();}
  718.  
  719.   inline
  720.   path temp_directory_path(system::error_code& ec)
  721.                                        {return detail::temp_directory_path(&ec);}
  722.   inline
  723.   path unique_path(const path& p="%%%%-%%%%-%%%%-%%%%")
  724.                                        {return detail::unique_path(p);}
  725.   inline
  726.   path unique_path(const path& p, system::error_code& ec)
  727.                                        {return detail::unique_path(p, &ec);}
  728.   inline
  729.   path weakly_canonical(const path& p)   {return detail::weakly_canonical(p);}
  730.  
  731.   inline
  732.   path weakly_canonical(const path& p, system::error_code& ec)
  733.                                        {return detail::weakly_canonical(p, &ec);}
  734.  
  735. //--------------------------------------------------------------------------------------//
  736. //                                                                                      //
  737. //                                 directory_entry                                      //
  738. //                                                                                      //
  739. //--------------------------------------------------------------------------------------//
  740.  
  741. //  GCC has a problem with a member function named path within a namespace or
  742. //  sub-namespace that also has a class named path. The workaround is to always
  743. //  fully qualify the name path when it refers to the class name.
  744.  
  745. class BOOST_FILESYSTEM_DECL directory_entry
  746. {
  747. public:
  748.   typedef mars_boost::filesystem::path::value_type value_type;   // enables class path ctor taking directory_entry
  749.  
  750.   directory_entry() BOOST_NOEXCEPT {}
  751.   explicit directory_entry(const mars_boost::filesystem::path& p)
  752.     : m_path(p), m_status(file_status()), m_symlink_status(file_status())
  753.     {}
  754.   directory_entry(const mars_boost::filesystem::path& p,
  755.     file_status st, file_status symlink_st = file_status())
  756.     : m_path(p), m_status(st), m_symlink_status(symlink_st) {}
  757.  
  758.   directory_entry(const directory_entry& rhs)
  759.     : m_path(rhs.m_path), m_status(rhs.m_status), m_symlink_status(rhs.m_symlink_status){}
  760.  
  761.   directory_entry& operator=(const directory_entry& rhs)
  762.   {
  763.     m_path = rhs.m_path;
  764.     m_status = rhs.m_status;
  765.     m_symlink_status = rhs.m_symlink_status;
  766.     return *this;
  767.   }
  768.  
  769.   //  As of October 2015 the interaction between noexcept and =default is so troublesome
  770.   //  for VC++, GCC, and probably other compilers, that =default is not used with noexcept
  771.   //  functions. GCC is not even consistent for the same release on different platforms.
  772.  
  773. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  774.   directory_entry(directory_entry&& rhs) BOOST_NOEXCEPT
  775.   {
  776.     m_path = std::move(rhs.m_path);
  777.     m_status = std::move(rhs.m_status);
  778.     m_symlink_status = std::move(rhs.m_symlink_status);
  779.   }
  780.   directory_entry& operator=(directory_entry&& rhs) BOOST_NOEXCEPT
  781.   {
  782.     m_path = std::move(rhs.m_path);
  783.     m_status = std::move(rhs.m_status);
  784.     m_symlink_status = std::move(rhs.m_symlink_status);
  785.     return *this;
  786.   }
  787. #endif
  788.  
  789.   void assign(const mars_boost::filesystem::path& p,
  790.     file_status st = file_status(), file_status symlink_st = file_status())
  791.     { m_path = p; m_status = st; m_symlink_status = symlink_st; }
  792.  
  793.   void replace_filename(const mars_boost::filesystem::path& p,
  794.     file_status st = file_status(), file_status symlink_st = file_status())
  795.   {
  796.     m_path.remove_filename();
  797.     m_path /= p;
  798.     m_status = st;
  799.     m_symlink_status = symlink_st;
  800.   }
  801.  
  802. # ifndef BOOST_FILESYSTEM_NO_DEPRECATED
  803.   void replace_leaf(const mars_boost::filesystem::path& p,
  804.     file_status st, file_status symlink_st)
  805.       { replace_filename(p, st, symlink_st); }
  806. # endif
  807.  
  808.   const mars_boost::filesystem::path&  path() const BOOST_NOEXCEPT {return m_path;}
  809.   operator const mars_boost::filesystem::path&() const BOOST_NOEXCEPT
  810.                                                               {return m_path;}
  811.   file_status   status() const                                {return m_get_status();}
  812.   file_status   status(system::error_code& ec) const BOOST_NOEXCEPT
  813.                                                               {return m_get_status(&ec); }
  814.   file_status   symlink_status() const                        {return m_get_symlink_status();}
  815.   file_status   symlink_status(system::error_code& ec) const BOOST_NOEXCEPT
  816.                                                               {return m_get_symlink_status(&ec); }
  817.  
  818.   bool operator==(const directory_entry& rhs) const BOOST_NOEXCEPT {return m_path == rhs.m_path; }
  819.   bool operator!=(const directory_entry& rhs) const BOOST_NOEXCEPT {return m_path != rhs.m_path;}
  820.   bool operator< (const directory_entry& rhs) const BOOST_NOEXCEPT {return m_path < rhs.m_path;}
  821.   bool operator<=(const directory_entry& rhs) const BOOST_NOEXCEPT {return m_path <= rhs.m_path;}
  822.   bool operator> (const directory_entry& rhs) const BOOST_NOEXCEPT {return m_path > rhs.m_path;}
  823.   bool operator>=(const directory_entry& rhs) const BOOST_NOEXCEPT {return m_path >= rhs.m_path;}
  824.  
  825. private:
  826.   mars_boost::filesystem::path   m_path;
  827.   mutable file_status       m_status;           // stat()-like
  828.   mutable file_status       m_symlink_status;   // lstat()-like
  829.  
  830.   file_status m_get_status(system::error_code* ec=0) const;
  831.   file_status m_get_symlink_status(system::error_code* ec=0) const;
  832. }; // directory_entry
  833.  
  834. //--------------------------------------------------------------------------------------//
  835. //                                                                                      //
  836. //                            directory_iterator helpers                                //
  837. //                                                                                      //
  838. //--------------------------------------------------------------------------------------//
  839.  
  840. class directory_iterator;
  841.  
  842. namespace detail
  843. {
  844.   BOOST_FILESYSTEM_DECL
  845.     system::error_code dir_itr_close(// never throws()
  846.     void *& handle
  847. #   if     defined(BOOST_POSIX_API)
  848.     , void *& buffer
  849. #   endif
  850.   );
  851.  
  852.   struct dir_itr_imp
  853.   {
  854.     directory_entry  dir_entry;
  855.     void*            handle;
  856.  
  857. #   ifdef BOOST_POSIX_API
  858.     void*            buffer;  // see dir_itr_increment implementation
  859. #   endif
  860.  
  861.     dir_itr_imp() : handle(0)
  862. #   ifdef BOOST_POSIX_API
  863.       , buffer(0)
  864. #   endif
  865.     {}
  866.  
  867.     ~dir_itr_imp() // never throws
  868.     {
  869.       dir_itr_close(handle
  870. #       if defined(BOOST_POSIX_API)
  871.          , buffer
  872. #       endif
  873.     );
  874.     }
  875.   };
  876.  
  877.   // see path::iterator: comment below
  878.   BOOST_FILESYSTEM_DECL void directory_iterator_construct(directory_iterator& it,
  879.     const path& p, system::error_code* ec);
  880.   BOOST_FILESYSTEM_DECL void directory_iterator_increment(directory_iterator& it,
  881.     system::error_code* ec);
  882.  
  883. }  // namespace detail
  884.  
  885. //--------------------------------------------------------------------------------------//
  886. //                                                                                      //
  887. //                                directory_iterator                                    //
  888. //                                                                                      //
  889. //--------------------------------------------------------------------------------------//
  890.  
  891.   class directory_iterator
  892.     : public mars_boost::iterator_facade< directory_iterator,
  893.                                      directory_entry,
  894.                                      mars_boost::single_pass_traversal_tag >
  895.   {
  896.   public:
  897.  
  898.     directory_iterator() BOOST_NOEXCEPT {}  // creates the "end" iterator
  899.  
  900.     // iterator_facade derived classes don't seem to like implementations in
  901.     // separate translation unit dll's, so forward to detail functions
  902.     explicit directory_iterator(const path& p)
  903.         : m_imp(new detail::dir_itr_imp)
  904.           { detail::directory_iterator_construct(*this, p, 0); }
  905.  
  906.     directory_iterator(const path& p, system::error_code& ec) BOOST_NOEXCEPT
  907.         : m_imp(new detail::dir_itr_imp)
  908.           { detail::directory_iterator_construct(*this, p, &ec); }
  909.  
  910.    ~directory_iterator() {}
  911.  
  912.     directory_iterator& increment(system::error_code& ec) BOOST_NOEXCEPT
  913.     {
  914.       detail::directory_iterator_increment(*this, &ec);
  915.       return *this;
  916.     }
  917.  
  918.   private:
  919.     friend struct detail::dir_itr_imp;
  920.     friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_construct(directory_iterator& it,
  921.       const path& p, system::error_code* ec);
  922.     friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_increment(directory_iterator& it,
  923.       system::error_code* ec);
  924.  
  925.     // shared_ptr provides shallow-copy semantics required for InputIterators.
  926.     // m_imp.get()==0 indicates the end iterator.
  927.     mars_boost::shared_ptr< detail::dir_itr_imp >  m_imp;
  928.  
  929.     friend class mars_boost::iterator_core_access;
  930.  
  931.     mars_boost::iterator_facade<
  932.       directory_iterator,
  933.       directory_entry,
  934.       mars_boost::single_pass_traversal_tag >::reference dereference() const
  935.     {
  936.       BOOST_ASSERT_MSG(m_imp.get(), "attempt to dereference end iterator");
  937.       return m_imp->dir_entry;
  938.     }
  939.  
  940.     void increment() { detail::directory_iterator_increment(*this, 0); }
  941.  
  942.     bool equal(const directory_iterator& rhs) const
  943.       { return m_imp == rhs.m_imp; }
  944.  
  945.   };  // directory_iterator
  946.  
  947.   //  enable directory_iterator C++11 range-base for statement use  --------------------//
  948.  
  949.   //  begin() and end() are only used by a range-based for statement in the context of
  950.   //  auto - thus the top-level const is stripped - so returning const is harmless and
  951.   //  emphasizes begin() is just a pass through.
  952.   inline
  953.   const directory_iterator& begin(const directory_iterator& iter) BOOST_NOEXCEPT
  954.     {return iter;}
  955.   inline
  956.   directory_iterator end(const directory_iterator&) BOOST_NOEXCEPT
  957.     {return directory_iterator();}
  958.  
  959.   //  enable directory_iterator BOOST_FOREACH  -----------------------------------------//
  960.  
  961.   inline
  962.   directory_iterator& range_begin(directory_iterator& iter) BOOST_NOEXCEPT
  963.     {return iter;}
  964.   inline
  965.   directory_iterator range_begin(const directory_iterator& iter) BOOST_NOEXCEPT
  966.     {return iter;}
  967.   inline
  968.   directory_iterator range_end(const directory_iterator&) BOOST_NOEXCEPT
  969.     {return directory_iterator();}
  970.   }  // namespace filesystem
  971.  
  972.   //  namespace mars_boost template specializations
  973.   template<>
  974.   struct range_mutable_iterator<mars_boost::filesystem::directory_iterator>
  975.     { typedef mars_boost::filesystem::directory_iterator type; };
  976.   template<>
  977.   struct range_const_iterator <mars_boost::filesystem::directory_iterator>
  978.     { typedef mars_boost::filesystem::directory_iterator type; };
  979.  
  980. namespace filesystem
  981. {
  982.  
  983. //--------------------------------------------------------------------------------------//
  984. //                                                                                      //
  985. //                      recursive_directory_iterator helpers                            //
  986. //                                                                                      //
  987. //--------------------------------------------------------------------------------------//
  988.  
  989.   BOOST_SCOPED_ENUM_START(symlink_option)
  990.   {
  991.     none,
  992.     no_recurse = none,         // don't follow directory symlinks (default behavior)
  993.     recurse,                   // follow directory symlinks
  994.     _detail_no_push = recurse << 1  // internal use only
  995.   };
  996.   BOOST_SCOPED_ENUM_END
  997.  
  998.   BOOST_BITMASK(BOOST_SCOPED_ENUM(symlink_option))
  999.  
  1000.   namespace detail
  1001.   {
  1002.     struct recur_dir_itr_imp
  1003.     {
  1004.       typedef directory_iterator element_type;
  1005.       std::stack< element_type, std::vector< element_type > > m_stack;
  1006.       int  m_level;
  1007.       BOOST_SCOPED_ENUM(symlink_option) m_options;
  1008.  
  1009.       recur_dir_itr_imp() : m_level(0), m_options(symlink_option::none) {}
  1010.  
  1011.       void increment(system::error_code* ec);  // ec == 0 means throw on error
  1012.  
  1013.       bool push_directory(system::error_code& ec) BOOST_NOEXCEPT;
  1014.  
  1015.       void pop();
  1016.  
  1017.     };
  1018.  
  1019.     //  Implementation is inline to avoid dynamic linking difficulties with m_stack:
  1020.     //  Microsoft warning C4251, m_stack needs to have dll-interface to be used by
  1021.     //  clients of struct 'mars_boost::filesystem::detail::recur_dir_itr_imp'
  1022.  
  1023.     inline
  1024.     bool recur_dir_itr_imp::push_directory(system::error_code& ec) BOOST_NOEXCEPT
  1025.     // Returns: true if push occurs, otherwise false. Always returns false on error.
  1026.     {
  1027.       ec.clear();
  1028.  
  1029.       //  Discover if the iterator is for a directory that needs to be recursed into,
  1030.       //  taking symlinks and options into account.
  1031.  
  1032.       if ((m_options & symlink_option::_detail_no_push) == symlink_option::_detail_no_push)
  1033.         m_options &= ~symlink_option::_detail_no_push;
  1034.  
  1035.       else
  1036.       {
  1037.         // Logic for following predicate was contributed by Daniel Aarno to handle cyclic
  1038.         // symlinks correctly and efficiently, fixing ticket #5652.
  1039.         //   if (((m_options & symlink_option::recurse) == symlink_option::recurse
  1040.         //         || !is_symlink(m_stack.top()->symlink_status()))
  1041.         //       && is_directory(m_stack.top()->status())) ...
  1042.         // The predicate code has since been rewritten to pass error_code arguments,
  1043.         // per ticket #5653.
  1044.  
  1045.         file_status symlink_stat;
  1046.  
  1047.         if ((m_options & symlink_option::recurse) != symlink_option::recurse)
  1048.         {
  1049.           symlink_stat = m_stack.top()->symlink_status(ec);
  1050.           if (ec)
  1051.             return false;
  1052.         }
  1053.  
  1054.         if ((m_options & symlink_option::recurse) == symlink_option::recurse
  1055.           || !is_symlink(symlink_stat))
  1056.         {
  1057.           file_status stat = m_stack.top()->status(ec);
  1058.           if (ec || !is_directory(stat))
  1059.             return false;
  1060.  
  1061.           directory_iterator next(m_stack.top()->path(), ec);
  1062.           if (!ec && next != directory_iterator())
  1063.           {
  1064.             m_stack.push(next);
  1065.             ++m_level;
  1066.             return true;
  1067.           }
  1068.         }
  1069.       }
  1070.       return false;
  1071.     }
  1072.  
  1073.     inline
  1074.     void recur_dir_itr_imp::increment(system::error_code* ec)
  1075.     // ec == 0 means throw on error
  1076.     //
  1077.     // Invariant: On return, the top of the iterator stack is the next valid (possibly
  1078.     // end) iterator, regardless of whether or not an error is reported, and regardless of
  1079.     // whether any error is reported by exception or error code. In other words, progress
  1080.     // is always made so a loop on the iterator will always eventually terminate
  1081.     // regardless of errors.
  1082.     {
  1083.       system::error_code ec_push_directory;
  1084.  
  1085.       //  if various conditions are met, push a directory_iterator into the iterator stack
  1086.       if (push_directory(ec_push_directory))
  1087.       {
  1088.         if (ec)
  1089.           ec->clear();
  1090.         return;
  1091.       }
  1092.  
  1093.       //  Do the actual increment operation on the top iterator in the iterator
  1094.       //  stack, popping the stack if necessary, until either the stack is empty or a
  1095.       //  non-end iterator is reached.
  1096.       while (!m_stack.empty() && ++m_stack.top() == directory_iterator())
  1097.       {
  1098.         m_stack.pop();
  1099.         --m_level;
  1100.       }
  1101.  
  1102.       // report errors if any
  1103.       if (ec_push_directory)
  1104.       {
  1105.         if (ec)
  1106.           *ec = ec_push_directory;
  1107.         else
  1108.         {
  1109.           BOOST_FILESYSTEM_THROW(filesystem_error(
  1110.             "filesystem::recursive_directory_iterator directory error",
  1111.             ec_push_directory));
  1112.         }
  1113.       }
  1114.       else if (ec)
  1115.         ec->clear();
  1116.     }
  1117.  
  1118.     inline
  1119.     void recur_dir_itr_imp::pop()
  1120.     {
  1121.       BOOST_ASSERT_MSG(m_level > 0,
  1122.         "pop() on recursive_directory_iterator with level < 1");
  1123.  
  1124.       do
  1125.       {
  1126.         m_stack.pop();
  1127.         --m_level;
  1128.       }
  1129.       while (!m_stack.empty() && ++m_stack.top() == directory_iterator());
  1130.     }
  1131.   } // namespace detail
  1132.  
  1133. //--------------------------------------------------------------------------------------//
  1134. //                                                                                      //
  1135. //                           recursive_directory_iterator                               //
  1136. //                                                                                      //
  1137. //--------------------------------------------------------------------------------------//
  1138.  
  1139.   class recursive_directory_iterator
  1140.     : public mars_boost::iterator_facade<
  1141.         recursive_directory_iterator,
  1142.         directory_entry,
  1143.         mars_boost::single_pass_traversal_tag >
  1144.   {
  1145.   public:
  1146.  
  1147.     recursive_directory_iterator() BOOST_NOEXCEPT {}  // creates the "end" iterator
  1148.  
  1149.     explicit recursive_directory_iterator(const path& dir_path)  // throws if !exists()
  1150.       : m_imp(new detail::recur_dir_itr_imp)
  1151.     {
  1152.       m_imp->m_options = symlink_option::none;
  1153.       m_imp->m_stack.push(directory_iterator(dir_path));
  1154.       if (m_imp->m_stack.top() == directory_iterator())
  1155.         { m_imp.reset(); }
  1156.     }
  1157.  
  1158.     recursive_directory_iterator(const path& dir_path,
  1159.       BOOST_SCOPED_ENUM(symlink_option) opt)  // throws if !exists()
  1160.       : m_imp(new detail::recur_dir_itr_imp)
  1161.     {
  1162.       m_imp->m_options = opt;
  1163.       m_imp->m_stack.push(directory_iterator(dir_path));
  1164.       if (m_imp->m_stack.top() == directory_iterator())
  1165.         { m_imp.reset (); }
  1166.     }
  1167.  
  1168.     recursive_directory_iterator(const path& dir_path,
  1169.       BOOST_SCOPED_ENUM(symlink_option) opt,
  1170.       system::error_code & ec) BOOST_NOEXCEPT
  1171.     : m_imp(new detail::recur_dir_itr_imp)
  1172.     {
  1173.       m_imp->m_options = opt;
  1174.       m_imp->m_stack.push(directory_iterator(dir_path, ec));
  1175.       if (m_imp->m_stack.top() == directory_iterator())
  1176.         { m_imp.reset (); }
  1177.     }
  1178.  
  1179.     recursive_directory_iterator(const path& dir_path,
  1180.       system::error_code & ec) BOOST_NOEXCEPT
  1181.     : m_imp(new detail::recur_dir_itr_imp)
  1182.     {
  1183.       m_imp->m_options = symlink_option::none;
  1184.       m_imp->m_stack.push(directory_iterator(dir_path, ec));
  1185.       if (m_imp->m_stack.top() == directory_iterator())
  1186.         { m_imp.reset (); }
  1187.     }
  1188.  
  1189.     recursive_directory_iterator& increment(system::error_code& ec) BOOST_NOEXCEPT
  1190.     {
  1191.       BOOST_ASSERT_MSG(m_imp.get(),
  1192.         "increment() on end recursive_directory_iterator");
  1193.       m_imp->increment(&ec);
  1194.       if (m_imp->m_stack.empty())
  1195.         m_imp.reset(); // done, so make end iterator
  1196.       return *this;
  1197.     }
  1198.  
  1199.     int depth() const BOOST_NOEXCEPT
  1200.     {
  1201.       BOOST_ASSERT_MSG(m_imp.get(),
  1202.         "depth() on end recursive_directory_iterator");
  1203.       return m_imp->m_level;
  1204.     }
  1205.  
  1206.     int level() const BOOST_NOEXCEPT { return depth(); }
  1207.  
  1208.     bool recursion_pending() const BOOST_NOEXCEPT
  1209.     {
  1210.       BOOST_ASSERT_MSG(m_imp.get(),
  1211.         "is_no_push_requested() on end recursive_directory_iterator");
  1212.       return (m_imp->m_options & symlink_option::_detail_no_push)
  1213.         == symlink_option::_detail_no_push;
  1214.     }
  1215.  
  1216.     bool no_push_pending() const BOOST_NOEXCEPT { return recursion_pending(); }
  1217.  
  1218. #   ifndef BOOST_FILESYSTEM_NO_DEPRECATED
  1219.     bool no_push_request() const BOOST_NOEXCEPT { return no_push_pending(); }
  1220. #   endif
  1221.  
  1222.     void pop()
  1223.     {
  1224.       BOOST_ASSERT_MSG(m_imp.get(),
  1225.         "pop() on end recursive_directory_iterator");
  1226.       m_imp->pop();
  1227.       if (m_imp->m_stack.empty()) m_imp.reset(); // done, so make end iterator
  1228.     }
  1229.  
  1230.     void disable_recursion_pending(bool value=true) BOOST_NOEXCEPT
  1231.     {
  1232.       BOOST_ASSERT_MSG(m_imp.get(),
  1233.         "no_push() on end recursive_directory_iterator");
  1234.       if (value)
  1235.         m_imp->m_options |= symlink_option::_detail_no_push;
  1236.       else
  1237.         m_imp->m_options &= ~symlink_option::_detail_no_push;
  1238.     }
  1239.  
  1240.     void no_push(bool value=true) BOOST_NOEXCEPT { disable_recursion_pending(value); }
  1241.  
  1242.     file_status status() const
  1243.     {
  1244.       BOOST_ASSERT_MSG(m_imp.get(),
  1245.         "status() on end recursive_directory_iterator");
  1246.       return m_imp->m_stack.top()->status();
  1247.     }
  1248.  
  1249.     file_status symlink_status() const
  1250.     {
  1251.       BOOST_ASSERT_MSG(m_imp.get(),
  1252.         "symlink_status() on end recursive_directory_iterator");
  1253.       return m_imp->m_stack.top()->symlink_status();
  1254.     }
  1255.  
  1256.   private:
  1257.  
  1258.     // shared_ptr provides shallow-copy semantics required for InputIterators.
  1259.     // m_imp.get()==0 indicates the end iterator.
  1260.     mars_boost::shared_ptr< detail::recur_dir_itr_imp >  m_imp;
  1261.  
  1262.     friend class mars_boost::iterator_core_access;
  1263.  
  1264.     mars_boost::iterator_facade<
  1265.       recursive_directory_iterator,
  1266.       directory_entry,
  1267.       mars_boost::single_pass_traversal_tag >::reference
  1268.     dereference() const
  1269.     {
  1270.       BOOST_ASSERT_MSG(m_imp.get(),
  1271.         "dereference of end recursive_directory_iterator");
  1272.       return *m_imp->m_stack.top();
  1273.     }
  1274.  
  1275.     void increment()
  1276.     {
  1277.       BOOST_ASSERT_MSG(m_imp.get(),
  1278.         "increment of end recursive_directory_iterator");
  1279.       m_imp->increment(0);
  1280.       if (m_imp->m_stack.empty())
  1281.         m_imp.reset(); // done, so make end iterator
  1282.     }
  1283.  
  1284.     bool equal(const recursive_directory_iterator& rhs) const
  1285.       { return m_imp == rhs.m_imp; }
  1286.  
  1287.   };  // recursive directory iterator
  1288.  
  1289.   //  enable recursive directory iterator C++11 range-base for statement use  ----------//
  1290.  
  1291.   //  begin() and end() are only used by a range-based for statement in the context of
  1292.   //  auto - thus the top-level const is stripped - so returning const is harmless and
  1293.   //  emphasizes begin() is just a pass through.
  1294.   inline
  1295.   const recursive_directory_iterator&
  1296.     begin(const recursive_directory_iterator& iter) BOOST_NOEXCEPT
  1297.                                                   {return iter;}
  1298.   inline
  1299.   recursive_directory_iterator end(const recursive_directory_iterator&) BOOST_NOEXCEPT
  1300.                                                   {return recursive_directory_iterator();}
  1301.  
  1302.   //  enable recursive directory iterator BOOST_FOREACH  -------------------------------//
  1303.  
  1304.   inline
  1305.   recursive_directory_iterator&
  1306.     range_begin(recursive_directory_iterator& iter) BOOST_NOEXCEPT
  1307.                                                    {return iter;}
  1308.   inline
  1309.   recursive_directory_iterator
  1310.     range_begin(const recursive_directory_iterator& iter) BOOST_NOEXCEPT
  1311.                                                    {return iter;}
  1312.   inline
  1313.   recursive_directory_iterator range_end(const recursive_directory_iterator&) BOOST_NOEXCEPT
  1314.                                                   {return recursive_directory_iterator();}
  1315.   }  // namespace filesystem
  1316.  
  1317.   //  namespace mars_boost template specializations
  1318.   template<>
  1319.   struct range_mutable_iterator<mars_boost::filesystem::recursive_directory_iterator>
  1320.                         { typedef mars_boost::filesystem::recursive_directory_iterator type; };
  1321.   template<>
  1322.   struct range_const_iterator <mars_boost::filesystem::recursive_directory_iterator>
  1323.                         { typedef mars_boost::filesystem::recursive_directory_iterator type; };
  1324.  
  1325. namespace filesystem
  1326. {
  1327.  
  1328. # if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
  1329.   typedef recursive_directory_iterator wrecursive_directory_iterator;
  1330. # endif
  1331.  
  1332. //  test helper  -----------------------------------------------------------------------//
  1333.  
  1334. //  Not part of the documented interface since false positives are possible;
  1335. //  there is no law that says that an OS that has large stat.st_size
  1336. //  actually supports large file sizes.
  1337.  
  1338.   namespace detail
  1339.   {
  1340.     BOOST_FILESYSTEM_DECL bool possible_large_file_size_support();
  1341.   }
  1342.  
  1343.   } // namespace filesystem
  1344. } // namespace mars_boost
  1345.  
  1346. #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
  1347. #endif // BOOST_FILESYSTEM3_OPERATIONS_HPP
  1348.  
downloadoperations.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top