--- nono/lib/fixedqueue.h 2026/04/29 17:04:28 1.1 +++ nono/lib/fixedqueue.h 2026/04/29 17:04:40 1.1.1.5 @@ -1,8 +1,11 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // +#pragma once + #include "header.h" #include @@ -76,15 +79,20 @@ class FixedQueue return length; } + // 要素が一杯なら true を返す + bool IsFull() const { + return (length >= capacity); + } + // 要素を覗き見る。 // idx は 0 .. length-1 までで、0 がキューの先頭。 - T Peek(int idx) { + T Peek(int idx) const { // XXX 範囲チェックすべきだがとりあえず return buf[(start + idx) % capacity]; } private: - std::vector buf; // バッファ - uint start = 0; // 開始位置 - uint length = 0; // 現在有効な長さ + std::vector buf {}; // バッファ + uint start {}; // 開始位置 + uint length {}; // 現在有効な長さ };