Skip to content

Commit

Permalink
add peek all with break
Browse files Browse the repository at this point in the history
  • Loading branch information
Forairaaaaa committed Mar 19, 2024
1 parent 7fba103 commit ef6bfb6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/utils/ring_buffer/ring_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ namespace SmoothUIToolKit
return true;
}

bool peekAllWithBreak(std::function<void(const T&, bool& stopPeeking)> valueCallback)
{
if (isEmpty())
return false;

size_t peek_index = _data.r_index;
bool stop_peeking = false;
while (peek_index != _data.w_index)
{
valueCallback(_data.buffer[peek_index], stop_peeking);
peek_index = (peek_index + 1) % _data.capacity;

if (stop_peeking)
break;
}
return true;
}

size_t valueNum()
{
if (isFull())
Expand Down

0 comments on commit ef6bfb6

Please sign in to comment.