Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72382 - in trunk: boost/iostreams/detail libs/iostreams/test
From: dnljms_at_[hidden]
Date: 2011-06-03 19:30:00


Author: danieljames
Date: 2011-06-03 19:29:59 EDT (Fri, 03 Jun 2011)
New Revision: 72382
URL: http://svn.boost.org/trac/boost/changeset/72382

Log:
Iostreams: Support filesystem3 paths. Refs #4485.

Based on Zhuo Qiang's patch with added tests and support
for `operator=`.

I also used `codecvt_type` to detect `filesystem3::path`
instead of `string_type`. Using `string_type` made
`filesystem2::path` ambiguous because it has both
`string_type` and `external_string_type` members.

The member types are a bit arbitrary, but a more precise
distinction would probably also be more expensive.

Added:
   trunk/libs/iostreams/test/path_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/iostreams/detail/path.hpp | 46 ++++++++++++++++++++++++++++-----------
   trunk/libs/iostreams/test/Jamfile.v2 | 9 ++++++
   trunk/libs/iostreams/test/mapped_file_test.cpp | 15 +++++++++++++
   3 files changed, 56 insertions(+), 14 deletions(-)

Modified: trunk/boost/iostreams/detail/path.hpp
==============================================================================
--- trunk/boost/iostreams/detail/path.hpp (original)
+++ trunk/boost/iostreams/detail/path.hpp 2011-06-03 19:29:59 EDT (Fri, 03 Jun 2011)
@@ -35,6 +35,11 @@
 #ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS //------------------------------------//
 
 class path {
+ template<typename T, typename V>
+ struct sfinae
+ {
+ typedef V type;
+ };
 public:
 
     // Default constructor
@@ -46,12 +51,19 @@
     // Constructor taking a C-style string
     path(const char* p) : narrow_(p), wide_(), is_wide_(false) { }
 
- // Constructor taking a boost::filesystem::path or boost::filesystem::wpath
+ // Constructor taking a boost::filesystem2::path or
+ // boost::filesystem2::wpath
     template<typename Path>
     explicit path(const Path& p, typename Path::external_string_type* = 0)
     {
- typedef typename Path::external_string_type string_type;
- init(p, boost::type<string_type>());
+ init(p.external_file_string());
+ }
+
+ // Constructor taking a boost::filesystem3::path (boost filesystem v3)
+ template<typename Path>
+ explicit path(const Path& p, typename Path::codecvt_type* = 0)
+ {
+ init(p.native());
     }
 
     // Copy constructor
@@ -86,12 +98,22 @@
         return *this;
     }
 
- // Assignment operator taking a Boost.Filesystem path
+ // Assignment operator taking a boost::filesystem2::path or
+ // boost::filesystem2::wpath
+ template<typename Path>
+ typename sfinae<typename Path::external_string_type, path&>::type
+ operator=(const Path& p)
+ {
+ init(p.external_file_string());
+ return *this;
+ }
+
+ // Assignment operator taking a boost::filesystem3::path
     template<typename Path>
- path& operator=(const Path& p)
+ typename sfinae<typename Path::codecvt_type, path&>::type
+ operator=(const Path& p)
     {
- typedef typename Path::external_string_type string_type;
- init(p, boost::type<string_type>());
+ init(p.native());
         return *this;
     }
 
@@ -111,19 +133,17 @@
     path(const std::wstring&);
     path& operator=(const std::wstring&);
 
- template<typename Path>
- void init(const Path& p, boost::type<std::string>)
+ void init(std::string const& file_path)
     {
- narrow_ = p.external_file_string();
+ narrow_ = file_path;
         wide_.clear();
         is_wide_ = false;
     }
 
- template<typename Path>
- void init(const Path& p, boost::type<std::wstring>)
+ void init(std::wstring const& file_path)
     {
         narrow_.clear();
- wide_ = p.external_file_string();
+ wide_ = file_path;
         is_wide_ = true;
     }
 

Modified: trunk/libs/iostreams/test/Jamfile.v2
==============================================================================
--- trunk/libs/iostreams/test/Jamfile.v2 (original)
+++ trunk/libs/iostreams/test/Jamfile.v2 2011-06-03 19:29:59 EDT (Fri, 03 Jun 2011)
@@ -15,7 +15,7 @@
 local LARGE_FILE_TEMP = [ modules.peek : LARGE_FILE_TEMP ] ;
 local LARGE_FILE_KEEP = [ modules.peek : LARGE_FILE_KEEP ] ;
 
-rule test-iostreams ( sources * : requirements * ) {
+rule test-iostreams ( sources * : requirements * : target-name ? ) {
     return [
             run
                 $(sources)
@@ -30,6 +30,7 @@
                 <define>BOOST_IOSTREAMS_NO_LIB
                 <link>shared:<define>BOOST_IOSTREAMS_DYN_LINK=1
                 $(requirements)
+ : $(target-name)
         ] ;
 }
 
@@ -86,6 +87,12 @@
           [ test-iostreams line_filter_test.cpp ]
           [ test-iostreams mapped_file_test.cpp
                 ../build//boost_iostreams ]
+ [ test-iostreams path_test.cpp
+ : <define>BOOST_FILESYSTEM_VERSION=2
+ : path_test_filesystem2 ]
+ [ test-iostreams path_test.cpp
+ : <define>BOOST_FILESYSTEM_VERSION=3
+ : path_test_filesystem3 ]
           [ test-iostreams newline_test.cpp ]
           [ test-iostreams null_test.cpp ]
           [ test-iostreams operation_sequence_test.cpp ]

Modified: trunk/libs/iostreams/test/mapped_file_test.cpp
==============================================================================
--- trunk/libs/iostreams/test/mapped_file_test.cpp (original)
+++ trunk/libs/iostreams/test/mapped_file_test.cpp 2011-06-03 19:29:59 EDT (Fri, 03 Jun 2011)
@@ -21,6 +21,7 @@
 
 #include <boost/iostreams/stream.hpp>
 #include <boost/iostreams/device/mapped_file.hpp>
+#include <boost/filesystem/path.hpp>
 #include "detail/temp_file.hpp"
 #include "detail/verification.hpp"
 
@@ -300,6 +301,20 @@
 
         mf.close();
     }
+
+ //---------Check creating opening mapped_file with filesystem3 path------//
+ {
+ boost::iostreams::test::test_file orig;
+
+ mapped_file mf(boost::filesystem::path(orig.name()));
+
+ BOOST_CHECK_MESSAGE(
+ boost::iostreams::test::test_writeable(mf),
+ "failed seeking within private mapped_file"
+ );
+
+ mf.close();
+ }
 }
 
 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)

Added: trunk/libs/iostreams/test/path_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/iostreams/test/path_test.cpp 2011-06-03 19:29:59 EDT (Fri, 03 Jun 2011)
@@ -0,0 +1,25 @@
+// (C) Copyright Daniel James 2011.
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+
+// See http://www.boost.org/libs/iostreams for documentation.
+
+#include <boost/iostreams/detail/path.hpp>
+#include <boost/filesystem/path.hpp>
+
+#include <boost/test/test_tools.hpp>
+#include <boost/test/unit_test.hpp>
+
+void path_test()
+{
+ boost::filesystem::path orig("a/b");
+ boost::iostreams::detail::path p(orig);
+ p = orig;
+}
+
+boost::unit_test::test_suite* init_unit_test_suite(int, char* [])
+{
+ boost::unit_test::test_suite* test = BOOST_TEST_SUITE("mapped_file test");
+ test->add(BOOST_TEST_CASE(&path_test));
+ return test;
+}


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