LCOV - code coverage report
Current view: top level - usr/include/boost/filesystem - path.hpp (source / functions) Hit Total Coverage
Test: bitcoincash_test.info Lines: 7 8 87.5 %
Date: 2018-04-13 15:12:50 Functions: 1 1 100.0 %

          Line data    Source code
       1             : //  filesystem path.hpp  ---------------------------------------------------------------//
       2             : 
       3             : //  Copyright Beman Dawes 2002-2005, 2009
       4             : //  Copyright Vladimir Prus 2002
       5             : 
       6             : //  Distributed under the Boost Software License, Version 1.0.
       7             : //  See http://www.boost.org/LICENSE_1_0.txt
       8             : 
       9             : //  Library home page: http://www.boost.org/libs/filesystem
      10             : 
      11             : //  path::stem(), extension(), and replace_extension() are based on
      12             : //  basename(), extension(), and change_extension() from the original
      13             : //  filesystem/convenience.hpp header by Vladimir Prus.
      14             : 
      15             : #ifndef BOOST_FILESYSTEM_PATH_HPP
      16             : #define BOOST_FILESYSTEM_PATH_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_traits.hpp>  // includes <cwchar>
      26             : #include <boost/system/error_code.hpp>
      27             : #include <boost/system/system_error.hpp>
      28             : #include <boost/iterator/iterator_facade.hpp>
      29             : #include <boost/shared_ptr.hpp>
      30             : #include <boost/io/detail/quoted_manip.hpp>
      31             : #include <boost/static_assert.hpp>
      32             : #include <boost/functional/hash_fwd.hpp>
      33             : #include <boost/type_traits/is_integral.hpp>
      34             : #include <string>
      35             : #include <iterator>
      36             : #include <cstring>
      37             : #include <iosfwd>
      38             : #include <stdexcept>
      39             : #include <cassert>
      40             : #include <locale>
      41             : #include <algorithm>
      42             : 
      43             : #include <boost/config/abi_prefix.hpp> // must be the last #include
      44             : 
      45             : namespace boost
      46             : {
      47             : namespace filesystem
      48             : {
      49             :   //------------------------------------------------------------------------------------//
      50             :   //                                                                                    //
      51             :   //                                    class path                                      //
      52             :   //                                                                                    //
      53             :   //------------------------------------------------------------------------------------//
      54             : 
      55        3762 :   class BOOST_FILESYSTEM_DECL path
      56             :   {
      57             :   public:
      58             : 
      59             :     //  value_type is the character type used by the operating system API to
      60             :     //  represent paths.
      61             : 
      62             : # ifdef BOOST_WINDOWS_API
      63             :     typedef wchar_t                        value_type;
      64             :     BOOST_STATIC_CONSTEXPR value_type      preferred_separator = L'\\';
      65             : # else 
      66             :     typedef char                           value_type;
      67             :     BOOST_STATIC_CONSTEXPR value_type      preferred_separator = '/';
      68             : # endif
      69             :     typedef std::basic_string<value_type>  string_type;  
      70             :     typedef std::codecvt<wchar_t, char,
      71             :                          std::mbstate_t>   codecvt_type;
      72             : 
      73             : 
      74             :     //  ----- character encoding conversions -----
      75             : 
      76             :     //  Following the principle of least astonishment, path input arguments
      77             :     //  passed to or obtained from the operating system via objects of
      78             :     //  class path behave as if they were directly passed to or
      79             :     //  obtained from the O/S API, unless conversion is explicitly requested.
      80             :     //
      81             :     //  POSIX specfies that path strings are passed unchanged to and from the
      82             :     //  API. Note that this is different from the POSIX command line utilities,
      83             :     //  which convert according to a locale.
      84             :     //
      85             :     //  Thus for POSIX, char strings do not undergo conversion.  wchar_t strings
      86             :     //  are converted to/from char using the path locale or, if a conversion
      87             :     //  argument is given, using a conversion object modeled on
      88             :     //  std::wstring_convert.
      89             :     //
      90             :     //  The path locale, which is global to the thread, can be changed by the
      91             :     //  imbue() function. It is initialized to an implementation defined locale.
      92             :     //  
      93             :     //  For Windows, wchar_t strings do not undergo conversion. char strings
      94             :     //  are converted using the "ANSI" or "OEM" code pages, as determined by
      95             :     //  the AreFileApisANSI() function, or, if a conversion argument is given,
      96             :     //  using a conversion object modeled on std::wstring_convert.
      97             :     //
      98             :     //  See m_pathname comments for further important rationale.
      99             : 
     100             :     //  TODO: rules needed for operating systems that use / or .
     101             :     //  differently, or format directory paths differently from file paths. 
     102             :     //
     103             :     //  **********************************************************************************
     104             :     //
     105             :     //  More work needed: How to handle an operating system that may have
     106             :     //  slash characters or dot characters in valid filenames, either because
     107             :     //  it doesn't follow the POSIX standard, or because it allows MBCS
     108             :     //  filename encodings that may contain slash or dot characters. For
     109             :     //  example, ISO/IEC 2022 (JIS) encoding which allows switching to
     110             :     //  JIS x0208-1983 encoding. A valid filename in this set of encodings is
     111             :     //  0x1B 0x24 0x42 [switch to X0208-1983] 0x24 0x2F [U+304F Kiragana letter KU]
     112             :     //                                             ^^^^
     113             :     //  Note that 0x2F is the ASCII slash character
     114             :     //
     115             :     //  **********************************************************************************
     116             : 
     117             :     //  Supported source arguments: half-open iterator range, container, c-array,
     118             :     //  and single pointer to null terminated string.
     119             : 
     120             :     //  All source arguments except pointers to null terminated byte strings support
     121             :     //  multi-byte character strings which may have embedded nulls. Embedded null
     122             :     //  support is required for some Asian languages on Windows.
     123             : 
     124             :     //  "const codecvt_type& cvt=codecvt()" default arguments are not used because this
     125             :     //  limits the impact of locale("") initialization failures on POSIX systems to programs
     126             :     //  that actually depend on locale(""). It further ensures that exceptions thrown
     127             :     //  as a result of such failues occur after main() has started, so can be caught. 
     128             : 
     129             :     //  -----  constructors  -----
     130             : 
     131          76 :     path(){}                                          
     132             : 
     133        6740 :     path(const path& p) : m_pathname(p.m_pathname) {}
     134             : 
     135             :     template <class Source>
     136             :     path(Source const& source,
     137             :       typename boost::enable_if<path_traits::is_pathable<
     138             :         typename boost::decay<Source>::type> >::type* =0)
     139             :     {
     140             :       path_traits::dispatch(source, m_pathname);
     141             :     }
     142             : 
     143          10 :     path(const value_type* s) : m_pathname(s) {}
     144             :     path(value_type* s) : m_pathname(s) {}
     145          78 :     path(const string_type& s) : m_pathname(s) {}
     146             :     path(string_type& s) : m_pathname(s) {}
     147             : 
     148             :     template <class Source>
     149             :     path(Source const& source, const codecvt_type& cvt)
     150             :     {
     151             :       path_traits::dispatch(source, m_pathname, cvt);
     152             :     }
     153             : 
     154             :     template <class InputIterator>
     155             :     path(InputIterator begin, InputIterator end)
     156             :     { 
     157             :       if (begin != end)
     158             :       {
     159             :         // convert requires contiguous string, so copy
     160             :         std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
     161             :           seq(begin, end);
     162             :         path_traits::convert(seq.c_str(), seq.c_str()+seq.size(), m_pathname);
     163             :       }
     164             :     }
     165             : 
     166             :     template <class InputIterator>
     167             :     path(InputIterator begin, InputIterator end, const codecvt_type& cvt)
     168             :     { 
     169             :       if (begin != end)
     170             :       {
     171             :         // convert requires contiguous string, so copy
     172             :         std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
     173             :           seq(begin, end);
     174             :         path_traits::convert(seq.c_str(), seq.c_str()+seq.size(), m_pathname, cvt);
     175             :       }
     176             :     }
     177             : 
     178             :     //  -----  assignments  -----
     179             : 
     180             :     path& operator=(const path& p)
     181             :     {
     182          76 :       m_pathname = p.m_pathname;
     183             :       return *this;
     184             :     }
     185             : 
     186             :     template <class Source>
     187             :       typename boost::enable_if<path_traits::is_pathable<
     188             :         typename boost::decay<Source>::type>, path&>::type
     189             :     operator=(Source const& source)
     190             :     {
     191             :       m_pathname.clear();
     192             :       path_traits::dispatch(source, m_pathname);
     193             :       return *this;
     194             :     }
     195             : 
     196             :     //  value_type overloads
     197             : 
     198             :     path& operator=(const value_type* ptr)  // required in case ptr overlaps *this
     199             :                                           {m_pathname = ptr; return *this;}
     200             :     path& operator=(value_type* ptr)  // required in case ptr overlaps *this
     201             :                                           {m_pathname = ptr; return *this;}
     202             :     path& operator=(const string_type& s) {m_pathname = s; return *this;}
     203             :     path& operator=(string_type& s)       {m_pathname = s; return *this;}
     204             : 
     205             :     path& assign(const value_type* ptr, const codecvt_type&)  // required in case ptr overlaps *this
     206             :                                           {m_pathname = ptr; return *this;}
     207             :     template <class Source>
     208             :     path& assign(Source const& source, const codecvt_type& cvt)
     209             :     {
     210             :       m_pathname.clear();
     211             :       path_traits::dispatch(source, m_pathname, cvt);
     212             :       return *this;
     213             :     }
     214             : 
     215             :     template <class InputIterator>
     216             :     path& assign(InputIterator begin, InputIterator end)
     217             :     {
     218             :       m_pathname.clear();
     219             :       if (begin != end)
     220             :       {
     221             :         std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
     222             :           seq(begin, end);
     223             :         path_traits::convert(seq.c_str(), seq.c_str()+seq.size(), m_pathname);
     224             :       }
     225             :       return *this;
     226             :     }
     227             : 
     228             :     template <class InputIterator>
     229             :     path& assign(InputIterator begin, InputIterator end, const codecvt_type& cvt)
     230             :     { 
     231             :       m_pathname.clear();
     232             :       if (begin != end)
     233             :       {
     234             :         std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
     235             :           seq(begin, end);
     236             :         path_traits::convert(seq.c_str(), seq.c_str()+seq.size(), m_pathname, cvt);
     237             :       }
     238             :       return *this;
     239             :     }
     240             : 
     241             :     //  -----  concatenation  -----
     242             : 
     243             :     template <class Source>
     244             :       typename boost::enable_if<path_traits::is_pathable<
     245             :         typename boost::decay<Source>::type>, path&>::type
     246             :     operator+=(Source const& source)
     247             :     {
     248             :       return concat(source);
     249             :     }
     250             : 
     251             :     //  value_type overloads. Same rationale as for constructors above
     252             :     path& operator+=(const path& p)         { m_pathname += p.m_pathname; return *this; }
     253             :     path& operator+=(const value_type* ptr) { m_pathname += ptr; return *this; }
     254             :     path& operator+=(value_type* ptr)       { m_pathname += ptr; return *this; }
     255             :     path& operator+=(const string_type& s)  { m_pathname += s; return *this; }
     256             :     path& operator+=(string_type& s)        { m_pathname += s; return *this; }
     257             :     path& operator+=(value_type c)          { m_pathname += c; return *this; }
     258             : 
     259             :     template <class CharT>
     260             :       typename boost::enable_if<is_integral<CharT>, path&>::type
     261             :     operator+=(CharT c)
     262             :     {
     263             :       CharT tmp[2];
     264             :       tmp[0] = c;
     265             :       tmp[1] = 0;
     266             :       return concat(tmp);
     267             :     }
     268             : 
     269             :     template <class Source>
     270             :     path& concat(Source const& source)
     271             :     {
     272             :       path_traits::dispatch(source, m_pathname);
     273             :       return *this;
     274             :     }
     275             : 
     276             :     template <class Source>
     277             :     path& concat(Source const& source, const codecvt_type& cvt)
     278             :     {
     279             :       path_traits::dispatch(source, m_pathname, cvt);
     280             :       return *this;
     281             :     }
     282             : 
     283             :     template <class InputIterator>
     284             :     path& concat(InputIterator begin, InputIterator end)
     285             :     { 
     286             :       if (begin == end)
     287             :         return *this;
     288             :       std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
     289             :         seq(begin, end);
     290             :       path_traits::convert(seq.c_str(), seq.c_str()+seq.size(), m_pathname);
     291             :       return *this;
     292             :     }
     293             : 
     294             :     template <class InputIterator>
     295             :     path& concat(InputIterator begin, InputIterator end, const codecvt_type& cvt)
     296             :     { 
     297             :       if (begin == end)
     298             :         return *this;
     299             :       std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
     300             :         seq(begin, end);
     301             :       path_traits::convert(seq.c_str(), seq.c_str()+seq.size(), m_pathname, cvt);
     302             :       return *this;
     303             :     }
     304             : 
     305             :     //  -----  appends  -----
     306             : 
     307             :     //  if a separator is added, it is the preferred separator for the platform;
     308             :     //  slash for POSIX, backslash for Windows
     309             : 
     310             :     path& operator/=(const path& p);
     311             : 
     312             :     template <class Source>
     313             :       typename boost::enable_if<path_traits::is_pathable<
     314             :         typename boost::decay<Source>::type>, path&>::type
     315             :     operator/=(Source const& source)
     316             :     {
     317             :       return append(source);
     318             :     }
     319             : 
     320             :     path& operator/=(const value_type* ptr);
     321             :     path& operator/=(value_type* ptr)
     322             :     {
     323             :       return this->operator/=(const_cast<const value_type*>(ptr));
     324             :     }
     325             :     path& operator/=(const string_type& s) { return this->operator/=(path(s)); }
     326             :     path& operator/=(string_type& s)       { return this->operator/=(path(s)); }
     327             : 
     328             :     path& append(const value_type* ptr)  // required in case ptr overlaps *this
     329             :     {
     330             :       this->operator/=(ptr);
     331             :       return *this;
     332             :     }
     333             : 
     334             :     path& append(const value_type* ptr, const codecvt_type&)  // required in case ptr overlaps *this
     335             :     {
     336             :       this->operator/=(ptr);
     337             :       return *this;
     338             :     }
     339             : 
     340             :     template <class Source>
     341             :     path& append(Source const& source);
     342             : 
     343             :     template <class Source>
     344             :     path& append(Source const& source, const codecvt_type& cvt);
     345             : 
     346             :     template <class InputIterator>
     347             :     path& append(InputIterator begin, InputIterator end);
     348             : 
     349             :     template <class InputIterator>
     350             :     path& append(InputIterator begin, InputIterator end, const codecvt_type& cvt);
     351             : 
     352             :     //  -----  modifiers  -----
     353             : 
     354             :     void   clear()             { m_pathname.clear(); }
     355             :     path&  make_preferred()
     356             : #   ifdef BOOST_POSIX_API
     357             :       { return *this; }  // POSIX no effect
     358             : #   else // BOOST_WINDOWS_API
     359             :       ;  // change slashes to backslashes
     360             : #   endif
     361             :     path&  remove_filename();
     362             :     path&  remove_trailing_separator();
     363             :     path&  replace_extension(const path& new_extension = path());
     364             :     void   swap(path& rhs)     { m_pathname.swap(rhs.m_pathname); }
     365             : 
     366             :     //  -----  observers  -----
     367             :   
     368             :     //  For operating systems that format file paths differently than directory
     369             :     //  paths, return values from observers are formatted as file names unless there
     370             :     //  is a trailing separator, in which case returns are formatted as directory
     371             :     //  paths. POSIX and Windows make no such distinction.
     372             : 
     373             :     //  Implementations are permitted to return const values or const references.
     374             : 
     375             :     //  The string or path returned by an observer are specified as being formatted
     376             :     //  as "native" or "generic".
     377             :     //
     378             :     //  For POSIX, these are all the same format; slashes and backslashes are as input and
     379             :     //  are not modified.
     380             :     //
     381             :     //  For Windows,   native:    as input; slashes and backslashes are not modified;
     382             :     //                            this is the format of the internally stored string.
     383             :     //                 generic:   backslashes are converted to slashes
     384             : 
     385             :     //  -----  native format observers  -----
     386             : 
     387             :     const string_type&  native() const { return m_pathname; }          // Throws: nothing
     388             :     const value_type*   c_str() const  { return m_pathname.c_str(); }  // Throws: nothing
     389             : 
     390             :     template <class String>
     391             :     String string() const;
     392             : 
     393             :     template <class String>
     394             :     String string(const codecvt_type& cvt) const;
     395             : 
     396             : #   ifdef BOOST_WINDOWS_API
     397             :     const std::string string() const
     398             :     {
     399             :       std::string tmp;
     400             :       if (!m_pathname.empty())
     401             :         path_traits::convert(&*m_pathname.begin(), &*m_pathname.begin()+m_pathname.size(),
     402             :         tmp);
     403             :       return tmp;
     404             :     }
     405             :     const std::string string(const codecvt_type& cvt) const
     406             :     { 
     407             :       std::string tmp;
     408             :       if (!m_pathname.empty())
     409             :         path_traits::convert(&*m_pathname.begin(), &*m_pathname.begin()+m_pathname.size(),
     410             :           tmp, cvt);
     411             :       return tmp;
     412             :     }
     413             :     
     414             :     //  string_type is std::wstring, so there is no conversion
     415             :     const std::wstring&  wstring() const { return m_pathname; }
     416             :     const std::wstring&  wstring(const codecvt_type&) const { return m_pathname; }
     417             : 
     418             : #   else   // BOOST_POSIX_API
     419             :     //  string_type is std::string, so there is no conversion
     420             :     const std::string&  string() const { return m_pathname; }
     421             :     const std::string&  string(const codecvt_type&) const { return m_pathname; }
     422             : 
     423             :     const std::wstring  wstring() const
     424             :     {
     425             :       std::wstring tmp;
     426             :       if (!m_pathname.empty())
     427             :         path_traits::convert(&*m_pathname.begin(), &*m_pathname.begin()+m_pathname.size(),
     428             :           tmp);
     429             :       return tmp;
     430             :     }
     431             :     const std::wstring  wstring(const codecvt_type& cvt) const
     432             :     { 
     433             :       std::wstring tmp;
     434             :       if (!m_pathname.empty())
     435             :         path_traits::convert(&*m_pathname.begin(), &*m_pathname.begin()+m_pathname.size(),
     436             :           tmp, cvt);
     437             :       return tmp;
     438             :     }
     439             : 
     440             : #   endif
     441             : 
     442             :     //  -----  generic format observers  -----
     443             : 
     444             :     template <class String>
     445             :     String generic_string() const;
     446             : 
     447             :     template <class String>
     448             :     String generic_string(const codecvt_type& cvt) const;
     449             : 
     450             : #   ifdef BOOST_WINDOWS_API
     451             :     const std::string   generic_string() const; 
     452             :     const std::string   generic_string(const codecvt_type& cvt) const; 
     453             :     const std::wstring  generic_wstring() const;
     454             :     const std::wstring  generic_wstring(const codecvt_type&) const { return generic_wstring(); };
     455             : 
     456             : #   else // BOOST_POSIX_API
     457             :     //  On POSIX-like systems, the generic format is the same as the native format
     458             :     const std::string&  generic_string() const  { return m_pathname; }
     459             :     const std::string&  generic_string(const codecvt_type&) const  { return m_pathname; }
     460             :     const std::wstring  generic_wstring() const { return wstring(); }
     461             :     const std::wstring  generic_wstring(const codecvt_type& cvt) const { return wstring(cvt); }
     462             : 
     463             : #   endif
     464             : 
     465             :     //  -----  compare  -----
     466             : 
     467             :     int compare(const path& p) const BOOST_NOEXCEPT;  // generic, lexicographical
     468             :     int compare(const std::string& s) const { return compare(path(s)); }
     469             :     int compare(const value_type* s) const  { return compare(path(s)); }
     470             : 
     471             :     //  -----  decomposition  -----
     472             : 
     473             :     path  root_path() const; 
     474             :     path  root_name() const;         // returns 0 or 1 element path
     475             :                                      // even on POSIX, root_name() is non-empty() for network paths
     476             :     path  root_directory() const;    // returns 0 or 1 element path
     477             :     path  relative_path() const;
     478             :     path  parent_path() const;
     479             :     path  filename() const;          // returns 0 or 1 element path
     480             :     path  stem() const;              // returns 0 or 1 element path
     481             :     path  extension() const;         // returns 0 or 1 element path
     482             : 
     483             :     //  -----  query  -----
     484             : 
     485           0 :     bool empty() const               { return m_pathname.empty(); } // name consistent with std containers
     486             :     bool has_root_path() const       { return has_root_directory() || has_root_name(); }
     487             :     bool has_root_name() const       { return !root_name().empty(); }
     488             :     bool has_root_directory() const  { return !root_directory().empty(); }
     489             :     bool has_relative_path() const   { return !relative_path().empty(); }
     490             :     bool has_parent_path() const     { return !parent_path().empty(); }
     491             :     bool has_filename() const        { return !m_pathname.empty(); }
     492             :     bool has_stem() const            { return !stem().empty(); }
     493             :     bool has_extension() const       { return !extension().empty(); }
     494             :     bool is_absolute() const
     495             :     {
     496             : #     ifdef BOOST_WINDOWS_API
     497             :       return has_root_name() && has_root_directory();
     498             : #     else
     499             :       return has_root_directory();
     500             : #     endif
     501             :     }
     502             :     bool is_relative() const         { return !is_absolute(); } 
     503             : 
     504             :     //  -----  iterators  -----
     505             : 
     506             :     class iterator;
     507             :     typedef iterator const_iterator;
     508             : 
     509             :     iterator begin() const;
     510             :     iterator end() const;
     511             : 
     512             :     //  -----  static member functions  -----
     513             : 
     514             :     static std::locale  imbue(const std::locale& loc);
     515             :     static const        codecvt_type& codecvt();
     516             : 
     517             :     //  -----  deprecated functions  -----
     518             : 
     519             : # if defined(BOOST_FILESYSTEM_DEPRECATED) && defined(BOOST_FILESYSTEM_NO_DEPRECATED)
     520             : #   error both BOOST_FILESYSTEM_DEPRECATED and BOOST_FILESYSTEM_NO_DEPRECATED are defined
     521             : # endif
     522             : 
     523             : # if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
     524             :     //  recently deprecated functions supplied by default
     525             :     path&  normalize()              { return m_normalize(); }
     526             :     path&  remove_leaf()            { return remove_filename(); }
     527             :     path   leaf() const             { return filename(); }
     528             :     path   branch_path() const      { return parent_path(); }
     529             :     bool   has_leaf() const         { return !m_pathname.empty(); }
     530             :     bool   has_branch_path() const  { return !parent_path().empty(); }
     531             :     bool   is_complete() const      { return is_absolute(); }
     532             : # endif
     533             : 
     534             : # if defined(BOOST_FILESYSTEM_DEPRECATED)
     535             :     //  deprecated functions with enough signature or semantic changes that they are
     536             :     //  not supplied by default 
     537             :     const std::string file_string() const               { return string(); }
     538             :     const std::string directory_string() const          { return string(); }
     539             :     const std::string native_file_string() const        { return string(); }
     540             :     const std::string native_directory_string() const   { return string(); }
     541             :     const string_type external_file_string() const      { return native(); }
     542             :     const string_type external_directory_string() const { return native(); }
     543             : 
     544             :     //  older functions no longer supported
     545             :     //typedef bool (*name_check)(const std::string & name);
     546             :     //basic_path(const string_type& str, name_check) { operator/=(str); }
     547             :     //basic_path(const typename string_type::value_type* s, name_check)
     548             :     //  { operator/=(s);}
     549             :     //static bool default_name_check_writable() { return false; } 
     550             :     //static void default_name_check(name_check) {}
     551             :     //static name_check default_name_check() { return 0; }
     552             :     //basic_path& canonize();
     553             : # endif
     554             : 
     555             : //--------------------------------------------------------------------------------------//
     556             : //                            class path private members                                //
     557             : //--------------------------------------------------------------------------------------//
     558             : 
     559             :   private:
     560             : #   if defined(_MSC_VER)
     561             : #     pragma warning(push) // Save warning settings
     562             : #     pragma warning(disable : 4251) // disable warning: class 'std::basic_string<_Elem,_Traits,_Ax>'
     563             : #   endif                            // needs to have dll-interface...
     564             : /*
     565             :       m_pathname has the type, encoding, and format required by the native
     566             :       operating system. Thus for POSIX and Windows there is no conversion for
     567             :       passing m_pathname.c_str() to the O/S API or when obtaining a path from the
     568             :       O/S API. POSIX encoding is unspecified other than for dot and slash
     569             :       characters; POSIX just treats paths as a sequence of bytes. Windows
     570             :       encoding is UCS-2 or UTF-16 depending on the version.
     571             : */
     572             :     string_type  m_pathname;  // Windows: as input; backslashes NOT converted to slashes,
     573             :                               // slashes NOT converted to backslashes
     574             : #   if defined(_MSC_VER)
     575             : #     pragma warning(pop) // restore warning settings.
     576             : #   endif 
     577             : 
     578             :     string_type::size_type m_append_separator_if_needed();
     579             :     //  Returns: If separator is to be appended, m_pathname.size() before append. Otherwise 0.
     580             :     //  Note: An append is never performed if size()==0, so a returned 0 is unambiguous.
     581             : 
     582             :     void m_erase_redundant_separator(string_type::size_type sep_pos);
     583             :     string_type::size_type m_parent_path_end() const;
     584             : 
     585             :     path& m_normalize();
     586             : 
     587             :     // Was qualified; como433beta8 reports:
     588             :     //    warning #427-D: qualified name is not allowed in member declaration 
     589             :     friend class iterator;
     590             :     friend bool operator<(const path& lhs, const path& rhs);
     591             : 
     592             :     // see path::iterator::increment/decrement comment below
     593             :     static void m_path_iterator_increment(path::iterator & it);
     594             :     static void m_path_iterator_decrement(path::iterator & it);
     595             : 
     596             :   };  // class path
     597             : 
     598             :   namespace detail
     599             :   {
     600             :     BOOST_FILESYSTEM_DECL
     601             :       int lex_compare(path::iterator first1, path::iterator last1,
     602             :         path::iterator first2, path::iterator last2);
     603             :     BOOST_FILESYSTEM_DECL
     604             :       const path&  dot_path();
     605             :     BOOST_FILESYSTEM_DECL
     606             :       const path&  dot_dot_path();
     607             :   }
     608             : 
     609             : # ifndef BOOST_FILESYSTEM_NO_DEPRECATED
     610             :   typedef path wpath;
     611             : # endif
     612             : 
     613             :   //------------------------------------------------------------------------------------//
     614             :   //                             class path::iterator                                   //
     615             :   //------------------------------------------------------------------------------------//
     616             :  
     617             :   class path::iterator
     618             :     : public boost::iterator_facade<
     619             :       path::iterator,
     620             :       path const,
     621             :       boost::bidirectional_traversal_tag >
     622             :   {
     623             :   private:
     624             :     friend class boost::iterator_core_access;
     625             :     friend class boost::filesystem::path;
     626             :     friend void m_path_iterator_increment(path::iterator & it);
     627             :     friend void m_path_iterator_decrement(path::iterator & it);
     628             : 
     629             :     const path& dereference() const { return m_element; }
     630             : 
     631             :     bool equal(const iterator & rhs) const
     632             :     {
     633             :       return m_path_ptr == rhs.m_path_ptr && m_pos == rhs.m_pos;
     634             :     }
     635             : 
     636             :     // iterator_facade derived classes don't seem to like implementations in
     637             :     // separate translation unit dll's, so forward to class path static members
     638             :     void increment() { m_path_iterator_increment(*this); }
     639             :     void decrement() { m_path_iterator_decrement(*this); }
     640             : 
     641             :     path                    m_element;   // current element
     642             :     const path*             m_path_ptr;  // path being iterated over
     643             :     string_type::size_type  m_pos;       // position of m_element in
     644             :                                          // m_path_ptr->m_pathname.
     645             :                                          // if m_element is implicit dot, m_pos is the
     646             :                                          // position of the last separator in the path.
     647             :                                          // end() iterator is indicated by 
     648             :                                          // m_pos == m_path_ptr->m_pathname.size()
     649             :   }; // path::iterator
     650             : 
     651             :   //------------------------------------------------------------------------------------//
     652             :   //                                                                                    //
     653             :   //                              non-member functions                                  //
     654             :   //                                                                                    //
     655             :   //------------------------------------------------------------------------------------//
     656             : 
     657             :   //  std::lexicographical_compare would infinately recurse because path iterators
     658             :   //  yield paths, so provide a path aware version
     659             :   inline bool lexicographical_compare(path::iterator first1, path::iterator last1,
     660             :     path::iterator first2, path::iterator last2)
     661             :     { return detail::lex_compare(first1, last1, first2, last2) < 0; }
     662             :   
     663             :   inline bool operator==(const path& lhs, const path& rhs)              {return lhs.compare(rhs) == 0;}
     664             :   inline bool operator==(const path& lhs, const path::string_type& rhs) {return lhs.compare(rhs) == 0;} 
     665             :   inline bool operator==(const path::string_type& lhs, const path& rhs) {return rhs.compare(lhs) == 0;}
     666             :   inline bool operator==(const path& lhs, const path::value_type* rhs)  {return lhs.compare(rhs) == 0;}
     667             :   inline bool operator==(const path::value_type* lhs, const path& rhs)  {return rhs.compare(lhs) == 0;}
     668             :   
     669             :   inline bool operator!=(const path& lhs, const path& rhs)              {return lhs.compare(rhs) != 0;}
     670             :   inline bool operator!=(const path& lhs, const path::string_type& rhs) {return lhs.compare(rhs) != 0;} 
     671             :   inline bool operator!=(const path::string_type& lhs, const path& rhs) {return rhs.compare(lhs) != 0;}
     672             :   inline bool operator!=(const path& lhs, const path::value_type* rhs)  {return lhs.compare(rhs) != 0;}
     673             :   inline bool operator!=(const path::value_type* lhs, const path& rhs)  {return rhs.compare(lhs) != 0;}
     674             : 
     675             :   // TODO: why do == and != have additional overloads, but the others don't?
     676             : 
     677             :   inline bool operator<(const path& lhs, const path& rhs)  {return lhs.compare(rhs) < 0;}
     678             :   inline bool operator<=(const path& lhs, const path& rhs) {return !(rhs < lhs);}
     679             :   inline bool operator> (const path& lhs, const path& rhs) {return rhs < lhs;}
     680             :   inline bool operator>=(const path& lhs, const path& rhs) {return !(lhs < rhs);}
     681             : 
     682             :   inline std::size_t hash_value(const path& x)
     683             :   {
     684             : # ifdef BOOST_WINDOWS_API
     685             :     std::size_t seed = 0;
     686             :     for(const path::value_type* it = x.c_str(); *it; ++it)
     687             :       hash_combine(seed, *it == '/' ? L'\\' : *it);
     688             :     return seed;
     689             : # else   // BOOST_POSIX_API
     690             :     return hash_range(x.native().begin(), x.native().end());
     691             : # endif
     692             :   }
     693             : 
     694             :   inline void swap(path& lhs, path& rhs)                   { lhs.swap(rhs); }
     695             : 
     696        6740 :   inline path operator/(const path& lhs, const path& rhs)  { return path(lhs) /= rhs; }
     697             : 
     698             :   //  inserters and extractors
     699             :   //    use boost::io::quoted() to handle spaces in paths
     700             :   //    use '&' as escape character to ease use for Windows paths
     701             : 
     702             :   template <class Char, class Traits>
     703             :   inline std::basic_ostream<Char, Traits>&
     704             :   operator<<(std::basic_ostream<Char, Traits>& os, const path& p)
     705             :   {
     706             :     return os
     707             :       << boost::io::quoted(p.template string<std::basic_string<Char> >(), static_cast<Char>('&'));
     708             :   }
     709             :   
     710             :   template <class Char, class Traits>
     711             :   inline std::basic_istream<Char, Traits>&
     712             :   operator>>(std::basic_istream<Char, Traits>& is, path& p)
     713             :   {
     714             :     std::basic_string<Char> str;
     715             :     is >> boost::io::quoted(str, static_cast<Char>('&'));
     716             :     p = str;
     717             :     return is;
     718             :   }
     719             :   
     720             :   //  name_checks
     721             : 
     722             :   //  These functions are holdovers from version 1. It isn't clear they have much
     723             :   //  usefulness, or how to generalize them for later versions.
     724             : 
     725             :   BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string & name);
     726             :   BOOST_FILESYSTEM_DECL bool windows_name(const std::string & name);
     727             :   BOOST_FILESYSTEM_DECL bool portable_name(const std::string & name);
     728             :   BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string & name);
     729             :   BOOST_FILESYSTEM_DECL bool portable_file_name(const std::string & name);
     730             :   BOOST_FILESYSTEM_DECL bool native(const std::string & name);
     731             :  
     732             : //--------------------------------------------------------------------------------------//
     733             : //                     class path member template implementation                        //
     734             : //--------------------------------------------------------------------------------------//
     735             : 
     736             :   template <class InputIterator>
     737             :   path& path::append(InputIterator begin, InputIterator end)
     738             :   {
     739             :     if (begin == end)
     740             :       return *this;
     741             :     string_type::size_type sep_pos(m_append_separator_if_needed());
     742             :     std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
     743             :       seq(begin, end);
     744             :     path_traits::convert(seq.c_str(), seq.c_str()+seq.size(), m_pathname);
     745             :     if (sep_pos)
     746             :       m_erase_redundant_separator(sep_pos);
     747             :     return *this;
     748             :   }
     749             : 
     750             :   template <class InputIterator>
     751             :   path& path::append(InputIterator begin, InputIterator end, const codecvt_type& cvt)
     752             :   {
     753             :     if (begin == end)
     754             :       return *this;
     755             :     string_type::size_type sep_pos(m_append_separator_if_needed());
     756             :     std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
     757             :       seq(begin, end);
     758             :     path_traits::convert(seq.c_str(), seq.c_str()+seq.size(), m_pathname, cvt);
     759             :     if (sep_pos)
     760             :       m_erase_redundant_separator(sep_pos);
     761             :     return *this;
     762             :   }
     763             : 
     764             :   template <class Source>
     765             :   path& path::append(Source const& source)
     766             :   {
     767             :     if (path_traits::empty(source))
     768             :       return *this;
     769             :     string_type::size_type sep_pos(m_append_separator_if_needed());
     770             :     path_traits::dispatch(source, m_pathname);
     771             :     if (sep_pos)
     772             :       m_erase_redundant_separator(sep_pos);
     773             :     return *this;
     774             :   }
     775             : 
     776             :   template <class Source>
     777             :   path& path::append(Source const& source, const codecvt_type& cvt)
     778             :   {
     779             :     if (path_traits::empty(source))
     780             :       return *this;
     781             :     string_type::size_type sep_pos(m_append_separator_if_needed());
     782             :     path_traits::dispatch(source, m_pathname, cvt);
     783             :     if (sep_pos)
     784             :       m_erase_redundant_separator(sep_pos);
     785             :     return *this;
     786             :   }
     787             : 
     788             : //--------------------------------------------------------------------------------------//
     789             : //                     class path member template specializations                       //
     790             : //--------------------------------------------------------------------------------------//
     791             : 
     792             :   template <> inline
     793             :   std::string path::string<std::string>() const
     794             :     { return string(); }
     795             : 
     796             :   template <> inline
     797             :   std::wstring path::string<std::wstring>() const
     798             :     { return wstring(); }
     799             : 
     800             :   template <> inline
     801             :   std::string path::string<std::string>(const codecvt_type& cvt) const
     802             :     { return string(cvt); }
     803             : 
     804             :   template <> inline
     805             :   std::wstring path::string<std::wstring>(const codecvt_type& cvt) const
     806             :     { return wstring(cvt); }
     807             : 
     808             :   template <> inline
     809             :   std::string path::generic_string<std::string>() const
     810             :     { return generic_string(); }
     811             : 
     812             :   template <> inline
     813             :   std::wstring path::generic_string<std::wstring>() const
     814             :     { return generic_wstring(); }
     815             : 
     816             :   template <> inline
     817             :   std::string path::generic_string<std::string>(const codecvt_type& cvt) const
     818             :     { return generic_string(cvt); }
     819             : 
     820             :   template <> inline
     821             :   std::wstring path::generic_string<std::wstring>(const codecvt_type& cvt) const
     822             :     { return generic_wstring(cvt); }
     823             : 
     824             :   //--------------------------------------------------------------------------------------//
     825             :   //                     path_traits convert function implementations                     //
     826             :   //                        requiring path::codecvt() be visable                          //
     827             :   //--------------------------------------------------------------------------------------//
     828             : 
     829             : namespace path_traits
     830             : {  //  without codecvt
     831             : 
     832             :   inline
     833             :     void convert(const char* from,
     834             :     const char* from_end,    // 0 for null terminated MBCS
     835             :     std::wstring & to)
     836             :   {
     837             :     convert(from, from_end, to, path::codecvt());
     838             :   }
     839             : 
     840             :   inline
     841             :     void convert(const wchar_t* from,
     842             :     const wchar_t* from_end,  // 0 for null terminated MBCS
     843             :     std::string & to)
     844             :   {
     845             :     convert(from, from_end, to, path::codecvt());
     846             :   }
     847             : 
     848             :   inline
     849             :     void convert(const char* from,
     850             :     std::wstring & to)
     851             :   {
     852             :     BOOST_ASSERT(from);
     853             :     convert(from, 0, to, path::codecvt());
     854             :   }
     855             : 
     856             :   inline
     857             :     void convert(const wchar_t* from,
     858             :     std::string & to)
     859             :   {
     860             :     BOOST_ASSERT(from);
     861             :     convert(from, 0, to, path::codecvt());
     862             :   }
     863             : }  // namespace path_traits
     864             : }  // namespace filesystem
     865             : }  // namespace boost
     866             : 
     867             : //----------------------------------------------------------------------------//
     868             : 
     869             : #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
     870             : 
     871             : #endif  // BOOST_FILESYSTEM_PATH_HPP

Generated by: LCOV version 1.12