Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50746 - in sandbox/filesystem-v3: boost/filesystem libs/filesystem/test
From: bdawes_at_[hidden]
Date: 2009-01-23 09:31:50


Author: bemandawes
Date: 2009-01-23 09:31:49 EST (Fri, 23 Jan 2009)
New Revision: 50746
URL: http://svn.boost.org/trac/boost/changeset/50746

Log:
Filesystem.v3: path relationals optimization complete. Added path::source() to support relationals and similar user needs.
Text files modified:
   sandbox/filesystem-v3/boost/filesystem/path.hpp | 49 ++++++++++++++++++++++++++-------------
   sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp | 8 +++---
   2 files changed, 36 insertions(+), 21 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-23 09:31:49 EST (Fri, 23 Jan 2009)
@@ -434,6 +434,9 @@
 
     // ----- appends -----
 
+ // if a separator is added, it is the preferred separator for the platform;
+ // slash for POSIX, backslash for Windows
+
     path & operator/=( const path & p ) // #1
     {
       append_separator_if_needed_();
@@ -511,22 +514,31 @@
 
     // Implementations are permitted to return const values or const references.
 
- template< class T >
- T string( system::error_code & ec = boost::throws() ) const
+ // The string or path returned by an observer will be described as being formatted
+ // as "native", "generic", or "source".
+ //
+ // For POSIX, these are all the same format; slashes and backslashes are not modified.
+ //
+ // For Windows, native: slashes are converted to backslashes
+ // generic: backslashes are converted to backslashes
+ // source: slashes and backslashes are not modified
+
+ template< class T >
+ T string( system::error_code & ec = boost::throws() ) const // source format
     {
       return path_traits::convert<T>( m_path, ec );
     }
 
 # ifdef BOOST_WINDOWS_API
 
- // return value is formatted "as input"
+ // source format
     const std::string string( system::error_code & ec = boost::throws() ) const { return detail::convert_to_string( m_path, ec ); }
     const std::wstring & wstring() const { return m_path; }
     const std::wstring & wstring( system::error_code & ec ) const { ec.clear(); return m_path; }
 
 # else // BOOST_POSIX_API
 
- // return value is formatted "as input"
+ // source format
     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
@@ -537,22 +549,22 @@
     
 # ifdef BOOST_WINDOWS_PATH
 
- // return value is formatted as indicated by function name
- const path native() const; // all separators converted to preferred separator;
- // thus on Windows slashes are converted to backslashes
- const path generic() const;
+
+ const path native() const; // native format
+ const path generic() const; // generic format
 
 # else // BOOST_POSIX_PATH
 
- // return value is formatted as indicated by function name
     const path native() const { return m_path; }
     const path generic() const { return m_path; }
 
 # endif
 
- // native format c_str(), suitable for passing to native OS API calls;
- // on Windows, slashes and backslashes are exactly as input
- const value_type * c_str() const { return m_path.c_str(); }
+ const string_type & source() const { return m_path; } // source format
+
+ // c_str() returns a C string suitable for calls to the operating system API.
+ // On POSIX and Windows that's source format, on some OS's it may be native format.
+ const value_type * c_str() const { return m_path.c_str(); } //
 
     // ----- decomposition -----
 
@@ -716,6 +728,8 @@
   // //
   //------------------------------------------------------------------------------------//
 
+ // relational operators act as if comparing native format strings
+
   inline bool operator<( const path & lhs, const path & rhs )
   {
     // because path iterators yield paths, std::lexicographical_compare
@@ -731,6 +745,7 @@
   // operator==() efficiency is a concern; a user reported the original version 2
   // !(lhs < rhs) && !(rhs < lhs) implementation caused a serious performance problem
   // for a map of 10,000 paths.
+
 # ifdef BOOST_WINDOWS_API
   inline bool operator==( const path & lhs, const path::value_type * rhs )
   {
@@ -744,11 +759,11 @@
   inline bool operator==( const path::string_type & lhs, const path & rhs ) { return rhs == lhs; }
   inline bool operator==( const path::value_type * lhs, const path & rhs ) { return rhs == lhs; }
 # else // BOOST_POSIX_API
- inline bool operator==( const path & lhs, const path & rhs ) { return lhs.native_string() == rhs.native_string(); }
- inline bool operator==( const path & lhs, const path::string_type & rhs ) { return lhs.native_string() == rhs; }
- inline bool operator==( const path & lhs, const path::value_type * rhs ) { return lhs.native_string() == rhs; }
- inline bool operator==( const path::string_type & lhs, const path & rhs ) { return lhs == rhs.native_string(); }
- inline bool operator==( const path::value_type * lhs, const path & rhs ) { return lhs == rhs.native_string(); }
+ inline bool operator==( const path & lhs, const path & rhs ) { return lhs.source_string() == rhs.source_string(); }
+ inline bool operator==( const path & lhs, const path::string_type & rhs ) { return lhs.source_string() == rhs; }
+ inline bool operator==( const path & lhs, const path::value_type * rhs ) { return lhs.source_string() == rhs; }
+ inline bool operator==( const path::string_type & lhs, const path & rhs ) { return lhs == rhs.source_string(); }
+ inline bool operator==( const path::value_type * lhs, const path & rhs ) { return lhs == rhs.source_string(); }
 # endif
 
 

Modified: sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp 2009-01-23 09:31:49 EST (Fri, 23 Jan 2009)
@@ -59,7 +59,7 @@
   void check_dir( const fs::path & source,
               const std::string & expected, const char* file, int line )
   {
- if ( source.string()== expected ) return;
+ if ( source.string() == expected ) return;
 
     ++errors;
 
@@ -69,14 +69,14 @@
               << "\"" << std::endl;
   }
 
- void check_equal( const std::string & value,
+ void check_equal( const fs::path & source,
               const std::string & expected, const char* file, int line )
   {
- if ( value == expected ) return;
+ if ( source == expected ) return;
 
     ++errors;
 
- std::cout << file << '(' << line << "): value: \"" << value
+ std::cout << file << '(' << line << "): source: \"" << source.string()
               << "\" != expected: \"" << expected
               << "\"" << std::endl;
   }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk