Boost logo

Boost :

Subject: Re: [boost] [gil::io] Feedback for scanline_read_iterator
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2013-02-19 05:27:11


Christian Henning wrote:
>>> I think Phil means rather than do the read in operator++, just set a flag
>>> in operator++ that the read should be done, and actually do it in
>>> operator* (which then clears the flag). Then if someone calls operator++
>>> again without calling operator* (which you can detect by the flag being
>>> set in operator++), you can do a skip in operator++, and thus avoid
>>> decoding the line you didn't need.
>>
>> Interesting idea. I'll update the code.
>
> Actually that doesn't work. How would the user signal to just skip a
> scanline? I cannot add a parameter to operator++.

PSEUDO-CODE!!!!

class iterator {
   buffer_t& buffer;
   size_t pending_advance_rows;

public:
   const buffer_t& operator*() {
     while (pending_advance_rows > 1) {
       format_specific_skip_row();
       --pending_advance_rows;
     }
     if (pending_advance_rows == 1) {
       format_specific_read_row_into(buffer);
       --pending_advance_rows;
     }
     return buffer;
   }

   void operator++() {
     ++pending_advance_rows;
   }
};

or in iterator-facade-style:

class iterator: public iterator_facade<........> {
   buffer_t& buffer;
   size_t pending_advance_rows;

   const buffer_t& dereference() {
     while (pending_advance_rows > 1) {
       format_specific_skip_row();
       --pending_advance_rows;
     }
     if (pending_advance_rows == 1) {
       format_specific_read_row_into(buffer);
       --pending_advance_rows;
     }
     return buffer;
   }

   void increment() {
     ++pending_advance_rows;
   }
};


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