|
Boost : |
From: Carlo Wood (carlo_at_[hidden])
Date: 2004-08-26 13:48:02
On Thu, Aug 26, 2004 at 12:18:12PM -0400, Beman Dawes wrote:
> I remember that you had some feeling that the generic path grammar could be
> improved to make relative/absolute queries more uniform between Windows and
> POSIX. My plan was to sit down with you in Sydney and learn more about your
> ideas, but then I ended up not going. Maybe we could work on that by email.
What do you think about my proposal(s)?
I (too?) think that an important improvement can be made by
making an explicit distinguishment between relative and
absolute paths.
My feeling is that only relative paths are truely portable
and therefore, the developer should be "forced" more or less
to set up the absolute path "nodes" that he wants to work
with as a sort of initialization.
Apart from that there is then user input of course, which
might happen at any point in the code - but that is then
either a change of such a "node", or it is an explicit
filepath which is to be treated at native the whole time.
My idea is therefore that there should be two types:
- An absolute/native path type
and
- A relative/portable path type
It should not be possible to convert the native_path class
into the relative_path class type (these are just my naming proposals),
but the other way around can be seemless supported by allowing
to specify a "node" (of the absolute/native path type) at the
moment a relative path is created. The developer then can concentrate
and work on with just the portable, relative, value of the path
and does not have to worry about the native conversion when
this is necessary prior to calling a system call (like say fs::exists),
because this could be done automatically then.
Actually, this idea is very closely related to the whole windows
concept of multiple roots: C:, D:, E: etc are not only "just"
unmounted partitions (that is, on linux they would be just mounted
somewhere and therefore, if C: is the root say, a D: would be /usr
etc) but they have a _variable_ value each: the working directory.
If one specifies A:foo or B:foo, then this refers to whatever
the value of the "node" (working directory) of 'A' respectively
'B' is at that moment - with the restriction that they have to
be on that particular partition. Of course we'd not have that
restriction.
Example:
fs::native_path A("C:/mydir");
fs::native_path B("B:/");
fs::native path C("C:/actually this can be anything");
fs::relative_path bar("bar.txt");
// Use A / bar, or B / bar or C / bar.
However, I think it makes more sense to do:
fs::relative_path bar(C); // Relative to C.
bar = "bar.txt";
// Just use bar.
if (fs::exists(bar))
...
What do you think?
-- Carlo Wood <carlo_at_[hidden]>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk