$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r50459 - in sandbox/filesystem-v3: boost/filesystem libs/filesystem/src
From: bdawes_at_[hidden]
Date: 2009-01-04 10:24:30
Author: bemandawes
Date: 2009-01-04 10:24:30 EST (Sun, 04 Jan 2009)
New Revision: 50459
URL: http://svn.boost.org/trac/boost/changeset/50459
Log:
filesystem.v3: get ready for POSIX
Text files modified: 
   sandbox/filesystem-v3/boost/filesystem/path.hpp    |   152 +++++++++++++-------------------------- 
   sandbox/filesystem-v3/libs/filesystem/src/path.cpp |    45 +++++++---                              
   2 files changed, 81 insertions(+), 116 deletions(-)
Modified: sandbox/filesystem-v3/boost/filesystem/path.hpp
==============================================================================
--- sandbox/filesystem-v3/boost/filesystem/path.hpp	(original)
+++ sandbox/filesystem-v3/boost/filesystem/path.hpp	2009-01-04 10:24:30 EST (Sun, 04 Jan 2009)
@@ -18,6 +18,7 @@
 
    * Windows, POSIX, conversions for char16_t, char32_t for supporting compilers.
    * Windows, POSIX, conversions for user-defined types.
+   * Fix inserter/extractor problems; see comments in commented out code below.
    * Need an error category for codecvt errors. Seed path.cpp detail::append, etc.
    * Add Alternate Data Stream test cases. See http://en.wikipedia.org/wiki/NTFS Features.
    * test case: relational on paths differing only in trailing separator. rationale?
@@ -132,73 +133,6 @@
   };
 
   //------------------------------------------------------------------------------------//
-  //                           implementation details                                   //
-  //------------------------------------------------------------------------------------//
-
-  namespace detail
-  {
-
-#   ifdef BOOST_WINDOWS_API
-
-    BOOST_FILESYSTEM_DECL
-    void append( const char * begin,
-                 const char * end,      // 0 for null terminated MBCS
-                 std::wstring & target, system::error_code & ec );
-
-    BOOST_FILESYSTEM_DECL
-    std::string convert_to_string( const std::wstring & src, system::error_code & ec ); 
-
-# else   // BOOST_POSIX_API
- 
-    typedef std::string              string_type;
-    typedef string_type::value_type  value_type;
-    typedef string_type::size_type   size_type;
-
-    //  See comment at equivalent location in Windows API detail above
-
-    //  -----  char[] to string  -----
-
-    inline void append( const char * begin,
-                         const char * end,      // 0 for null terminated MBCS
-                         std::string & target,
-                         system::error_code & ec )
-    {
-      ec.clear(); 
-      target.assign( begin, end ); // but what if this throws bad_alloc?
-    }
-
-    inline void append( const char * begin, std::string & target,
-      system::error_code & ec )
-    {
-      ec.clear(); 
-      target += begin; // but what if throws bad_alloc?
-    }
-
-#   ifndef BOOST_FILESYSTEM_NARROW_ONLY
-
-    //  -----  wchar_t[] to string  -----  
-
-    inline void append( const wchar_t * begin, const wchar_t * end,
-      std::string & target, system::error_code & ec );
-
-    inline void append( const wchar_t * begin, std::string & target,
-      system::error_code & ec )
-    { 
-      append( begin, 0, target, ec );
-    }
-
-    //  ----- convert ----
-
-    BOOST_FILESYSTEM_DECL
-    std::wstring convert_to_wstring( const std::string & src, system::error_code & ec ); 
-
-#   endif
-
-# endif  // BOOST_POSIX_API
-
-}  // namespace detail
-
-  //------------------------------------------------------------------------------------//
   //                                                                                    //
   //                                path_traits                                         //
   //                                                                                    //
@@ -211,14 +145,15 @@
 
 namespace path_traits
 {
-
-  // path representation type
+  
 #ifdef BOOST_WINDOWS_API
-  typedef std::wstring string_type;  
+  typedef std::wstring  string_type;  // path internal representation type
 #else 
-  typedef std::string string_type;
+  typedef std::string   string_type;
 #endif
 
+  typedef string_type::value_type           value_type;
+
   template< class I > struct is_iterator { static const bool value = false; };
   template< class C > struct is_container { static const bool value = false; };
 
@@ -236,10 +171,39 @@
   template< class String >   // specialization required
   String convert( const string_type & source, system::error_code & ec );
 
+}  // namespace path_traits
+  
   //------------------------------------------------------------------------------------//
-  //                              specializations                                       //
+  //                           implementation details                                   //
   //------------------------------------------------------------------------------------//
 
+namespace detail
+{
+#ifdef BOOST_WINDOWS_API
+  typedef std::string   extern_string_type; 
+#else 
+  typedef std::wstring  extern_string_type; 
+#endif
+
+  typedef extern_string_type::value_type  extern_value_type;
+
+  BOOST_FILESYSTEM_DECL
+  void append( const extern_value_type * begin,
+               const extern_value_type * end,      // 0 for null terminated MBCS
+               path_traits::string_type & target, system::error_code & ec );
+
+  BOOST_FILESYSTEM_DECL
+  extern_string_type convert_to_string( const path_traits::string_type & src,
+                                 system::error_code & ec ); 
+
+}  // namespace detail
+
+  //------------------------------------------------------------------------------------//
+  //                             path_traits specializations                            //
+  //------------------------------------------------------------------------------------//
+
+namespace path_traits
+{
   template<> struct is_iterator<const char *> { static const bool value = true; };
   template<> struct is_iterator<char *> { static const bool value = true; };
   template<> struct is_iterator<std::string::iterator> { static const bool value = true; };
@@ -257,7 +221,7 @@
     const string_type::value_type * end, string_type & target, system::error_code & ec )
   {
     ec.clear(); 
-    target.assign( begin, end ); // but what if throws bad_alloc?
+    target.assign( begin, end ); // TODO: what if throws bad_alloc?
   }
 
   template<>
@@ -265,40 +229,38 @@
     string_type & target, system::error_code & ec )
   {
     ec.clear(); 
-    target += begin; // but what if throws bad_alloc?
+    target += begin; // TODO:  what if throws bad_alloc?
   }
 
   template<>
   inline string_type convert<string_type>( const string_type & s, system::error_code & ec )
   { 
+    if ( &ec != &system::throws ) ec.clear();
     return s;
   }
 
-# ifdef BOOST_WINDOWS_API
-
   template<>
-  inline void append<char>( const char * begin, const char * end,
-    std::wstring & target, system::error_code & ec )
+  inline void append<char>( const detail::extern_value_type * begin,
+    const detail::extern_value_type * end,
+    string_type & target, system::error_code & ec )
   {
     detail::append( begin, end, target, ec );
   }
 
   template<>
-  inline void append<char>( const char * begin, std::wstring & target,
-     system::error_code & ec )
+  inline void append<char>( const detail::extern_value_type * begin,
+    string_type & target, system::error_code & ec )
   { 
     detail::append( begin, 0, target, ec );
   }
 
   template<>
-  inline std::string convert<std::string>( const std::wstring & s,
+  inline detail::extern_string_type convert<std::string>( const string_type & s,
     system::error_code & ec )
   {
     return detail::convert_to_string( s, ec );
   }
 
-# endif
-
 #   ifdef BOOST_FILESYSTEM_CPP0X_CHAR_TYPES
       ...
 #   endif
@@ -545,25 +507,17 @@
 
     //  return formatted "as input"
 
-#   ifdef BOOST_WINDOWS_API
-
-    operator const std::string() const    { return detail::convert_to_string( m_path, system::throws ); }
-    operator const std::wstring&() const  { return m_path; }
+    operator const string_type&() const  { return m_path; }
+    operator const detail::extern_string_type() const
+    { 
+      return detail::convert_to_string( m_path, system::throws );
+    }
 
 # ifdef BOOST_FILESYSTEM_CPP0X_CHAR_TYPES
     operator const std::u16string() const { return detail::convert_to_u16string( m_path, system::throws ); }
     operator const std::u32string() const { return detail::convert_to_u32string( m_path, system::throws ); }
 # endif
 
-#   else   // BOOST_POSIX_API
-
-    operator const std::string&() const   { return m_path; }
-#     ifndef BOOST_FILESYSTEM_NARROW_ONLY
-    operator const std::wstring() const   { return detail::convert( m_path, system::throws ); }
-#     endif
-
-#   endif
-
     //  -----  observers  -----
   
     //  For operating systems that format file paths differently than directory
@@ -586,17 +540,13 @@
     const std::wstring &  wstring() const                                          { return m_path; }
     const std::wstring &  wstring( system::error_code & ec ) const                 { ec.clear(); return m_path; }
 
-#   ifdef BOOST_FILESYSTEM_CPP0X_CHAR_TYPES
-     ...
-#   endif
-
 #   else   // BOOST_POSIX_API
 
     //  return value is formatted "as input"
     const std::string &  string() const                                            { return m_path; }
     const std::string &  string( system::error_code & ec ) const                   { ec.clear(); return m_path; }
 #     ifndef BOOST_FILESYSTEM_NARROW_ONLY
-    const std::wstring   wstring( system::error_code & ec = system::throws ) const { return detail::convert( m_path, ec ); }
+    const std::wstring   wstring( system::error_code & ec = system::throws ) const { return detail::convert_to_string( m_path, ec ); }
 #     endif    
 #   endif
 
Modified: sandbox/filesystem-v3/libs/filesystem/src/path.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/src/path.cpp	(original)
+++ sandbox/filesystem-v3/libs/filesystem/src/path.cpp	2009-01-04 10:24:30 EST (Sun, 04 Jan 2009)
@@ -149,9 +149,7 @@
     return tmp;
   }
 
