Boost logo

Boost :

From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2004-09-28 09:24:12

Angus Leeming wrote:

> Gennadiy Rozental wrote:
>> You need to implement iterator that match InputIterator concept.
>> Also it is very similar to iteration though N-ary matrix.
>> You need to build a collection of directory iterators on each
>> level.
>> Here is a sketch of how next function would look like (if you use
>> input_iterator_adaptor).
>> void next()
>> {
>> starting from end find first level iterator that is not equal
>> to end
>> If not found, finite la comedi.
>> if found last level, increment it and that's all
>> If found level in the middle increment it, rebuild all
>> directory
>> iterators for following levels and start from the beginning.
>> }
>> I think there should be iterator like this (generic, over matrix)
>> somewhere.If not it would be interesting undertaking.
> Gennadiy,
> Thank you for this. I'll mull it over and get back to you.

Ok, I've thought a bit and think I understand your proposal. Let's
use a class to store the predicates that will be used to initialise
the filter_iterators at each level of the tree:

class glob_pattern {
        vector<glob_predicate<> > predicates;

Ie, "../foo*bar/baz?.eps" would require that glob_pattern stored a
vector of 3 predicates.

Let's call these "filter_iterators at each level of the
tree" glob_directory_iterators. A glob_iterator will store a
vector of glob_directory_iterators. (Also 3 in the example's case).
Incrementing a glob_iterator will use a strategy similar to the one
you outline above.

class glob_pattern {
        vector<glob_predicate<> > predicates;
        glob_iterator begin() const;
        glob_iterator end() const;

class glob_iterator {
        vector<glob_directory_iterator> dir_iterators;
        glob_iterator(vector<glob_predicate<> > const & p)
                typedef vector<glob_predicate<> > p_vec;

                p_vec::const_iterator it = p.begin();
                p_vec::const_iterator const end = p.end();
                for (; it != end; ++it)

        glob_iterator operator++()
        { /* implement the "next" strategy */ }

This strategy moves all the nonsense about "does the predicate
contain wildcards or not" into glob_directory_iterator. Fine.

No doubt there's lots of implementation details left, (like using
input_iterator_adaptor), but I think that this pseudo code covers the

Am I on the right track?

Boost list run by bdawes at, gregod at, cpdaniel at, john at