Boost logo

Boost :

From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2004-09-27 12:18:56


Gennadiy Rozental wrote:

>
> "Angus Leeming" <angus.leeming_at_[hidden]> wrote in message
> news:cj96ub$l89$1_at_sea.gmane.org...
>> Dear all,
>>
>> I've taken Richard Johnson's glob_iterator that he posted to the list
>> back in January and re-written it completely, using Boost.Spirit to
>> transform the input 'glob' into an equivalent regex. The result is a
>> 'boost::glob' function that I believe is fully POSIX-conformant.
>>
>> Example usage:
>>
>> fs::path const starting_directory(".");
>> std::list<fs::path> const matches =
>> boost::glob("../te?t/foo*bar", starting_directory);
>
> This look way too inefficient. Why would you want to copy list of complex
> objects? Iterator interface seems much better fit here.

Hi, Gennadiy.

Rich Johnson's original proposal was for

class glob_iterator
    : public filter_iterator<
          glob_predicate<>,
          filesystem::directory_iterator>
struct glob_iterator {};

Indeed, I've retained this, although I shoved it into namespace
boost::detail.

The problem is that this glob_iterator will iterate only over the contents
of a single directory. Moreover, good implementations of the system glob
require that:

   In order to have access to a pathname, this function requires
   search permission on every component of a pathname except the last,
   and read permission on each directory of any filename component
   in @c pattern that contains a wild card.

which means that you *shouldn't* use glob_iterator if the component does
not contain wildcards. Would you be happy if I changed the interface to:

    std::list<fs::path> matches;
    boost::glob(matches, "../te?t/foo*bar", starting_directory);

If not, could you expand further?

Regards,
Angus


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