Boost logo

Boost :

From: Thomas Witt (witt_at_[hidden])
Date: 2002-09-19 15:23:17


Hello

I propose the following changes to the filesystem path interface in order to
solve the problem of rooted/absolute paths.

I'd like to introduce the notion of a path 'root' and of an 'absolute path'.

Root:
A filessystem can have multiple roots(e.g. C:;D:) each filesystem has at least
one root. A path can be rooted. That means it belongs to the hierarchie of
its root.

Roots are modelled by a newly introduced root type that
provides the following public interface. An access method
is added to path to retrieve the root. Whether Root has to be default
constructable needs further investigation.

namespace boost {
  namespace filesystem {

    class Root
    {
    public:
      bool empty() const;
    };

    bool operator==(Root const&, Root const&);
    bool operator!=(Root const&, Root const&);
    bool operator<(Root const&, Root const&);

    class path
    {
      ...
    /*
     * Returns an empty root for
     * non rooted pathes.
     * Otherwise a non empty root
     * Root that refer to the same filesystem
     * hierarchy are guaranteed to compare equal.
     */
    Root const root() const;
      ...
    };
  }
}

The path iterator no longer references the root element of the
path. I.e. iterating over a path means iterating over path elements
as defined in the grammar. From my experience that would greatly
simplify path iteratoin.

Absolut Path:
An absolute path describes a fixed named location in a filesystem
hierarchy. Note that the location is fixed with respect to the name
not the referenced entity. Its counterpart is the relative path. An absolute
path must have a non-empty root. A relative path does not have to be rooted
but it can be rooted. Forinstance on Windows C:xy.txt is a relative rooted
path.

To support the notion of relative/absolute paths the following methods are
added/modofied. Whether these should be members/nonmembers needs further
investigation

namespace boost {
  namespace filesystem {

    class path
    {
      ...
    /*
     * Returns true if path is absolute
     */
    bool is_absolute() const;

    /*
     * Precondition p.root().empty()
     */
    path& <<=(path const& p);

    /*
     * Precondition p.root().empty()
     */
    path const operator<<(path const& p)

      ...
    };

    /*
     * Returns an absolute path by either
     * prepending the current working directory
     * of the application, or by inserting the root
     * specific working directory for rooted paths.
     * Does nothing if p is absolute.
     */
    path const absolute(path const& p);

    // We may want to provide the following
    // convenience method
    /*
     * Merges p1 and p2.
     *
     * Precondition ((p1.root() == p2.root())
                     || p2.root().empty()
                     || p1.root().empty) )
                    if both are absolute one must be a sub path of the other.
     */
    path const merge(path const& p1, path const& p2);

  }
}

Comments ?

--Thomas

-- 
Dipl.-Ing. Thomas Witt
Institut fuer Verkehrswesen, Eisenbahnbau und -betrieb, Universitaet Hannover
voice: +49(0) 511 762 - 4273, fax: +49(0) 511 762-3001
http://www.ive.uni-hannover.de

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk