|
Boost : |
From: Rob Stewart (stewart_at_[hidden])
Date: 2004-10-01 11:41:13
From: Angus Leeming <angus.leeming_at_[hidden]>
>
> This is, in essence, what I am proposing. I have now reworked the interface
> following Gennadiy's suggestion. Here's a glob_iterator that can recurse
> down directories:
>
> class BOOST_GLOB_DECL glob_iterator
> : public iterator_facade<
> glob_iterator // Derived type
> , filesystem::path const // value_type
> , single_pass_traversal_tag
> >
> {
> public:
> glob_iterator() {}
> glob_iterator(std::string const & pattern,
> filesystem::path const & wd,
> glob_flags flags);
> private:
> ...
> };
I think you misunderstood what Gennadiy meant. (If not, I think
this is a good idea, anyway.) Your function should accept an
output iterator through which you save the results. That enables
the caller to decide where the results go instead of you deciding
that they go into a list which then must be iterated. Thus, I'm
proposing something like this:
template <typename OutIt, typename Char>
OutIt
glob(OutIt & out, std::basic_string<Char> const & pattern,
filesystem::path const & pathname, glob_flags flags);
Appropriate output iterators can forward the matches to a
collection, to a GUI control, to a file, etc.
> It works, but is considerably slower than the function returning a list. No
> doubt profiling will help track down what I'm doing inefficiiently.
No doubt.
-- Rob Stewart stewart_at_[hidden] Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk