|
Boost : |
From: John Maddock (John_Maddock_at_[hidden])
Date: 2002-01-27 08:03:55
I'm really pleased to see someone working on this, however I'm not sure
that we have the right interface yet, on the whole I prefer
http://stewart.simwright.net/sample/classswMenagerie_1_1Pathname.html
to
http://www.helsinki.fi/~kajala/code/path_20020124a/classboost_1_1path.html
but a few extra design considerations should be in order:
the class should be a template with narrow and wide character versions (I'm
not actually sure if a wide character version is possible on non-win32
systems unless there are OS-specific rather than POSIX-standard API's
available, but that's another issue):
template <class charT, class traits=std::char_traits<charT>, class
Allocator=std::allocator<charT> >
class basic_pathname;
typedef basic_pathname<char> pathname;
typedef basic_pathname<wchar_t> wpathname; // or similar names....
For the interface - we already have the basics - it should be an immutable
sequence (23.1.1) - and in addition support some of the extra interfaces
analogous to those of std::basic_string:
char_type operator[]const;
const_pointer c_str()const;
const_pointer data()const;
along with:
typedef std::basic_string<charT, traits, Allocator> string_type;
string_type str()const;
which just leaves the pathname-specific member functions (probably more
similar to
http://stewart.simwright.net/sample/classswMenagerie_1_1Pathname.html than
http://www.helsinki.fi/~kajala/code/path_20020124a/classboost_1_1path.html)
.
BTW member functions like parent()const; should return a pathname not a
string. We also need static member functions for:
the current directory (absolute).
the current directory (relative - ie ./).
the parent directory (relative ie ../).
BTW I am open to the issue of whether there should be separate classes for
filenames and pathnames - although logically they are probably the same
thing. I would also like to see a directory_iterator/file_iterator classes
which enumerated pathnames (note not strings!), there is something like
this already in boost - both Dietmar's dirit lib and in
boost/regex/detail/fileiter.hpp. Neither are perfect, but both could be
scavenged for code and ideas. Finally we also need a way to enumerate
directories in the PATH, and to find the first directory in the PATH which
has a particular file.
whew, enough for now :-)
- John Maddock
http://ourworld.compuserve.com/homepages/john_maddock/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk