$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r59092 - in sandbox/filesystem-v3: boost/filesystem libs/filesystem/doc libs/filesystem/src libs/filesystem/test
From: bdawes_at_[hidden]
Date: 2010-01-17 08:11:48
Author: bemandawes
Date: 2010-01-17 08:11:47 EST (Sun, 17 Jan 2010)
New Revision: 59092
URL: http://svn.boost.org/trac/boost/changeset/59092
Log:
Add path::absolute
Text files modified: 
   sandbox/filesystem-v3/boost/filesystem/path.hpp               |     4 ++                                      
   sandbox/filesystem-v3/libs/filesystem/doc/do_list.html        |     9 -----                                   
   sandbox/filesystem-v3/libs/filesystem/doc/reference.html      |     4 -                                       
   sandbox/filesystem-v3/libs/filesystem/src/path.cpp            |    46 +++++++++++++++++++++++++               
   sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp      |    72 ++++++++++++++++++++++++++++++++++++--- 
   sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp |    15 +++++++                                 
   6 files changed, 130 insertions(+), 20 deletions(-)
Modified: sandbox/filesystem-v3/boost/filesystem/path.hpp
==============================================================================
--- sandbox/filesystem-v3/boost/filesystem/path.hpp	(original)
+++ sandbox/filesystem-v3/boost/filesystem/path.hpp	2010-01-17 08:11:47 EST (Sun, 17 Jan 2010)
@@ -278,6 +278,10 @@
 
 # endif
 
+    //  -----  composition  -----
+
+    path  absolute(const path& base) const; 
+
     //  -----  decomposition  -----
 
     path  root_path() const; 
Modified: sandbox/filesystem-v3/libs/filesystem/doc/do_list.html
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/doc/do_list.html	(original)
+++ sandbox/filesystem-v3/libs/filesystem/doc/do_list.html	2010-01-17 08:11:47 EST (Sun, 17 Jan 2010)
@@ -59,15 +59,6 @@
   take a path argument?</li>
   <li style="font-size: 10pt">Add test for scoped_path_locale.</li>
   <li style="font-size: 10pt">Add codepage 936/950/etc test cases.</li>
-  <li style="font-size: 10pt">Are generic versions of string(), native_string() 
-  needed? IE:<br>
-  template< class T ><br>
-  T string(const error_code ec = throws());<br>
-  TODO: Maybe; all member functions need to be usable in generic code.</li>
-  <li style="font-size: 10pt">Assuming generic versions of string(), 
-  native_string(), are the w flavors needed? No. KISS. basic_string<char> is 
-  special because it is the predominant use case. w (and other) flavors can be 
-  added later.</li>
   <li style="font-size: 10pt">Should UDT's be supported?</li>
   <li style="font-size: 10pt">Should path iteration to a separator result in:<br>
   -- the actual separator used<br>
Modified: sandbox/filesystem-v3/libs/filesystem/doc/reference.html
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/doc/reference.html	(original)
+++ sandbox/filesystem-v3/libs/filesystem/doc/reference.html	2010-01-17 08:11:47 EST (Sun, 17 Jan 2010)
@@ -1779,10 +1779,9 @@
 an error. See Error reporting. <i>-- end note</i>]</p>
 <h4><a name="Function-specifications">Operational function specifications</a></h4>
 <pre>path <a name="complete">complete</a>(const path& p, const path& base, system::error_code& ec);</pre>
-<blockquote>
   <p><i>Effects:</i> Composes an absolute path from <code>p</code> and <code>base</code>, 
   using the following rules:</p>
-  <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
+  <table border="1" cellpadding="5" cellspacing="0" bordercolor="#111111" style="border-collapse: collapse">
     <tr>
       <td align="center"> </td>
       <td align="center"><b><code>p.has_root_directory()</code></b></td>
@@ -1817,7 +1816,6 @@
   paths supplied by user input, reported to program users, or when such behavior 
   is expected by program users. <i>-- 
   end note</i>]</p>
-</blockquote>
 <pre>path complete(const path& p, system::error_code& ec);</pre>
 <blockquote>
 <p><i>Returns:</i> <code>path(p, initial_path(), ec)</code>.</p>
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	2010-01-17 08:11:47 EST (Sun, 17 Jan 2010)
@@ -218,6 +218,52 @@
 )) { m_pathname.erase(sep_pos, 1); } // erase the added separator
   }
 
+  //  composition  ---------------------------------------------------------------------//
+
+  path  path::absolute(const path& base) const
+  {
+    //  store expensive to compute values that are needed multiple times
+    path this_root_name (root_name());
+    path base_root_name (base.root_name());
+#   ifdef BOOST_WINDOWS_PATH
+    path this_root_directory (root_directory());
+#   endif
+
+#   ifndef BOOST_WINDOWS_PATH
+    BOOST_ASSERT(!this_root_name.empty() || !base_root_name.empty());
+#   endif
+
+    BOOST_ASSERT(!this_root_directory.empty() || base.has_root_directory());
+//
+//    if (has_root_directory() // is_absolute
+// #      ifdef BOOST_WINDOWS_PATH
+//        && !this_root_name.empty()
+// #      endif
+//       ) return *this;
+//
+//    return (!this_root_name.empty() ? this_root_name : base_root_name)
+//#     ifdef BOOST_POSIX_PATH
+//      / separator
+//#     else  // BOOST_WINDOWS_PATH
+//      // use actual separator, which may be slash or backslash
+//      / (!this_root_directory.empty() ? this_root_directory : base.root_directory())
+//#     endif
+//      / base.relative_path()
+//      / relative_path();
+
+    if (empty())
+      return base;
+
+    if (!this_root_name.empty()) // has_root_name
+      return has_root_directory()
+        ? m_pathname
+        : this_root_name / base.root_directory() / base.relative_path() / relative_path();
+
+    return has_root_directory()
+      ? base.root_name() / m_pathname
+      : base /  m_pathname;
+  }
+
   //  decomposition  -------------------------------------------------------------------//
 
   path  path::root_path() const
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	2010-01-17 08:11:47 EST (Sun, 17 Jan 2010)
@@ -69,7 +69,7 @@
   path p4("foobar");
   path p5;
 
-  //  exception_tests  -------------------------------------------------------//
+  //  exception_tests  -----------------------------------------------------------------//
 
   void exception_tests()
   {
@@ -97,7 +97,7 @@
     }
   }
 
-  //  overload_tests  --------------------------------------------------------//
+  //  overload_tests  ------------------------------------------------------------------//
 
   // These verify various overloads don't cause compiler errors
   // They pre-date operations_unit_test.cpp
@@ -122,7 +122,7 @@
     p4 /= std::string("foo");
   }
 
-  //  iterator_tests  --------------------------------------------------------//
+  //  iterator_tests  ------------------------------------------------------------------//
 
   void iterator_tests()
   {
@@ -360,7 +360,7 @@
     }
   }
 
-  //  non_member_tests  ------------------------------------------------------//
+  //  non_member_tests  ----------------------------------------------------------------//
 
   void non_member_tests()
   {
@@ -398,6 +398,7 @@
     PATH_CHECK(path("") / "..", "..");
     if (platform == "Windows")
     {
+      BOOST_TEST(path("foo\\bar") == "foo/bar");
       BOOST_TEST((b / a).string() == "b\\a");
       BOOST_TEST((bs / a).string() == "b\\a");
       BOOST_TEST((bcs / a).string() == "b\\a");
@@ -655,9 +656,7 @@
       BOOST_TEST(!(L"c:/file" > p10));
       BOOST_TEST(!(L"c:\\file" > p11));
       BOOST_TEST(!(L"c:/file" > p11));
-
     }
-
   }
 
   //  query_and_decomposition_tests  ---------------------------------------------------//
@@ -1200,7 +1199,65 @@
     } // POSIX
   }
 
