Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2002-02-01 02:44:09


From: "mfdylan" <dylan_at_[hidden]>
Sent: Friday, February 01, 2002 1:02 AM
> --- In boost_at_y..., Glen Knowles <gknowles_at_c...> wrote:
> > I do like having a path class rather then a simple string so that I
> can use
> > member functions to access path components, get canonical name, etc.
> > Policies could be used to implement some of this functionality with
> prebuilt
> > packages for windows and unix.
> >

[SNIP]

> On possibility would be for a suffix() call that took either no or
> one argument:
>
> pathname p("/home.dylan/file.cpp.keep.1");
> assert(p.suffix() == ".cpp.keep.1");
> assert(p.suffix(1) == ".cpp");
> assert(p.suffix(2) == ".keep");
> assert(p.suffix(3) == ".1");
> assert(p.suffix(-1) == ".1");
> assert(p.suffix(-2) == ".keep.1");
> assert(p.suffix(-3) == ".cpp.keep.1");
>
> Likewise for basename
>
> p.basename() = "file.cpp.keep.1"
> assert(p.basename(1) == "file");
> assert(p.basename(2) == "file.cpp");
> assert(p.basename(3) == "file.cpp.keep");
> assert(p.basename(4) == "file.cpp.keep.1");
>
> but also (in the tradition of POSIX basename)
>
> assert(p.basename(".1") == "file.cpp.keep");
> assert(p.basename(".cpp.keep.1") == "file");
> assert(p.basename(p.suffix()) == "file");
>
> Only then you need a separate function to modify the basename
> (modify_basename?) which I don't think is a big deal (I've never
> liked the policy of using a property name as a 'setting' function.
> Unfortunately there's not always obvious verb choices in the manner
> of capacity/reserve, size/resize etc).
>
> Random ideas continue...
>
> assert(p.dirname() == "/home.dylan");
> assert(p.dirname().dirname() == "/");
> assert(p.dirname().suffix() == ".dylan");
> assert(p.suffix().suffix() == ".cpp.keep");
> assert(p.basename(".1").basename(".keep") == "file.cpp");

I like the idea of this sort of thing. The PathName class I use takes a
filename, and converts it to cannonical form form internal storage (e.g.
removing /./, making all slashes point the same way etc.). It then supports
extracting path components, and building a new path from separate
components. I think changing a path in-place is a no-goer, as Dylan
suggests --- what consititues the suffix?

The PathName comparison can then just check the canonical forms --- are they
the same (give or take case-sensitivity as appropriate)

I also have a separate FileInfo class that accesses the filesystem to check
for existence/type/size/permissions etc. for a file. It could be extended to
compare PathNames --- are they the same object? --- where by default this is
just a simple comparison, but on File Systems with links, it could check the
inode (or something).

Just my 2p

Anthony


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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