ska-sa / spead2

Library for the Streaming Protocol for Exchange of Astronomical Data (SPEAD)
http://spead2.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
23 stars 14 forks source link

Support ringbuffer iteration #307

Closed bmerry closed 9 months ago

bmerry commented 10 months ago

This allows this pattern:

while (true)
{
    try
    {
        auto value = ringbuffer.pop();
        // Do stuff with value
    }
    catch (spead2::ringbuffer_stopped &)
    {
        break;
    }
}

to be replaced by

for (auto value : ringbuffer)
{
    // Do stuff with value
}

This was previously implemented for class ring_stream in #294. This PR makes the iterator implementation more generic and applies it to class ringbuffer as well.

james-smith-za commented 9 months ago

I presume that the macos failures are addressed in #306 ?

sjperkins commented 9 months ago

Will take a look @bmerry. Ideally, when you like this reviewed by?

bmerry commented 9 months ago

I presume that the macos failures are addressed in https://github.com/ska-sa/spead2/pull/306 ?

Yes, that's the theory.

Will take a look @bmerry. Ideally, when you like this reviewed by?

Thanks! This week would be great if you have the time.

bmerry commented 9 months ago

Is the changed behaviour covered by existing test cases in https://github.com/ska-sa/spead2/pull/294?

More-or-less - the hairy bits anyway. The begin() and end() functions on the ringbuffer class aren't covered in the tests, but they're pretty trivial, and I'm developing more example code for a tutorial so I'm happy that it's working at the moment (and if it's broken at compile time I'll find out about it).