-  //  construction_tests  ----------------------------------------------------//
+ //  composition_tests  ----------------------------------------------------------------//
+
+  void composition_tests()
+  {
+    std::cout << "composition_tests..." << std::endl;
+
+    // these are white box tests constructed with knowledge of execution paths
+
+    // *this.empty()
+      BOOST_TEST_EQ(path().absolute("//foo/bar"), "//foo/bar");
+      if (platform == "Windows")
+        BOOST_TEST_EQ(path().absolute("a:/bar"), "a:/bar");
+
+    // *this.has_root_name()
+      //   *this.has_root_directory()
+        BOOST_TEST_EQ(path("//foo/bar").absolute("//uvw/xyz"), "//foo/bar");
+        if (platform == "Windows")
+          BOOST_TEST_EQ(path("a:/bar").absolute("b:/xyz"), "a:/bar");
+      //   !*this.has_root_directory()
+        BOOST_TEST_EQ(path("//net").absolute("//xyz/"), "//net/");
+        BOOST_TEST_EQ(path("//net").absolute("//xyz/abc"), "//net/abc");
+        BOOST_TEST_EQ(path("//net").absolute("//xyz/abc/def"), "//net/abc/def");
+        if (platform == "Windows")
+        {
+          BOOST_TEST_EQ(path("a:").absolute("b:/"), "a:/");
+          BOOST_TEST_EQ(path("a:").absolute("b:/abc"), "a:/abc");
+          BOOST_TEST_EQ(path("a:").absolute("b:/abc/def"), "a:/abc/def");
+          BOOST_TEST_EQ(path("a:foo").absolute("b:/"), "a:/foo");
+          BOOST_TEST_EQ(path("a:foo").absolute("b:/abc"), "a:/abc/foo");
+          BOOST_TEST_EQ(path("a:foo").absolute("b:/abc/def"), "a:/abc/def/foo");
+          BOOST_TEST_EQ(path("a:foo/bar").absolute("b:/"), "a:/foo/bar");
+          BOOST_TEST_EQ(path("a:foo/bar").absolute("b:/abc"), "a:/abc/foo/bar");
+          BOOST_TEST_EQ(path("a:foo/bar").absolute("b:/abc/def"), "a:/abc/def/foo/bar");
+        }
+    // !*this.has_root_name()
+      //   *this.has_root_directory()
+        BOOST_TEST_EQ(path("/").absolute("//xyz/"), "//xyz/");
+        BOOST_TEST_EQ(path("/").absolute("//xyz/abc"), "//xyz/");
+        BOOST_TEST_EQ(path("/foo").absolute("//xyz/"), "//xyz/foo");
+        BOOST_TEST_EQ(path("/foo").absolute("//xyz/abc"), "//xyz/foo");
+      //   !*this.has_root_directory()
+        BOOST_TEST_EQ(path("foo").absolute("//xyz/abc"), "//xyz/abc/foo");
+        BOOST_TEST_EQ(path("foo/bar").absolute("//xyz/abc"), "//xyz/abc/foo/bar");
+        BOOST_TEST_EQ(path(".").absolute("//xyz/abc"), "//xyz/abc/.");
+        BOOST_TEST_EQ(path("..").absolute("//xyz/abc"), "//xyz/abc/..");
+        BOOST_TEST_EQ(path("./foo").absolute("//xyz/abc"), "//xyz/abc/./foo");
+        BOOST_TEST_EQ(path("../foo").absolute("//xyz/abc"), "//xyz/abc/../foo");
+        if (platform == "POSIX")
+        {
+          BOOST_TEST_EQ(path("foo").absolute("/abc"), "/abc/foo");
+          BOOST_TEST_EQ(path("foo/bar").absolute("/abc"), "/abc/foo/bar");
+          BOOST_TEST_EQ(path(".").absolute("/abc"), "/abc/.");
+          BOOST_TEST_EQ(path("..").absolute("/abc"), "/abc/..");
+          BOOST_TEST_EQ(path("./foo").absolute("/abc"), "/abc/./foo");
+          BOOST_TEST_EQ(path("../foo").absolute("/abc"), "/abc/../foo");
+        }
+  }
+
+ //  construction_tests  ---------------------------------------------------------------//
 
   void construction_tests()
   {
@@ -1573,6 +1630,7 @@
   append_tests();
   overload_tests();
   query_and_decomposition_tests();
+  composition_tests();
   iterator_tests();
   non_member_tests();
   exception_tests();
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-01-17 08:11:47 EST (Sun, 17 Jan 2010)
@@ -398,7 +398,6 @@
     CHECK(path("").remove_filename() == "");
     CHECK(path("foo").remove_filename() == "");
     CHECK(path("foo/bar").remove_filename() == "foo");
-
   }
 
 //  //  test_modifiers  ------------------------------------------------------------------//
@@ -435,7 +434,20 @@
     CHECK(*++it == "bar");
     CHECK(*++it == "baz");
     CHECK(++it == p3.end());
+  }
+
+  //  test_compositions  ---------------------------------------------------------------//
+
+  void test_compositions()
+  {
+    std::cout << "testing compositions..." << std::endl;
 
+//    CHECK(path("").absolute("") == "");  // should assert
+//    CHECK(path("").absolute("foo") == ""); // should assert
+    CHECK(path("baa").absolute("c:/") == "c:/baa"); 
+    CHECK(path("/baa").absolute("c:/foo").string() == path("c:/baa").string()); 
+    CHECK(path("baa/baz").absolute("c:/foo/bar").string()
+      == path("c:/foo/bar\\baa/baz").string()); 
   }
 
   //  test_decompositions  -------------------------------------------------------------//
@@ -804,6 +816,7 @@
   test_other_non_members();
   //test_modifiers();
   test_iterators();
+  test_compositions();
   test_decompositions();
   test_queries();
   test_imbue_locale();