Skip to content

Commit

Permalink
Revert to lexical functions back to being members of class path. This…
Browse files Browse the repository at this point in the history
… is not the time to redesign the library's lexical vs operational conventions. It would break existing users mental model of lexical vs operational.

See doc/relative_proposal.html#Add-lexical-functions for additional rationale.
  • Loading branch information
Beman committed Oct 25, 2015
1 parent b0091c2 commit 3c344a5
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 252 deletions.
11 changes: 2 additions & 9 deletions doc/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,6 @@ <h2><a name="Headers">Headers</a></h2>
</ul>
<h2><a name="Examples">Example programs</a></h2>
<p>See the <a href="tutorial.html">tutorial</a> for example programs.</p>
<h3>Other examples</h3>
<p>The programs used to generate the Boost regression test status tables use the
Filesystem Library extensively.&nbsp; See:</p>
<ul>
<li><a href="../../../tools/regression/src/process_jam_log.cpp">process_jam_log.cpp</a></li>
<li><a href="../../../tools/regression/src/compiler_status.cpp">compiler_status.cpp</a></li>
</ul>
<h2><a name="Implementation">Implementation</a></h2>
<p>The current implementation supports operating systems which provide
the POSIX or Windows API's.</p>
Expand Down Expand Up @@ -288,7 +281,7 @@ <h2><a name="Building">Building</a> the object-library</h2>
supplied in directory libs/filesystem/build, or the user can construct an IDE
project or make file which includes the object-library source files.</p>
<p>The object-library source files are
supplied in directory <a href="src">libs/filesystem/src</a>. These source files implement the
supplied in the <a href="../src">src directory</a>. These source files implement the
library for POSIX or Windows compatible operating systems; no implementation is
supplied for other operating systems. Note that many operating systems not
normally thought of as POSIX systems, such as mainframe legacy
Expand Down Expand Up @@ -451,7 +444,7 @@ <h3>Version 1</h3>

<hr>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->31 August, 2015<!--webbot bot="Timestamp" endspan i-checksum="34633" --></p>
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->25 October, 2015<!--webbot bot="Timestamp" endspan i-checksum="38877" --></p>

<p>&copy; Copyright Beman Dawes, 2002-2005</p>
<p> Use, modification, and distribution are subject to the Boost Software
Expand Down
146 changes: 106 additions & 40 deletions doc/reference.html

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions doc/relative_proposal.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
operational <code>relative</code> functions</a><br>
&nbsp;&nbsp;&nbsp; <a href="#Provide-separate-proximate">Provide
separate lexical and operational <code>proximate</code> functions</a><br>
&nbsp;&nbsp;&nbsp; <a href="#Add-lexical-functions-as-path-members">
Add lexical functions as <code>path</code> member functions</a><br>
&nbsp;&nbsp;&nbsp; <a href="#Add-lexical-functions">Add lexical functions as <code>path</code> member functions</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Provide-normal">Provide a non-member function
<code>lexically_normal</code> returning a
normal form path</a><br>
Expand All @@ -63,7 +62,7 @@
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Specify-op-rel-weakly">Specify operational <code>relative</code> in terms of <code>
weakly_canonical</code></a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Specify-op-rel-lex-rel">Specify operational <code>relative</code> in terms of
<code>lexical
<code>lexically
relative</code></a><br>
<a href="#Proposed-wording">Proposed wording</a><br>
&nbsp;&nbsp;&nbsp; <a href="#Define-normal-form">Define <i>normal form</i></a><br>
Expand Down Expand Up @@ -346,7 +345,7 @@ <h4><a name="Synopsis-path">Synopsis</a></h4>
<h4><a name="Specification-path">Specification</a></h4>


<pre>path lexically_<a name="normal">normal</a>() const;</pre>
<pre>path <a name="lex-normal">lexically_normal</a>() const;</pre>
<blockquote>
<p><i>Overview:</i> Returns <code>*this</code> with redundant current directory
(<i>dot</i>), parent directory (<i>dot-dot</i>), and <i>directory-separator</i> elements removed.</p>
Expand All @@ -360,7 +359,7 @@ <h4><a name="Specification-path">Specification</a></h4>
does not affect <code>path</code> equality.<i> —end example</i>]</p>
</blockquote>

<pre>path lexically_<a name="lex-relative">relative</a>(const path&amp; base) const;</pre>
<pre>path <a name="lex-relative">lexically_relative</a>(const path&amp; base) const;</pre>
<blockquote>
<p><i>Overview:</i> Returns <code>*this</code> made relative to <code>base</code>.
Treats empty or identical paths as corner cases, not errors. Does not resolve
Expand Down Expand Up @@ -481,7 +480,7 @@ <h4><a name="Specification-ops">Specification</a></h4>
Resolves symlinks and normalizes both <code>p</code> and <code>base</code>
before other processing.</p>

<p><i>Returns:</i> <code>l<a href="#lex-proximate">exically_relative</a>(<a href="#weakly_canonical">weakly_canonical</a>(p), <a href="#weakly_canonical">weakly_canonical</a>(base))</code>. The second form returns <code>path()</code> if an error occurs.</p>
<p><i>Returns:</i> <code><a href="#weakly_canonical">weakly_canonical</a>(p).l<a href="#lex-proximate">exically_relative</a>(<a href="#weakly_canonical">weakly_canonical</a>(base))</code>. The second form returns <code>path()</code> if an error occurs.</p>
<p><i>Throws:</i> As specified in Error reporting.</p>
</blockquote>

Expand All @@ -495,7 +494,7 @@ <h4><a name="Specification-ops">Specification</a></h4>
path proximate(const path&amp; p, const path&amp; base, system::error_code&amp; ec);</pre>
<blockquote>

<p><i>Returns:</i> <code>l<a href="#lex-proximate">exically_proximate</a>(<a href="#weakly_canonical">weakly_canonical</a>(p), <a href="#weakly_canonical">weakly_canonical</a>(base))</code>. The second form returns <code>path()</code> if an error occurs.</p>
<p><i>Returns:</i> <code><a href="#weakly_canonical">weakly_canonical</a>(p).l<a href="#lex-proximate">exically_proximate</a>(<a href="#weakly_canonical">weakly_canonical</a>(base))</code>. The second form returns <code>path()</code> if an error occurs.</p>
<p><i>Throws:</i> As specified in Error reporting.</p>
</blockquote>

Expand Down
15 changes: 8 additions & 7 deletions doc/release_history.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@

<h2>1.60.0</h2>
<ul>
<li><b>New:</b> Added functions <code><a href="reference.html#normal">
lexically_normal</a></code>, <code><a href="reference.html#lex-relative">
lexically_relative</a></code>, <code><a href="reference.html#op-relative">
relative</a></code>, and <code><a href="reference.html#weakly_canonical">
weakly_canonical</a></code>. Many thanks to Jamie Allsop for his help and
perseverance. Resoves tickets
<li dir="ltr">
<p dir="ltr"><b>New:</b> Added functions <code>
<a href="reference.html#lex-normal">lexically_normal</a></code>, <code>
<a href="reference.html#lex-relative">lexically_relative</a></code>, <code>
<a href="reference.html#op-relative">relative</a></code>, and <code>
<a href="reference.html#weakly_canonical">weakly_canonical</a></code>. Many thanks to Jamie Allsop for his help and
perseverance. Resolves tickets
<a href="https://svn.boost.org/trac/boost/ticket/1976">#1976</a>,
<a href="https://svn.boost.org/trac/boost/ticket/5897">#5897</a>,
<a href="https://svn.boost.org/trac/boost/ticket/6249">#6249</a></li>
Expand Down Expand Up @@ -393,7 +394,7 @@ <h2>1.46.0</h2>
</ul>
<hr>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->19 October, 2015<!--webbot bot="Timestamp" endspan i-checksum="38884" --></p>
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->25 October, 2015<!--webbot bot="Timestamp" endspan i-checksum="38877" --></p>
<p>&copy; Copyright Beman Dawes, 2011</p>
<p> Use, modification, and distribution are subject to the Boost Software
License, Version 1.0. See <a href="http://www.boost.org/LICENSE_1_0.txt">
Expand Down
16 changes: 8 additions & 8 deletions include/boost/filesystem/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@ namespace boost
void permissions(perms prms) BOOST_NOEXCEPT { m_perms = prms; }

bool operator==(const file_status& rhs) const BOOST_NOEXCEPT
{ return type() == rhs.type() &&
{ return type() == rhs.type() &&
permissions() == rhs.permissions(); }
bool operator!=(const file_status& rhs) const BOOST_NOEXCEPT
{ return !(*this == rhs); }
{ return !(*this == rhs); }

private:
file_type m_value;
Expand Down Expand Up @@ -1201,8 +1201,8 @@ namespace filesystem
"depth() on end recursive_directory_iterator");
return m_imp->m_level;
}
int level() const BOOST_NOEXCEPT { return depth(); }
int level() const BOOST_NOEXCEPT { return depth(); }

bool recursion_pending() const BOOST_NOEXCEPT
{
Expand All @@ -1211,8 +1211,8 @@ namespace filesystem
return (m_imp->m_options & symlink_option::_detail_no_push)
== symlink_option::_detail_no_push;
}
bool no_push_pending() const BOOST_NOEXCEPT { return recursion_pending(); }
bool no_push_pending() const BOOST_NOEXCEPT { return recursion_pending(); }

# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
bool no_push_request() const BOOST_NOEXCEPT { return no_push_pending(); }
Expand All @@ -1235,8 +1235,8 @@ namespace filesystem
else
m_imp->m_options &= ~symlink_option::_detail_no_push;
}
void no_push(bool value=true) BOOST_NOEXCEPT { disable_recursion_pending(value); }
void no_push(bool value=true) BOOST_NOEXCEPT { disable_recursion_pending(value); }

file_status status() const
{
Expand Down
32 changes: 11 additions & 21 deletions include/boost/filesystem/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ namespace boost
{
namespace filesystem
{
// forward declarations
class BOOST_FILESYSTEM_DECL path;
BOOST_FILESYSTEM_DECL path lexically_normal(const path& p);

//------------------------------------------------------------------------------------//
// //
Expand Down Expand Up @@ -530,6 +527,16 @@ namespace filesystem
# endif
}

// ----- lexical operations -----

path lexically_normal() const;
path lexically_relative(const path& base) const;
path lexically_proximate(const path& base) const
{
path tmp(lexically_relative(base));
return tmp.empty() ? *this : tmp;
}

// ----- iterators -----

class iterator;
Expand All @@ -556,7 +563,7 @@ namespace filesystem
# if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
// recently deprecated functions supplied by default
path& normalize() {
path tmp(lexically_normal(*this));
path tmp(lexically_normal());
m_pathname.swap(tmp.m_pathname);
return *this;
}
Expand Down Expand Up @@ -781,23 +788,6 @@ namespace filesystem

inline path operator/(const path& lhs, const path& rhs) { return path(lhs) /= rhs; }

// ----- lexical operations -----
//
// naming convention: prefix with "lexically_" to alert users that these functions
// have purely lexical semantics and, when necesssary, to disambiguate from
// operational functions with the same name.

BOOST_FILESYSTEM_DECL
path lexically_normal(const path& p);
BOOST_FILESYSTEM_DECL
path lexically_relative(const path& p, const path& base);
inline
path lexically_proximate(const path& p, const path& base)
{
path tmp(lexically_relative(p, base));
return tmp.empty() ? p : tmp;
}

// inserters and extractors
// use boost::io::quoted() to handle spaces in paths
// use '&' as escape character to ease use for Windows paths
Expand Down
6 changes: 3 additions & 3 deletions src/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ namespace detail
path wc_p(weakly_canonical(p, &tmp_ec));
if (error(tmp_ec.value(), base, ec, "boost::filesystem::relative"))
return path();
return lexically_relative(wc_p, wc_base);
return wc_p.lexically_relative(wc_base);
}

BOOST_FILESYSTEM_DECL
Expand Down Expand Up @@ -1919,14 +1919,14 @@ namespace detail
}

if (head.empty())
return lexically_normal(p);
return p.lexically_normal();
head = canonical(head, tmp_ec);
if (error(tmp_ec.value(), head, ec, "boost::filesystem::weakly_canonical"))
return path();
return tail.empty()
? head
: (tail_has_dots // optimization: only normalize if tail had dot or dot-dot element
? lexically_normal(head/tail)
? (head/tail).lexically_normal()
: head/tail);
}
} // namespace detail
Expand Down
26 changes: 13 additions & 13 deletions src/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,34 +407,34 @@ namespace filesystem
}
}

path lexically_relative(const path& p, const path& base)
path path::lexically_relative(const path& base) const
{
std::pair<path::iterator, path::iterator> mm
= detail::mismatch(p.begin(), p.end(), base.begin(), base.end());
if (mm.first == p.begin() && mm.second == base.begin())
= detail::mismatch(begin(), end(), base.begin(), base.end());
if (mm.first == begin() && mm.second == base.begin())
return path();
if (mm.first == p.end() && mm.second == base.end())
if (mm.first == end() && mm.second == base.end())
return detail::dot_path();
path tmp;
for (; mm.second != base.end(); ++mm.second)
tmp /= detail::dot_dot_path();
for (; mm.first != p.end(); ++mm.first)
for (; mm.first != end(); ++mm.first)
tmp /= *mm.first;
return tmp;
}

// normal --------------------------------------------------------------------------//

path lexically_normal(const path& p)
path path::lexically_normal() const
{
if (p.empty())
return p;
if (m_pathname.empty())
return *this;

path temp;
path::iterator start(p.begin());
path::iterator last(p.end());
path::iterator stop(last--);
for (path::iterator itr(start); itr != stop; ++itr)
iterator start(begin());
iterator last(end());
iterator stop(last--);
for (iterator itr(start); itr != stop; ++itr)
{
// ignore "." except at start and last
if (itr->native().size() == 1
Expand Down Expand Up @@ -478,7 +478,7 @@ namespace filesystem
// }
//}

path::iterator next(itr);
iterator next(itr);
if (temp.empty() && ++next != stop
&& next == last && *last == detail::dot_path())
{
Expand Down
Loading

0 comments on commit 3c344a5

Please sign in to comment.