Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2002-03-07 16:47:45


> actually i want no root_directory () function at all, but a
> hierarchy_iterator returning '/' for posix as a single element and all
> drive letters beginning with 'a:' (if it exists) for win. this was
> proposed by beman in the initial requirements (at least i understood it
> this way) and i thought that its a quite good idea. in my last posting
> about this problem i just wanted to make clear how unclear and confusing
> a directory_iterator (root_directory ()) solution can be. as this
> discussion proves, everyone has another opinion on this whereas a
> hierarchy_iterator leaves little room for guessing what i returns on
> each platform.

I like what you want to do with hierarchy_iterator except I see no need for a
different type. It is plain and simple a directory_iterator. Consider the
following:

class directory_iterator {
public:
  enum special_locations {roots, current_working, current_root};
  directory_iterator(special_locations);
  //...
};

On Unix
  directory_iterator ditr(directory_iterator::roots) ditr; // will return "/"

On Unix
  directory_iterator ditr(directory_iterator::roots) ditr; // will return "A:\
C:\ ..."

I think this could be done portably and still no global state. Of course, no
guarantees if someone mounts a new drive or changes the current working
directory after iteration has begun....

Jeff


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