Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59825 - in sandbox/filesystem-v3: boost/filesystem libs/filesystem/example libs/filesystem/test libs/filesystem/test/msvc
From: bdawes_at_[hidden]
Date: 2010-02-21 16:28:44


Author: bemandawes
Date: 2010-02-21 16:28:43 EST (Sun, 21 Feb 2010)
New Revision: 59825
URL: http://svn.boost.org/trac/boost/changeset/59825

Log:
Fix failure to dispatch non-continuous containers correctly, plus some beta 1 source formatting issues
Text files modified:
   sandbox/filesystem-v3/boost/filesystem/path_traits.hpp | 62 ++++++++++++++++++++++++++++++---------
   sandbox/filesystem-v3/libs/filesystem/example/tut2.cpp | 6 +-
   sandbox/filesystem-v3/libs/filesystem/example/tut3.cpp | 10 +++---
   sandbox/filesystem-v3/libs/filesystem/example/tut4.cpp | 10 +++---
   sandbox/filesystem-v3/libs/filesystem/example/tut5.cpp | 10 +++++-
   sandbox/filesystem-v3/libs/filesystem/test/msvc/filesystem-v3-sandbox.sln | 14 ++++----
   sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp | 38 +++++++++++++++++++++--
   7 files changed, 109 insertions(+), 41 deletions(-)

Modified: sandbox/filesystem-v3/boost/filesystem/path_traits.hpp
==============================================================================
--- sandbox/filesystem-v3/boost/filesystem/path_traits.hpp (original)
+++ sandbox/filesystem-v3/boost/filesystem/path_traits.hpp 2010-02-21 16:28:43 EST (Sun, 21 Feb 2010)
@@ -12,6 +12,7 @@
 
 #include <boost/filesystem/config.hpp>
 #include <string>
+#include <vector>
 #include <iterator>
 #include <boost/assert.hpp>
 #include <boost/system/error_code.hpp>
@@ -55,26 +56,57 @@
      bool empty(T (&)[N])
        { return N <= 1; }
 
- // Pathable dispatch
+ // Source dispatch
 
- template <class Container, class U> inline
- void dispatch(const Container & c, U & to, const codecvt_type & cvt)
+ // contiguous containers
+ template <class U> inline
+ void dispatch(const std::string& c, U& to, const codecvt_type& cvt)
+ {
+ if (c.size())
+ convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
+ }
+ template <class U> inline
+ void dispatch(const std::wstring& c, U& to, const codecvt_type& cvt)
+ {
+ if (c.size())
+ convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
+ }
+ template <class U> inline
+ void dispatch(const std::vector<char>& c, U& to, const codecvt_type& cvt)
   {
-// std::cout << "dispatch() container\n";
     if (c.size())
       convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
   }
+ template <class U> inline
+ void dispatch(const std::vector<wchar_t>& c, U& to, const codecvt_type& cvt)
+ {
+ if (c.size())
+ convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
+ }
+
+ // non-contiguous containers
+ template <class Container, class U> inline
+ void dispatch(const Container & c, U& to, const codecvt_type& cvt)
+ {
+ if (c.size())
+ {
+ std::basic_string<typename Container::value_type> s(c.begin(), c.end());
+ path_traits::convert(s.c_str(), s.c_str()+s.size(), to, cvt);
+ }
+ }
 
+ // c_str
   template <class T, class U> inline
- void dispatch(T * const & c_str, U & to, const codecvt_type & cvt)
+ void dispatch(T * const & c_str, U& to, const codecvt_type& cvt)
   {
 // std::cout << "dispatch() const T *\n";
     BOOST_ASSERT(c_str);
     convert(c_str, to, cvt);
   }
   
+ // C-style array
   template <typename T, size_t N, class U> inline
- void dispatch(T (&array)[N], U & to, const codecvt_type & cvt) // T, N, U deduced
+ void dispatch(T (&array)[N], U& to, const codecvt_type& cvt) // T, N, U deduced
   {
 // std::cout << "dispatch() array, N=" << N << "\n";
     convert(array, array + N - 1, to, cvt);
@@ -87,7 +119,7 @@
 # else
                    std::string & to,
 # endif
- const codecvt_type &);
+ const codecvt_type&);
 
   // value types differ ---------------------------------------------------------------//
   //
@@ -97,18 +129,18 @@
   void convert(const char* from,
                 const char* from_end, // 0 for null terminated MBCS
                 std::wstring & to,
- const codecvt_type & cvt);
+ const codecvt_type& cvt);
 
   BOOST_FILESYSTEM_DECL
   void convert(const wchar_t* from,
                 const wchar_t* from_end, // 0 for null terminated MBCS
                 std::string & to,
- const codecvt_type & cvt);
+ const codecvt_type& cvt);
 
   inline
   void convert(const char* from,
                 std::wstring & to,
- const codecvt_type & cvt)
+ const codecvt_type& cvt)
   {
     BOOST_ASSERT(from);
     convert(from, 0, to, cvt);
@@ -117,7 +149,7 @@
   inline
   void convert(const wchar_t* from,
                 std::string & to,
- const codecvt_type & cvt)
+ const codecvt_type& cvt)
   {
     BOOST_ASSERT(from);
     convert(from, 0, to, cvt);
@@ -129,7 +161,7 @@
 
   inline
   void convert(const char* from, const char* from_end, std::string & to,
- const codecvt_type &)
+ const codecvt_type&)
   {
     BOOST_ASSERT(from);
     BOOST_ASSERT(from_end);
@@ -139,7 +171,7 @@
   inline
   void convert(const char* from,
                 std::string & to,
- const codecvt_type &)
+ const codecvt_type&)
   {
     BOOST_ASSERT(from);
     to += from;
@@ -149,7 +181,7 @@
 
   inline
   void convert(const wchar_t* from, const wchar_t* from_end, std::wstring & to,
- const codecvt_type &)
+ const codecvt_type&)
   {
     BOOST_ASSERT(from);
     BOOST_ASSERT(from_end);
@@ -159,7 +191,7 @@
   inline
   void convert(const wchar_t* from,
                 std::wstring & to,
- const codecvt_type &)
+ const codecvt_type&)
   {
     BOOST_ASSERT(from);
     to += from;

Modified: sandbox/filesystem-v3/libs/filesystem/example/tut2.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/example/tut2.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/example/tut2.cpp 2010-02-21 16:28:43 EST (Sun, 21 Feb 2010)
@@ -24,12 +24,12 @@
 
   cout << p << ": "; // utilize the path narrow stream inserter
 
- if ( exists(p) ) // does p actually exist?
+ if (exists(p)) // does p actually exist?
   {
- if ( is_regular_file(p) ) // is p a regular file?
+ if (is_regular_file(p)) // is p a regular file?
       cout << file_size(p) << '\n';
 
- else if ( is_directory(p) ) // is p a directory?
+ else if (is_directory(p)) // is p a directory?
       cout << "is a directory\n";
 
     else

Modified: sandbox/filesystem-v3/libs/filesystem/example/tut3.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/example/tut3.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/example/tut3.cpp 2010-02-21 16:28:43 EST (Sun, 21 Feb 2010)
@@ -24,18 +24,18 @@
 
   cout << p << ": "; // utilize the path narrow stream inserter
 
- if ( exists(p) ) // does p actually exist?
+ if (exists(p)) // does p actually exist?
   {
- if ( is_regular_file(p) ) // is p a regular file?
+ if (is_regular_file(p)) // is p a regular file?
       cout << file_size(p) << '\n';
 
- else if ( is_directory(p) ) // is p a directory?
+ else if (is_directory(p)) // is p a directory?
     {
       cout << "is a directory containing:\n";
 
- for ( directory_iterator it (p); // initialize it to the first element
+ for (directory_iterator it (p); // initialize it to the first element
             it != directory_iterator(); // test for the past-the-end element
- ++it ) // increment
+ ++it) // increment
       {
         cout << " " << *it << '\n'; // *it returns a directory_entry,
                                             // which is converted to a path

Modified: sandbox/filesystem-v3/libs/filesystem/example/tut4.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/example/tut4.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/example/tut4.cpp 2010-02-21 16:28:43 EST (Sun, 21 Feb 2010)
@@ -26,21 +26,21 @@
 
   cout << p << ": "; // utilize the path narrow stream inserter
 
- if ( exists(p) ) // does p actually exist?
+ if (exists(p)) // does p actually exist?
   {
- if ( is_regular_file(p) ) // is p a regular file?
+ if (is_regular_file(p)) // is p a regular file?
       cout << file_size(p) << '\n';
 
- else if ( is_directory(p) ) // is p a directory?
+ else if (is_directory(p)) // is p a directory?
     {
       cout << "is a directory containing:\n";
 
       typedef vector<path> vec; // store paths,
       vec v; // so we can sort them later
 
- for ( directory_iterator it (p); // initialize it to the first element
+ for (directory_iterator it (p); // initialize it to the first element
             it != directory_iterator(); // test for the past-the-end element
- ++it ) // increment
+ ++it) // increment
       {
         path fn = it->path().filename(); // extract the filename from the path
         v.push_back(fn); // push into vector for later sorting

Modified: sandbox/filesystem-v3/libs/filesystem/example/tut5.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/example/tut5.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/example/tut5.cpp 2010-02-21 16:28:43 EST (Sun, 21 Feb 2010)
@@ -37,8 +37,14 @@
   { fs::ofstream f(L"smile\u263A"); }
   { fs::ofstream f(narrow_string); }
   { fs::ofstream f(wide_string); }
- // { fs::ofstream f(narrow_list); } and { fs::ofstream f(wide_list); }
- // would work, but we want to show off construction from an iterator range:
+ { fs::ofstream f(narrow_list); }
+ { fs::ofstream f(wide_list); }
+ narrow_list.pop_back();
+ narrow_list.push_back('4');
+ wide_list.pop_back();
+ wide_list.pop_back();
+ wide_list.push_back(L'4');
+ wide_list.push_back(L'\u263A');
   { fs::ofstream f(fs::path(narrow_list.begin(), narrow_list.end())); }
   { fs::ofstream f(fs::path(wide_list.begin(), wide_list.end())); }
 

Modified: sandbox/filesystem-v3/libs/filesystem/test/msvc/filesystem-v3-sandbox.sln
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/test/msvc/filesystem-v3-sandbox.sln (original)
+++ sandbox/filesystem-v3/libs/filesystem/test/msvc/filesystem-v3-sandbox.sln 2010-02-21 16:28:43 EST (Sun, 21 Feb 2010)
@@ -82,19 +82,19 @@
                 {FFD738F7-96F0-445C-81EA-551665EF53D1} = {FFD738F7-96F0-445C-81EA-551665EF53D1}
         EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "smile", "smile\smile.vcproj", "{CDC8DCF8-D55B-4F79-8508-4F32416BCB62}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "space", "space\space.vcproj", "{1AEABC96-F4D5-4B15-B246-3AA34A1827CB}"
         ProjectSection(ProjectDependencies) = postProject
                 {F94CCADD-A90B-480C-A304-C19D015D36B1} = {F94CCADD-A90B-480C-A304-C19D015D36B1}
                 {FFD738F7-96F0-445C-81EA-551665EF53D1} = {FFD738F7-96F0-445C-81EA-551665EF53D1}
         EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "space", "space\space.vcproj", "{1AEABC96-F4D5-4B15-B246-3AA34A1827CB}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tut5", "tut5\tut5.vcproj", "{9D7703A1-F076-4362-BE31-A1C5893D05DF}"
         ProjectSection(ProjectDependencies) = postProject
                 {F94CCADD-A90B-480C-A304-C19D015D36B1} = {F94CCADD-A90B-480C-A304-C19D015D36B1}
                 {FFD738F7-96F0-445C-81EA-551665EF53D1} = {FFD738F7-96F0-445C-81EA-551665EF53D1}
         EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tut5", "tut5\tut5.vcproj", "{9D7703A1-F076-4362-BE31-A1C5893D05DF}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scratch", "scratch\scratch.vcproj", "{D2F172A6-1D20-458D-8C46-83A2FBAC73E4}"
         ProjectSection(ProjectDependencies) = postProject
                 {F94CCADD-A90B-480C-A304-C19D015D36B1} = {F94CCADD-A90B-480C-A304-C19D015D36B1}
                 {FFD738F7-96F0-445C-81EA-551665EF53D1} = {FFD738F7-96F0-445C-81EA-551665EF53D1}
@@ -181,10 +181,6 @@
                 {18EA74B4-B284-4FD4-BC0A-3B2193801B8D}.Debug|Win32.Build.0 = Debug|Win32
                 {18EA74B4-B284-4FD4-BC0A-3B2193801B8D}.Release|Win32.ActiveCfg = Release|Win32
                 {18EA74B4-B284-4FD4-BC0A-3B2193801B8D}.Release|Win32.Build.0 = Release|Win32
- {CDC8DCF8-D55B-4F79-8508-4F32416BCB62}.Debug|Win32.ActiveCfg = Debug|Win32
- {CDC8DCF8-D55B-4F79-8508-4F32416BCB62}.Debug|Win32.Build.0 = Debug|Win32
- {CDC8DCF8-D55B-4F79-8508-4F32416BCB62}.Release|Win32.ActiveCfg = Release|Win32
- {CDC8DCF8-D55B-4F79-8508-4F32416BCB62}.Release|Win32.Build.0 = Release|Win32
                 {1AEABC96-F4D5-4B15-B246-3AA34A1827CB}.Debug|Win32.ActiveCfg = Debug|Win32
                 {1AEABC96-F4D5-4B15-B246-3AA34A1827CB}.Debug|Win32.Build.0 = Debug|Win32
                 {1AEABC96-F4D5-4B15-B246-3AA34A1827CB}.Release|Win32.ActiveCfg = Release|Win32
@@ -193,6 +189,10 @@
                 {9D7703A1-F076-4362-BE31-A1C5893D05DF}.Debug|Win32.Build.0 = Debug|Win32
                 {9D7703A1-F076-4362-BE31-A1C5893D05DF}.Release|Win32.ActiveCfg = Release|Win32
                 {9D7703A1-F076-4362-BE31-A1C5893D05DF}.Release|Win32.Build.0 = Release|Win32
+ {D2F172A6-1D20-458D-8C46-83A2FBAC73E4}.Debug|Win32.ActiveCfg = Debug|Win32
+ {D2F172A6-1D20-458D-8C46-83A2FBAC73E4}.Debug|Win32.Build.0 = Debug|Win32
+ {D2F172A6-1D20-458D-8C46-83A2FBAC73E4}.Release|Win32.ActiveCfg = Release|Win32
+ {D2F172A6-1D20-458D-8C46-83A2FBAC73E4}.Release|Win32.Build.0 = Release|Win32
         EndGlobalSection
         GlobalSection(SolutionProperties) = preSolution
                 HideSolutionNode = FALSE

Modified: sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp 2010-02-21 16:28:43 EST (Sun, 21 Feb 2010)
@@ -102,6 +102,8 @@
   wstring ws(L"wstring");
   std::list<char> l; // see main() for initialization to s, t, r, i, n, g
   std::list<wchar_t> wl; // see main() for initialization to w, s, t, r, i, n, g
+ std::vector<char> v; // see main() for initialization to f, u, z
+ std::vector<wchar_t> wv; // see main() for initialization to w, f, u, z
 
   // test_constructors ---------------------------------------------------------------//
 
@@ -125,14 +127,23 @@
     PATH_IS(x3, L"wstring");
     BOOST_TEST_EQ(x3.native().size(), 7U);
 
- path x4(string("std::string")); // container char
+ // contiguous containers
+ path x4(string("std::string")); // std::string
     PATH_IS(x4, L"std::string");
     BOOST_TEST_EQ(x4.native().size(), 11U);
 
- path x5(wstring(L"std::wstring")); // container wchar_t
+ path x5(wstring(L"std::wstring")); // std::wstring
     PATH_IS(x5, L"std::wstring");
     BOOST_TEST_EQ(x5.native().size(), 12U);
 
+ path x4v(v); // std::vector<char>
+ PATH_IS(x4v, L"fuz");
+ BOOST_TEST_EQ(x4v.native().size(), 3U);
+
+ path x5v(wv); // std::vector<wchar_t>
+ PATH_IS(x5v, L"wfuz");
+ BOOST_TEST_EQ(x5v.native().size(), 4U);
+
     path x6("array char"); // array char
     PATH_IS(x6, L"array char");
     BOOST_TEST_EQ(x6.native().size(), 10U);
@@ -141,13 +152,22 @@
     PATH_IS(x7, L"array wchar_t");
     BOOST_TEST_EQ(x7.native().size(), 13U);
 
- path x8(s.c_str()); // const char* null terminated
+ path x8(s.c_str()); // const char* null terminated
     PATH_IS(x8, L"string");
     BOOST_TEST_EQ(x8.native().size(), 6U);
 
- path x9(ws.c_str()); // const wchar_t* null terminated
+ path x9(ws.c_str()); // const wchar_t* null terminated
     PATH_IS(x9, L"wstring");
     BOOST_TEST_EQ(x9.native().size(), 7U);
+
+ // non-contiguous containers
+ path x10(l); // std::list<char>
+ PATH_IS(x10, L"string");
+ BOOST_TEST_EQ(x10.native().size(), 6U);
+
+ path xll(wl); // std::list<wchar_t>
+ PATH_IS(xll, L"wstring");
+ BOOST_TEST_EQ(xll.native().size(), 7U);
   }
 
   path x;
@@ -511,6 +531,7 @@
     CHECK(path("/foo/bar/baz.zoo").stem().string() == "baz");
     CHECK(path("/foo/bar.woo/baz").stem().string() == "baz");
 
+ CHECK(path("foo.bar.baz.tar.bz2").extension().string() == ".bz2");
     CHECK(path("/foo/bar/baz.zoo").extension().string() == ".zoo");
     CHECK(path("/foo/bar.woo/baz").extension().string() == "");
   }
@@ -838,6 +859,15 @@
   wl.push_back(L'n');
   wl.push_back(L'g');
 
+ v.push_back('f');
+ v.push_back('u');
+ v.push_back('z');
+
+ wv.push_back(L'w');
+ wv.push_back(L'f');
+ wv.push_back(L'u');
+ wv.push_back(L'z');
+
   test_overloads();
   test_constructors();
   test_assignments();


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