-# else   // BOOST_POSIX_API
-  ...
-# endif  // BOOST_POSIX_API
+# endif  // BOOST_WINDOWS_PATH
 
   //  append_separator_if_needed_  -------------------------------------------//
 
@@ -581,6 +579,8 @@
 
 namespace
 {
+# ifdef BOOST_WINDOWS_API
+
   //------------------------------------------------------------------------------------//
   //                                                                                    //
   //                     class windows_file_api_codecvt_facet                           //
@@ -659,6 +659,7 @@
     *to_next = '\0';
     return ok;
   }
+# endif  // BOOST_WINDOWS_API
 
   //------------------------------------------------------------------------------------//
   //                              locale helpers                                        //
@@ -671,9 +672,14 @@
 
   std::locale default_locale()
   {
+# ifdef BOOST_WINDOWS_API
     std::locale global_loc = std::locale();
     std::locale loc( global_loc, new windows_file_api_codecvt_facet );
     return loc;
+# else
+    // ISO C calls this "the locale-specific native environment":
+    return std::locale loc("");
+# endif
   }
 
   std::locale & path_locale()
@@ -736,6 +742,13 @@
 
 namespace detail
 {
+# ifdef BOOST_WINDOWS_API
+#  define APPEND_DIRECTION in
+#  define CONVERT_DIRECTION out
+# else
+#  define APPEND_DIRECTION out
+#  define CONVERT_DIRECTION in
+# endif
 
   //------------------------------------------------------------------------------------//
   //                                   append                                           //
@@ -743,15 +756,16 @@
 
   //  actual append done here to factor it out from messy buffer management code;
   //  this function just assumes the buffer is large enough.
-  inline void do_append( const char * from, const char * from_end,
-                   wchar_t * to, wchar_t * to_end,
-                   wstring & target, error_code & ec )
+  inline void do_append(
+                   const extern_value_type * from, const extern_value_type * from_end,
+                   value_type * to, value_type * to_end,
+                   string_type & target, error_code & ec )
   {
     std::mbstate_t state  = std::mbstate_t();  // perhaps unneeded, but cuts bug reports
-    const char * from_next;
-    wchar_t * to_next;
+    const extern_value_type * from_next;
+    value_type * to_next;
 
-    if ( wchar_t_codecvt_facet()->in( state, from, from_end, from_next,
+    if ( wchar_t_codecvt_facet()->APPEND_DIRECTION( state, from, from_end, from_next,
            to, to_end, to_next ) != std::codecvt_base::ok )
     {
       assert( 0 && "append error handling not implemented yet" );
@@ -762,7 +776,8 @@
   }
 
   BOOST_FILESYSTEM_DECL
-  void append( const char * begin, const char * end, wstring & target, error_code & ec )
+  void append( const extern_value_type * begin, const extern_value_type * end,
+  string_type & target, error_code & ec )
   {
     if ( !end ) 
       end = begin + std::strlen(begin);
@@ -783,7 +798,7 @@
     }
     else
     {
-      wchar_t buf[default_codecvt_buf_size];
+      value_type buf[default_codecvt_buf_size];
       do_append( begin, end, buf, buf+buf_size, target, ec );
     }
   }
@@ -801,7 +816,7 @@
     const wchar_t * from_next;
     char * to_next;
 
-    if ( wchar_t_codecvt_facet()->out( state, from, from_end,
+    if ( wchar_t_codecvt_facet()->CONVERT_DIRECTION( state, from, from_end,
           from_next, to, to_end, to_next ) != std::codecvt_base::ok )
     {
       assert( 0 && "convert error handling not implemented yet" );
@@ -812,7 +827,7 @@
   }
 
   BOOST_FILESYSTEM_DECL
-  string convert_to_string( const wstring & src, error_code & ec )
+  extern_string_type convert_to_string( const string_type & src, error_code & ec )
   {
     if ( src.empty() )
     {
@@ -830,13 +845,13 @@
     //  dynamically allocate a buffer only if source is unusually large
     if ( buf_size > default_codecvt_buf_size )
     {
-      boost::scoped_array< char > buf( new char [buf_size] );
+      boost::scoped_array< char > buf( new extern_value_type [buf_size] );
       return do_convert( src.c_str(), src.c_str()+src.size(),
         buf.get(), buf.get()+buf_size, ec );
     }
     else
     {
-      char buf[default_codecvt_buf_size];
+      extern_value_type buf[default_codecvt_buf_size];
       return do_convert( src.c_str(), src.c_str()+src.size(), buf, buf+buf_size, ec );
     }
   }