Commit 49784513 authored by Max Kellermann's avatar Max Kellermann

util/{Const,Writable}Buffer, ...: rename IsEmpty() to empty(), imitating STL

parent 52305113
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
* object is inaccessible to other threads. * object is inaccessible to other threads.
*/ */
bool IsEmptyUnsafe() const { bool IsEmptyUnsafe() const {
return buffer.IsEmpty(); return buffer.empty();
} }
#endif #endif
......
...@@ -109,7 +109,7 @@ tag_file_scan(Path path, TagBuilder &builder) ...@@ -109,7 +109,7 @@ tag_file_scan(Path path, TagBuilder &builder)
if (!tag_file_scan(path, full_tag_handler, &builder)) if (!tag_file_scan(path, full_tag_handler, &builder))
return false; return false;
if (builder.IsEmpty()) if (builder.empty())
ScanGenericTags(path, full_tag_handler, &builder); ScanGenericTags(path, full_tag_handler, &builder);
return true; return true;
......
...@@ -94,7 +94,7 @@ tag_stream_scan(InputStream &is, TagBuilder &builder) ...@@ -94,7 +94,7 @@ tag_stream_scan(InputStream &is, TagBuilder &builder)
if (!tag_stream_scan(is, full_tag_handler, &builder)) if (!tag_stream_scan(is, full_tag_handler, &builder))
return false; return false;
if (builder.IsEmpty()) if (builder.empty())
ScanGenericTags(is, full_tag_handler, &builder); ScanGenericTags(is, full_tag_handler, &builder);
return true; return true;
......
...@@ -58,7 +58,7 @@ handle_password(Client &client, Request args, Response &r) ...@@ -58,7 +58,7 @@ handle_password(Client &client, Request args, Response &r)
static TagMask static TagMask
ParseTagMask(Request request) ParseTagMask(Request request)
{ {
if (request.IsEmpty()) if (request.empty())
throw ProtocolError(ACK_ERROR_ARG, "Not enough arguments"); throw ProtocolError(ACK_ERROR_ARG, "Not enough arguments");
TagMask result = TagMask::None(); TagMask result = TagMask::None();
...@@ -77,14 +77,14 @@ ParseTagMask(Request request) ...@@ -77,14 +77,14 @@ ParseTagMask(Request request)
CommandResult CommandResult
handle_tagtypes(Client &client, Request request, Response &r) handle_tagtypes(Client &client, Request request, Response &r)
{ {
if (request.IsEmpty()) { if (request.empty()) {
tag_print_types(r); tag_print_types(r);
return CommandResult::OK; return CommandResult::OK;
} }
const char *cmd = request.shift(); const char *cmd = request.shift();
if (StringIsEqual(cmd, "all")) { if (StringIsEqual(cmd, "all")) {
if (!request.IsEmpty()) { if (!request.empty()) {
r.Error(ACK_ERROR_ARG, "Too many arguments"); r.Error(ACK_ERROR_ARG, "Too many arguments");
return CommandResult::ERROR; return CommandResult::ERROR;
} }
...@@ -92,7 +92,7 @@ handle_tagtypes(Client &client, Request request, Response &r) ...@@ -92,7 +92,7 @@ handle_tagtypes(Client &client, Request request, Response &r)
client.tag_mask = TagMask::All(); client.tag_mask = TagMask::All();
return CommandResult::OK; return CommandResult::OK;
} else if (StringIsEqual(cmd, "clear")) { } else if (StringIsEqual(cmd, "clear")) {
if (!request.IsEmpty()) { if (!request.empty()) {
r.Error(ACK_ERROR_ARG, "Too many arguments"); r.Error(ACK_ERROR_ARG, "Too many arguments");
return CommandResult::ERROR; return CommandResult::ERROR;
} }
......
...@@ -169,7 +169,7 @@ handle_count(Client &client, Request args, Response &r) ...@@ -169,7 +169,7 @@ handle_count(Client &client, Request args, Response &r)
} }
SongFilter filter; SongFilter filter;
if (!args.IsEmpty() && !filter.Parse(args, false)) { if (!args.empty() && !filter.Parse(args, false)) {
r.Error(ACK_ERROR_ARG, "incorrect arguments"); r.Error(ACK_ERROR_ARG, "incorrect arguments");
return CommandResult::ERROR; return CommandResult::ERROR;
} }
...@@ -235,7 +235,7 @@ handle_list(Client &client, Request args, Response &r) ...@@ -235,7 +235,7 @@ handle_list(Client &client, Request args, Response &r)
args.pop_back(); args.pop_back();
} }
if (!args.IsEmpty()) { if (!args.empty()) {
filter.reset(new SongFilter()); filter.reset(new SongFilter());
if (!filter->Parse(args, false)) { if (!filter->Parse(args, false)) {
r.Error(ACK_ERROR_ARG, "not able to parse args"); r.Error(ACK_ERROR_ARG, "not able to parse args");
......
...@@ -76,7 +76,7 @@ handle_unsubscribe(Client &client, Request args, Response &r) ...@@ -76,7 +76,7 @@ handle_unsubscribe(Client &client, Request args, Response &r)
CommandResult CommandResult
handle_channels(Client &client, gcc_unused Request args, Response &r) handle_channels(Client &client, gcc_unused Request args, Response &r)
{ {
assert(args.IsEmpty()); assert(args.empty());
std::set<std::string> channels; std::set<std::string> channels;
for (const auto &c : *client.GetInstance().client_list) for (const auto &c : *client.GetInstance().client_list)
...@@ -93,7 +93,7 @@ CommandResult ...@@ -93,7 +93,7 @@ CommandResult
handle_read_messages(Client &client, handle_read_messages(Client &client,
gcc_unused Request args, Response &r) gcc_unused Request args, Response &r)
{ {
assert(args.IsEmpty()); assert(args.empty());
while (!client.messages.empty()) { while (!client.messages.empty()) {
const ClientMessage &msg = client.messages.front(); const ClientMessage &msg = client.messages.front();
......
...@@ -284,7 +284,7 @@ handle_update(Client &client, Request args, Response &r, bool discard) ...@@ -284,7 +284,7 @@ handle_update(Client &client, Request args, Response &r, bool discard)
const char *path = ""; const char *path = "";
assert(args.size <= 1); assert(args.size <= 1);
if (!args.IsEmpty()) { if (!args.empty()) {
path = args.front(); path = args.front();
if (*path == 0 || StringIsEqual(path, "/")) if (*path == 0 || StringIsEqual(path, "/"))
......
...@@ -71,7 +71,7 @@ handle_toggleoutput(Client &client, Request args, Response &r) ...@@ -71,7 +71,7 @@ handle_toggleoutput(Client &client, Request args, Response &r)
CommandResult CommandResult
handle_devices(Client &client, gcc_unused Request args, Response &r) handle_devices(Client &client, gcc_unused Request args, Response &r)
{ {
assert(args.IsEmpty()); assert(args.empty());
printAudioDevices(r, client.GetPartition().outputs); printAudioDevices(r, client.GetPartition().outputs);
return CommandResult::OK; return CommandResult::OK;
......
...@@ -95,7 +95,7 @@ handle_pause(Client &client, Request args, gcc_unused Response &r) ...@@ -95,7 +95,7 @@ handle_pause(Client &client, Request args, gcc_unused Response &r)
{ {
auto &pc = client.GetPlayerControl(); auto &pc = client.GetPlayerControl();
if (!args.IsEmpty()) { if (!args.empty()) {
bool pause_flag = args.ParseBool(0); bool pause_flag = args.ParseBool(0);
pc.LockSetPause(pause_flag); pc.LockSetPause(pause_flag);
} else } else
......
...@@ -242,7 +242,7 @@ handle_playlistinfo(Client &client, Request args, Response &r) ...@@ -242,7 +242,7 @@ handle_playlistinfo(Client &client, Request args, Response &r)
CommandResult CommandResult
handle_playlistid(Client &client, Request args, Response &r) handle_playlistid(Client &client, Request args, Response &r)
{ {
if (!args.IsEmpty()) { if (!args.empty()) {
unsigned id = args.ParseUnsigned(0); unsigned id = args.ParseUnsigned(0);
playlist_print_id(r, client.GetPlaylist(), id); playlist_print_id(r, client.GetPlaylist(), id);
} else { } else {
......
...@@ -801,7 +801,7 @@ ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection, ...@@ -801,7 +801,7 @@ ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection,
TagBuilder tag; TagBuilder tag;
tag.AddItem(tag_type, pair->value); tag.AddItem(tag_type, pair->value);
if (tag.IsEmpty()) if (tag.empty())
/* if no tag item has been added, then the /* if no tag item has been added, then the
given value was not acceptable given value was not acceptable
(e.g. empty); forcefully insert an empty (e.g. empty); forcefully insert an empty
......
...@@ -496,7 +496,7 @@ DecoderBridge::SubmitData(InputStream *is, ...@@ -496,7 +496,7 @@ DecoderBridge::SubmitData(InputStream *is,
SongTime::FromS(timestamp) - SongTime::FromS(timestamp) -
dc.song->GetStartTime(), dc.song->GetStartTime(),
kbit_rate); kbit_rate);
if (dest.IsEmpty()) { if (dest.empty()) {
/* the chunk is full, flush it */ /* the chunk is full, flush it */
FlushChunk(); FlushChunk();
continue; continue;
......
...@@ -25,7 +25,7 @@ bool ...@@ -25,7 +25,7 @@ bool
DecoderBuffer::Fill() DecoderBuffer::Fill()
{ {
auto w = buffer.Write(); auto w = buffer.Write();
if (w.IsEmpty()) if (w.empty())
/* buffer is full */ /* buffer is full */
return false; return false;
......
...@@ -127,7 +127,7 @@ adts_song_duration(DecoderBuffer &buffer) ...@@ -127,7 +127,7 @@ adts_song_duration(DecoderBuffer &buffer)
if (frames == 0) { if (frames == 0) {
auto data = ConstBuffer<uint8_t>::FromVoid(buffer.Read()); auto data = ConstBuffer<uint8_t>::FromVoid(buffer.Read());
assert(!data.IsEmpty()); assert(!data.empty());
assert(frame_length <= data.size); assert(frame_length <= data.size);
sample_rate = adts_sample_rates[(data.data[2] & 0x3c) >> 2]; sample_rate = adts_sample_rates[(data.data[2] & 0x3c) >> 2];
...@@ -255,7 +255,7 @@ faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer &buffer, ...@@ -255,7 +255,7 @@ faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer &buffer,
AudioFormat &audio_format) AudioFormat &audio_format)
{ {
auto data = ConstBuffer<uint8_t>::FromVoid(buffer.Read()); auto data = ConstBuffer<uint8_t>::FromVoid(buffer.Read());
if (data.IsEmpty()) if (data.empty())
throw std::runtime_error("Empty file"); throw std::runtime_error("Empty file");
uint8_t channels; uint8_t channels;
...@@ -283,7 +283,7 @@ faad_decoder_decode(NeAACDecHandle decoder, DecoderBuffer &buffer, ...@@ -283,7 +283,7 @@ faad_decoder_decode(NeAACDecHandle decoder, DecoderBuffer &buffer,
NeAACDecFrameInfo *frame_info) NeAACDecFrameInfo *frame_info)
{ {
auto data = ConstBuffer<uint8_t>::FromVoid(buffer.Read()); auto data = ConstBuffer<uint8_t>::FromVoid(buffer.Read());
if (data.IsEmpty()) if (data.empty())
return nullptr; return nullptr;
return NeAACDecDecode(decoder, frame_info, return NeAACDecDecode(decoder, frame_info,
......
...@@ -617,7 +617,7 @@ FfmpegCheckTag(DecoderClient &client, InputStream &is, ...@@ -617,7 +617,7 @@ FfmpegCheckTag(DecoderClient &client, InputStream &is,
TagBuilder tag; TagBuilder tag;
FfmpegScanTag(format_context, audio_stream, tag); FfmpegScanTag(format_context, audio_stream, tag);
if (!tag.IsEmpty()) if (!tag.empty())
client.SubmitTag(is, tag.Commit()); client.SubmitTag(is, tag.Commit());
} }
......
...@@ -97,7 +97,7 @@ flac_scan_comment(const FLAC__StreamMetadata_VorbisComment_Entry *entry, ...@@ -97,7 +97,7 @@ flac_scan_comment(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
if (handler.pair != nullptr) { if (handler.pair != nullptr) {
const char *comment = (const char *)entry->entry; const char *comment = (const char *)entry->entry;
const DivideString split(comment, '='); const DivideString split(comment, '=');
if (split.IsDefined() && !split.IsEmpty()) if (split.IsDefined() && !split.empty())
tag_handler_invoke_pair(handler, handler_ctx, tag_handler_invoke_pair(handler, handler_ctx,
split.GetFirst(), split.GetFirst(),
split.GetSecond()); split.GetSecond());
......
...@@ -211,7 +211,7 @@ MPDOpusDecoder::HandleTags(const ogg_packet &packet) ...@@ -211,7 +211,7 @@ MPDOpusDecoder::HandleTags(const ogg_packet &packet)
if (ScanOpusTags(packet.packet, packet.bytes, if (ScanOpusTags(packet.packet, packet.bytes,
&rgi, &rgi,
add_tag_handler, &tag_builder) && add_tag_handler, &tag_builder) &&
!tag_builder.IsEmpty()) { !tag_builder.empty()) {
client.SubmitReplayGain(&rgi); client.SubmitReplayGain(&rgi);
Tag tag = tag_builder.Commit(); Tag tag = tag_builder.Commit();
......
...@@ -44,7 +44,7 @@ FillBuffer(DecoderClient &client, InputStream &is, B &buffer) ...@@ -44,7 +44,7 @@ FillBuffer(DecoderClient &client, InputStream &is, B &buffer)
{ {
buffer.Shift(); buffer.Shift();
auto w = buffer.Write(); auto w = buffer.Write();
if (w.IsEmpty()) if (w.empty())
return true; return true;
size_t nbytes = decoder_read(client, is, w.data, w.size); size_t nbytes = decoder_read(client, is, w.data, w.size);
...@@ -185,7 +185,7 @@ pcm_stream_decode(DecoderClient &client, InputStream &is) ...@@ -185,7 +185,7 @@ pcm_stream_decode(DecoderClient &client, InputStream &is)
r.size = (r.size / 3) * 4; r.size = (r.size / 3) * 4;
} }
cmd = !r.IsEmpty() cmd = !r.empty()
? client.SubmitData(is, r.data, r.size, 0) ? client.SubmitData(is, r.data, r.size, 0)
: client.GetCommand(); : client.GetCommand();
if (cmd == DecoderCommand::SEEK) { if (cmd == DecoderCommand::SEEK) {
......
...@@ -53,7 +53,7 @@ BufferedSocket::ReadToBuffer() ...@@ -53,7 +53,7 @@ BufferedSocket::ReadToBuffer()
assert(IsDefined()); assert(IsDefined());
const auto buffer = input.Write(); const auto buffer = input.Write();
assert(!buffer.IsEmpty()); assert(!buffer.empty());
const auto nbytes = DirectRead(buffer.data, buffer.size); const auto nbytes = DirectRead(buffer.data, buffer.size);
if (nbytes > 0) if (nbytes > 0)
...@@ -69,7 +69,7 @@ BufferedSocket::ResumeInput() ...@@ -69,7 +69,7 @@ BufferedSocket::ResumeInput()
while (true) { while (true) {
const auto buffer = input.Read(); const auto buffer = input.Read();
if (buffer.IsEmpty()) { if (buffer.empty()) {
ScheduleRead(); ScheduleRead();
return true; return true;
} }
......
...@@ -52,7 +52,7 @@ FullyBufferedSocket::Flush() ...@@ -52,7 +52,7 @@ FullyBufferedSocket::Flush()
assert(IsDefined()); assert(IsDefined());
const auto data = output.Read(); const auto data = output.Read();
if (data.IsEmpty()) { if (data.empty()) {
IdleMonitor::Cancel(); IdleMonitor::Cancel();
CancelWrite(); CancelWrite();
return true; return true;
...@@ -64,7 +64,7 @@ FullyBufferedSocket::Flush() ...@@ -64,7 +64,7 @@ FullyBufferedSocket::Flush()
output.Consume(nbytes); output.Consume(nbytes);
if (output.IsEmpty()) { if (output.empty()) {
IdleMonitor::Cancel(); IdleMonitor::Cancel();
CancelWrite(); CancelWrite();
} }
...@@ -80,7 +80,7 @@ FullyBufferedSocket::Write(const void *data, size_t length) ...@@ -80,7 +80,7 @@ FullyBufferedSocket::Write(const void *data, size_t length)
if (length == 0) if (length == 0)
return true; return true;
const bool was_empty = output.IsEmpty(); const bool was_empty = output.empty();
if (!output.Append(data, length)) { if (!output.Append(data, length)) {
OnSocketError(std::make_exception_ptr(std::runtime_error("Output buffer is full"))); OnSocketError(std::make_exception_ptr(std::runtime_error("Output buffer is full")));
...@@ -96,7 +96,7 @@ bool ...@@ -96,7 +96,7 @@ bool
FullyBufferedSocket::OnSocketReady(unsigned flags) FullyBufferedSocket::OnSocketReady(unsigned flags)
{ {
if (flags & WRITE) { if (flags & WRITE) {
assert(!output.IsEmpty()); assert(!output.empty());
assert(!IdleMonitor::IsActive()); assert(!IdleMonitor::IsActive());
if (!Flush()) if (!Flush())
...@@ -112,6 +112,6 @@ FullyBufferedSocket::OnSocketReady(unsigned flags) ...@@ -112,6 +112,6 @@ FullyBufferedSocket::OnSocketReady(unsigned flags)
void void
FullyBufferedSocket::OnIdle() FullyBufferedSocket::OnIdle()
{ {
if (Flush() && !output.IsEmpty()) if (Flush() && !output.empty())
ScheduleWrite(); ScheduleWrite();
} }
...@@ -70,7 +70,7 @@ void ...@@ -70,7 +70,7 @@ void
BufferedOutputStream::Format(const char *fmt, ...) BufferedOutputStream::Format(const char *fmt, ...)
{ {
auto r = buffer.Write(); auto r = buffer.Write();
if (r.IsEmpty()) { if (r.empty()) {
Flush(); Flush();
r = buffer.Write(); r = buffer.Write();
} }
...@@ -123,7 +123,7 @@ BufferedOutputStream::WriteWideToUTF8(const wchar_t *src, size_t src_length) ...@@ -123,7 +123,7 @@ BufferedOutputStream::WriteWideToUTF8(const wchar_t *src, size_t src_length)
return; return;
auto r = buffer.Write(); auto r = buffer.Write();
if (r.IsEmpty()) { if (r.empty()) {
Flush(); Flush();
r = buffer.Write(); r = buffer.Write();
} }
...@@ -158,7 +158,7 @@ void ...@@ -158,7 +158,7 @@ void
BufferedOutputStream::Flush() BufferedOutputStream::Flush()
{ {
auto r = buffer.Read(); auto r = buffer.Read();
if (r.IsEmpty()) if (r.empty())
return; return;
os.Write(r.data, r.size); os.Write(r.data, r.size);
......
...@@ -34,13 +34,13 @@ BufferedReader::Fill(bool need_more) ...@@ -34,13 +34,13 @@ BufferedReader::Fill(bool need_more)
return !need_more; return !need_more;
auto w = buffer.Write(); auto w = buffer.Write();
if (w.IsEmpty()) { if (w.empty()) {
if (buffer.GetCapacity() >= MAX_SIZE) if (buffer.GetCapacity() >= MAX_SIZE)
return !need_more; return !need_more;
buffer.Grow(buffer.GetCapacity() * 2); buffer.Grow(buffer.GetCapacity() * 2);
w = buffer.Write(); w = buffer.Write();
assert(!w.IsEmpty()); assert(!w.empty());
} }
size_t nbytes = reader.Read(w.data, w.size); size_t nbytes = reader.Read(w.data, w.size);
...@@ -104,14 +104,14 @@ BufferedReader::ReadLine() ...@@ -104,14 +104,14 @@ BufferedReader::ReadLine()
} }
} while (Fill(true)); } while (Fill(true));
if (!eof || buffer.IsEmpty()) if (!eof || buffer.empty())
return nullptr; return nullptr;
auto w = buffer.Write(); auto w = buffer.Write();
if (w.IsEmpty()) { if (w.empty()) {
buffer.Grow(buffer.GetCapacity() + 1); buffer.Grow(buffer.GetCapacity() + 1);
w = buffer.Write(); w = buffer.Write();
assert(!w.IsEmpty()); assert(!w.empty());
} }
/* terminate the last line */ /* terminate the last line */
......
...@@ -39,7 +39,7 @@ inline bool ...@@ -39,7 +39,7 @@ inline bool
GunzipReader::FillBuffer() GunzipReader::FillBuffer()
{ {
auto w = buffer.Write(); auto w = buffer.Write();
assert(!w.IsEmpty()); assert(!w.empty());
size_t nbytes = next.Read(w.data, w.size); size_t nbytes = next.Read(w.data, w.size);
if (nbytes == 0) if (nbytes == 0)
...@@ -62,7 +62,7 @@ GunzipReader::Read(void *data, size_t size) ...@@ -62,7 +62,7 @@ GunzipReader::Read(void *data, size_t size)
int flush = Z_NO_FLUSH; int flush = Z_NO_FLUSH;
auto r = buffer.Read(); auto r = buffer.Read();
if (r.IsEmpty()) { if (r.empty()) {
if (FillBuffer()) if (FillBuffer())
r = buffer.Read(); r = buffer.Read();
else else
......
...@@ -88,7 +88,7 @@ bool ...@@ -88,7 +88,7 @@ bool
AsyncInputStream::IsEOF() noexcept AsyncInputStream::IsEOF() noexcept
{ {
return (KnownSize() && offset >= size) || return (KnownSize() && offset >= size) ||
(!open && buffer.IsEmpty()); (!open && buffer.empty());
} }
void void
...@@ -108,7 +108,7 @@ AsyncInputStream::Seek(offset_type new_offset) ...@@ -108,7 +108,7 @@ AsyncInputStream::Seek(offset_type new_offset)
while (new_offset > offset) { while (new_offset > offset) {
auto r = buffer.Read(); auto r = buffer.Read();
if (r.IsEmpty()) if (r.empty())
break; break;
const size_t nbytes = const size_t nbytes =
...@@ -162,7 +162,7 @@ AsyncInputStream::IsAvailable() noexcept ...@@ -162,7 +162,7 @@ AsyncInputStream::IsAvailable() noexcept
{ {
return postponed_exception || return postponed_exception ||
IsEOF() || IsEOF() ||
!buffer.IsEmpty(); !buffer.empty();
} }
size_t size_t
...@@ -176,7 +176,7 @@ AsyncInputStream::Read(void *ptr, size_t read_size) ...@@ -176,7 +176,7 @@ AsyncInputStream::Read(void *ptr, size_t read_size)
Check(); Check();
r = buffer.Read(); r = buffer.Read();
if (!r.IsEmpty() || IsEOF()) if (!r.empty() || IsEOF())
break; break;
cond.wait(mutex); cond.wait(mutex);
...@@ -209,7 +209,7 @@ void ...@@ -209,7 +209,7 @@ void
AsyncInputStream::AppendToBuffer(const void *data, size_t append_size) noexcept AsyncInputStream::AppendToBuffer(const void *data, size_t append_size) noexcept
{ {
auto w = buffer.Write(); auto w = buffer.Write();
assert(!w.IsEmpty()); assert(!w.empty());
size_t nbytes = std::min(w.size, append_size); size_t nbytes = std::min(w.size, append_size);
memcpy(w.data, data, nbytes); memcpy(w.data, data, nbytes);
...@@ -218,7 +218,7 @@ AsyncInputStream::AppendToBuffer(const void *data, size_t append_size) noexcept ...@@ -218,7 +218,7 @@ AsyncInputStream::AppendToBuffer(const void *data, size_t append_size) noexcept
const size_t remaining = append_size - nbytes; const size_t remaining = append_size - nbytes;
if (remaining > 0) { if (remaining > 0) {
w = buffer.Write(); w = buffer.Write();
assert(!w.IsEmpty()); assert(!w.empty());
assert(w.size >= remaining); assert(w.size >= remaining);
memcpy(w.data, (const uint8_t *)data + nbytes, remaining); memcpy(w.data, (const uint8_t *)data + nbytes, remaining);
......
...@@ -114,7 +114,7 @@ protected: ...@@ -114,7 +114,7 @@ protected:
} }
bool IsBufferEmpty() const noexcept { bool IsBufferEmpty() const noexcept {
return buffer.IsEmpty(); return buffer.empty();
} }
bool IsBufferFull() const noexcept { bool IsBufferFull() const noexcept {
......
...@@ -47,7 +47,7 @@ TextInputStream::ReadLine() ...@@ -47,7 +47,7 @@ TextInputStream::ReadLine()
/* line too long: terminate the current /* line too long: terminate the current
line */ line */
assert(!dest.IsEmpty()); assert(!dest.empty());
dest[0] = 0; dest[0] = 0;
line = buffer.Read().data; line = buffer.Read().data;
buffer.Clear(); buffer.Clear();
...@@ -79,12 +79,12 @@ TextInputStream::ReadLine() ...@@ -79,12 +79,12 @@ TextInputStream::ReadLine()
line */ line */
dest = buffer.Write(); dest = buffer.Write();
assert(!dest.IsEmpty()); assert(!dest.empty());
dest[0] = 0; dest[0] = 0;
auto r = buffer.Read(); auto r = buffer.Read();
buffer.Clear(); buffer.Clear();
return r.IsEmpty() return r.empty()
? nullptr ? nullptr
: r.data; : r.data;
} }
......
...@@ -80,7 +80,7 @@ ThreadInputStream::ThreadFunc() ...@@ -80,7 +80,7 @@ ThreadInputStream::ThreadFunc()
assert(!postponed_exception); assert(!postponed_exception);
auto w = buffer.Write(); auto w = buffer.Write();
if (w.IsEmpty()) { if (w.empty()) {
wake_cond.wait(mutex); wake_cond.wait(mutex);
} else { } else {
size_t nbytes; size_t nbytes;
...@@ -122,7 +122,7 @@ ThreadInputStream::IsAvailable() noexcept ...@@ -122,7 +122,7 @@ ThreadInputStream::IsAvailable() noexcept
{ {
assert(!thread.IsInside()); assert(!thread.IsInside());
return !buffer.IsEmpty() || eof || postponed_exception; return !buffer.empty() || eof || postponed_exception;
} }
inline size_t inline size_t
...@@ -135,7 +135,7 @@ ThreadInputStream::Read(void *ptr, size_t read_size) ...@@ -135,7 +135,7 @@ ThreadInputStream::Read(void *ptr, size_t read_size)
std::rethrow_exception(postponed_exception); std::rethrow_exception(postponed_exception);
auto r = buffer.Read(); auto r = buffer.Read();
if (!r.IsEmpty()) { if (!r.empty()) {
size_t nbytes = std::min(read_size, r.size); size_t nbytes = std::min(read_size, r.size);
memcpy(ptr, r.data, nbytes); memcpy(ptr, r.data, nbytes);
buffer.Consume(nbytes); buffer.Consume(nbytes);
......
...@@ -71,7 +71,7 @@ vorbis_scan_comment(const char *comment, ...@@ -71,7 +71,7 @@ vorbis_scan_comment(const char *comment,
{ {
if (handler.pair != nullptr) { if (handler.pair != nullptr) {
const DivideString split(comment, '='); const DivideString split(comment, '=');
if (split.IsDefined() && !split.IsEmpty()) if (split.IsDefined() && !split.empty())
tag_handler_invoke_pair(handler, handler_ctx, tag_handler_invoke_pair(handler, handler_ctx,
split.GetFirst(), split.GetFirst(),
split.GetSecond()); split.GetSecond());
...@@ -104,7 +104,7 @@ vorbis_comments_to_tag(char **comments) ...@@ -104,7 +104,7 @@ vorbis_comments_to_tag(char **comments)
{ {
TagBuilder tag_builder; TagBuilder tag_builder;
vorbis_comments_scan(comments, add_tag_handler, &tag_builder); vorbis_comments_scan(comments, add_tag_handler, &tag_builder);
return tag_builder.IsEmpty() return tag_builder.empty()
? nullptr ? nullptr
: tag_builder.CommitNew(); : tag_builder.CommitNew();
} }
...@@ -138,7 +138,7 @@ AudioOutputSource::GetChunkData(const MusicChunk &chunk, ...@@ -138,7 +138,7 @@ AudioOutputSource::GetChunkData(const MusicChunk &chunk,
assert(data.size % in_audio_format.GetFrameSize() == 0); assert(data.size % in_audio_format.GetFrameSize() == 0);
if (!data.IsEmpty() && replay_gain_filter != nullptr) { if (!data.empty() && replay_gain_filter != nullptr) {
replay_gain_filter_set_mode(*replay_gain_filter, replay_gain_filter_set_mode(*replay_gain_filter,
replay_gain_mode); replay_gain_mode);
...@@ -161,7 +161,7 @@ AudioOutputSource::FilterChunk(const MusicChunk &chunk) ...@@ -161,7 +161,7 @@ AudioOutputSource::FilterChunk(const MusicChunk &chunk)
{ {
auto data = GetChunkData(chunk, replay_gain_filter_instance, auto data = GetChunkData(chunk, replay_gain_filter_instance,
&replay_gain_serial); &replay_gain_serial);
if (data.IsEmpty()) if (data.empty())
return data; return data;
/* cross-fade */ /* cross-fade */
...@@ -170,7 +170,7 @@ AudioOutputSource::FilterChunk(const MusicChunk &chunk) ...@@ -170,7 +170,7 @@ AudioOutputSource::FilterChunk(const MusicChunk &chunk)
auto other_data = GetChunkData(*chunk.other, auto other_data = GetChunkData(*chunk.other,
other_replay_gain_filter_instance, other_replay_gain_filter_instance,
&other_replay_gain_serial); &other_replay_gain_serial);
if (other_data.IsEmpty()) if (other_data.empty())
return data; return data;
/* if the "other" chunk is longer, then that trailer /* if the "other" chunk is longer, then that trailer
...@@ -211,7 +211,7 @@ bool ...@@ -211,7 +211,7 @@ bool
AudioOutputSource::Fill(Mutex &mutex) AudioOutputSource::Fill(Mutex &mutex)
{ {
if (current_chunk != nullptr && pending_tag == nullptr && if (current_chunk != nullptr && pending_tag == nullptr &&
pending_data.IsEmpty()) pending_data.empty())
pipe.Consume(*std::exchange(current_chunk, nullptr)); pipe.Consume(*std::exchange(current_chunk, nullptr));
if (current_chunk != nullptr) if (current_chunk != nullptr)
...@@ -242,6 +242,6 @@ AudioOutputSource::ConsumeData(size_t nbytes) noexcept ...@@ -242,6 +242,6 @@ AudioOutputSource::ConsumeData(size_t nbytes) noexcept
{ {
pending_data.skip_front(nbytes); pending_data.skip_front(nbytes);
if (pending_data.IsEmpty()) if (pending_data.empty())
pipe.Consume(*std::exchange(current_chunk, nullptr)); pipe.Consume(*std::exchange(current_chunk, nullptr));
} }
...@@ -259,7 +259,7 @@ AudioOutputControl::PlayChunk() noexcept ...@@ -259,7 +259,7 @@ AudioOutputControl::PlayChunk() noexcept
while (command == Command::NONE) { while (command == Command::NONE) {
const auto data = source.PeekData(); const auto data = source.PeekData();
if (data.IsEmpty()) if (data.empty())
break; break;
if (skip_delay) if (skip_delay)
......
...@@ -48,7 +48,7 @@ ConstBuffer<float> ...@@ -48,7 +48,7 @@ ConstBuffer<float>
PcmDsd::ToFloat(unsigned channels, ConstBuffer<uint8_t> src) PcmDsd::ToFloat(unsigned channels, ConstBuffer<uint8_t> src)
{ {
assert(!src.IsNull()); assert(!src.IsNull());
assert(!src.IsEmpty()); assert(!src.empty());
assert(src.size % channels == 0); assert(src.size % channels == 0);
assert(channels <= dsd2pcm.max_size()); assert(channels <= dsd2pcm.max_size());
......
...@@ -191,7 +191,7 @@ TagBuilder::Complement(const Tag &other) ...@@ -191,7 +191,7 @@ TagBuilder::Complement(const Tag &other)
inline void inline void
TagBuilder::AddItemInternal(TagType type, StringView value) TagBuilder::AddItemInternal(TagType type, StringView value)
{ {
assert(!value.IsEmpty()); assert(!value.empty());
auto f = FixTagString(value); auto f = FixTagString(value);
if (!f.IsNull()) if (!f.IsNull())
...@@ -209,7 +209,7 @@ TagBuilder::AddItemInternal(TagType type, StringView value) ...@@ -209,7 +209,7 @@ TagBuilder::AddItemInternal(TagType type, StringView value)
void void
TagBuilder::AddItem(TagType type, StringView value) TagBuilder::AddItem(TagType type, StringView value)
{ {
if (value.IsEmpty() || !IsTagEnabled(type)) if (value.empty() || !IsTagEnabled(type))
return; return;
AddItemInternal(type, value); AddItemInternal(type, value);
......
...@@ -74,7 +74,7 @@ public: ...@@ -74,7 +74,7 @@ public:
* Returns true if the tag contains no items. This ignores * Returns true if the tag contains no items. This ignores
* the "duration" attribute. * the "duration" attribute.
*/ */
bool IsEmpty() const { bool empty() const {
return items.empty(); return items.empty();
} }
...@@ -83,7 +83,7 @@ public: ...@@ -83,7 +83,7 @@ public:
*/ */
gcc_pure gcc_pure
bool IsDefined() const noexcept { bool IsDefined() const noexcept {
return !duration.IsNegative() || has_playlist || !IsEmpty(); return !duration.IsNegative() || has_playlist || !empty();
} }
void Clear(); void Clear();
......
...@@ -334,7 +334,7 @@ tag_id3_import(struct id3_tag *tag) ...@@ -334,7 +334,7 @@ tag_id3_import(struct id3_tag *tag)
{ {
TagBuilder tag_builder; TagBuilder tag_builder;
scan_id3_tag(tag, add_tag_handler, &tag_builder); scan_id3_tag(tag, add_tag_handler, &tag_builder);
return tag_builder.IsEmpty() return tag_builder.empty()
? nullptr ? nullptr
: tag_builder.CommitNew(); : tag_builder.CommitNew();
} }
......
...@@ -112,7 +112,7 @@ public: ...@@ -112,7 +112,7 @@ public:
* Returns true if no memory was allocated so far. * Returns true if no memory was allocated so far.
*/ */
constexpr bool empty() const { constexpr bool empty() const {
return buffer.IsEmpty(); return buffer.empty();
} }
/** /**
......
...@@ -90,7 +90,7 @@ public: ...@@ -90,7 +90,7 @@ public:
return capacity; return capacity;
} }
constexpr bool IsEmpty() const { constexpr bool empty() const {
return head == tail; return head == tail;
} }
......
...@@ -84,7 +84,7 @@ struct ConstBuffer<void> { ...@@ -84,7 +84,7 @@ struct ConstBuffer<void> {
return data != nullptr; return data != nullptr;
} }
constexpr bool IsEmpty() const { constexpr bool empty() const {
return size == 0; return size == 0;
} }
}; };
...@@ -167,7 +167,7 @@ struct ConstBuffer { ...@@ -167,7 +167,7 @@ struct ConstBuffer {
return data != nullptr; return data != nullptr;
} }
constexpr bool IsEmpty() const { constexpr bool empty() const {
return size == 0; return size == 0;
} }
...@@ -217,7 +217,7 @@ struct ConstBuffer { ...@@ -217,7 +217,7 @@ struct ConstBuffer {
#endif #endif
reference_type front() const { reference_type front() const {
#ifndef NDEBUG #ifndef NDEBUG
assert(!IsEmpty()); assert(!empty());
#endif #endif
return data[0]; return data[0];
} }
...@@ -231,7 +231,7 @@ struct ConstBuffer { ...@@ -231,7 +231,7 @@ struct ConstBuffer {
#endif #endif
reference_type back() const { reference_type back() const {
#ifndef NDEBUG #ifndef NDEBUG
assert(!IsEmpty()); assert(!empty());
#endif #endif
return data[size - 1]; return data[size - 1];
} }
...@@ -242,7 +242,7 @@ struct ConstBuffer { ...@@ -242,7 +242,7 @@ struct ConstBuffer {
*/ */
void pop_front() { void pop_front() {
#ifndef NDEBUG #ifndef NDEBUG
assert(!IsEmpty()); assert(!empty());
#endif #endif
++data; ++data;
...@@ -255,7 +255,7 @@ struct ConstBuffer { ...@@ -255,7 +255,7 @@ struct ConstBuffer {
*/ */
void pop_back() { void pop_back() {
#ifndef NDEBUG #ifndef NDEBUG
assert(!IsEmpty()); assert(!empty());
#endif #endif
--size; --size;
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
/** /**
* Is the first part empty? * Is the first part empty?
*/ */
bool IsEmpty() const { bool empty() const {
assert(IsDefined()); assert(IsDefined());
return *first == 0; return *first == 0;
......
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
using ForeignFifoBuffer<T>::GetCapacity; using ForeignFifoBuffer<T>::GetCapacity;
using ForeignFifoBuffer<T>::Clear; using ForeignFifoBuffer<T>::Clear;
using ForeignFifoBuffer<T>::IsEmpty; using ForeignFifoBuffer<T>::empty;
using ForeignFifoBuffer<T>::IsFull; using ForeignFifoBuffer<T>::IsFull;
using ForeignFifoBuffer<T>::GetAvailable; using ForeignFifoBuffer<T>::GetAvailable;
using ForeignFifoBuffer<T>::Read; using ForeignFifoBuffer<T>::Read;
......
...@@ -134,7 +134,7 @@ public: ...@@ -134,7 +134,7 @@ public:
head = tail = 0; head = tail = 0;
} }
constexpr bool IsEmpty() const { constexpr bool empty() const {
return head == tail; return head == tail;
} }
...@@ -147,7 +147,7 @@ public: ...@@ -147,7 +147,7 @@ public:
* When you are finished, call Append(). * When you are finished, call Append().
*/ */
Range Write() { Range Write() {
if (IsEmpty()) if (empty())
Clear(); Clear();
else if (tail == capacity) else if (tail == capacity)
Shift(); Shift();
......
...@@ -32,10 +32,10 @@ PeakBuffer::~PeakBuffer() ...@@ -32,10 +32,10 @@ PeakBuffer::~PeakBuffer()
} }
bool bool
PeakBuffer::IsEmpty() const noexcept PeakBuffer::empty() const noexcept
{ {
return (normal_buffer == nullptr || normal_buffer->IsEmpty()) && return (normal_buffer == nullptr || normal_buffer->empty()) &&
(peak_buffer == nullptr || peak_buffer->IsEmpty()); (peak_buffer == nullptr || peak_buffer->empty());
} }
WritableBuffer<void> WritableBuffer<void>
...@@ -43,13 +43,13 @@ PeakBuffer::Read() const noexcept ...@@ -43,13 +43,13 @@ PeakBuffer::Read() const noexcept
{ {
if (normal_buffer != nullptr) { if (normal_buffer != nullptr) {
const auto p = normal_buffer->Read(); const auto p = normal_buffer->Read();
if (!p.IsEmpty()) if (!p.empty())
return p.ToVoid(); return p.ToVoid();
} }
if (peak_buffer != nullptr) { if (peak_buffer != nullptr) {
const auto p = peak_buffer->Read(); const auto p = peak_buffer->Read();
if (!p.IsEmpty()) if (!p.empty())
return p.ToVoid(); return p.ToVoid();
} }
...@@ -59,14 +59,14 @@ PeakBuffer::Read() const noexcept ...@@ -59,14 +59,14 @@ PeakBuffer::Read() const noexcept
void void
PeakBuffer::Consume(size_t length) noexcept PeakBuffer::Consume(size_t length) noexcept
{ {
if (normal_buffer != nullptr && !normal_buffer->IsEmpty()) { if (normal_buffer != nullptr && !normal_buffer->empty()) {
normal_buffer->Consume(length); normal_buffer->Consume(length);
return; return;
} }
if (peak_buffer != nullptr && !peak_buffer->IsEmpty()) { if (peak_buffer != nullptr && !peak_buffer->empty()) {
peak_buffer->Consume(length); peak_buffer->Consume(length);
if (peak_buffer->IsEmpty()) { if (peak_buffer->empty()) {
delete peak_buffer; delete peak_buffer;
peak_buffer = nullptr; peak_buffer = nullptr;
} }
...@@ -86,7 +86,7 @@ AppendTo(DynamicFifoBuffer<uint8_t> &buffer, ...@@ -86,7 +86,7 @@ AppendTo(DynamicFifoBuffer<uint8_t> &buffer,
do { do {
const auto p = buffer.Write(); const auto p = buffer.Write();
if (p.IsEmpty()) if (p.empty())
break; break;
const size_t nbytes = std::min(length, p.size); const size_t nbytes = std::min(length, p.size);
...@@ -107,7 +107,7 @@ PeakBuffer::Append(const void *data, size_t length) ...@@ -107,7 +107,7 @@ PeakBuffer::Append(const void *data, size_t length)
if (length == 0) if (length == 0)
return true; return true;
if (peak_buffer != nullptr && !peak_buffer->IsEmpty()) { if (peak_buffer != nullptr && !peak_buffer->empty()) {
size_t nbytes = AppendTo(*peak_buffer, data, length); size_t nbytes = AppendTo(*peak_buffer, data, length);
return nbytes == length; return nbytes == length;
} }
......
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
PeakBuffer &operator=(const PeakBuffer &) = delete; PeakBuffer &operator=(const PeakBuffer &) = delete;
gcc_pure gcc_pure
bool IsEmpty() const noexcept; bool empty() const noexcept;
gcc_pure gcc_pure
WritableBuffer<void> Read() const noexcept; WritableBuffer<void> Read() const noexcept;
......
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
return buffer.size(); return buffer.size();
} }
bool IsEmpty() const { bool empty() const {
return n_allocated == 0; return n_allocated == 0;
} }
......
...@@ -78,7 +78,7 @@ public: ...@@ -78,7 +78,7 @@ public:
head = tail = 0; head = tail = 0;
} }
bool IsEmpty() const { bool empty() const {
return head == tail; return head == tail;
} }
...@@ -91,7 +91,7 @@ public: ...@@ -91,7 +91,7 @@ public:
* When you are finished, call Append(). * When you are finished, call Append().
*/ */
Range Write() { Range Write() {
if (IsEmpty()) if (empty())
Clear(); Clear();
else if (tail == size) else if (tail == size)
Shift(); Shift();
......
...@@ -34,7 +34,7 @@ template<typename T> ...@@ -34,7 +34,7 @@ template<typename T>
void void
BasicStringView<T>::StripLeft() noexcept BasicStringView<T>::StripLeft() noexcept
{ {
while (!IsEmpty() && IsWhitespaceOrNull(front())) while (!empty() && IsWhitespaceOrNull(front()))
pop_front(); pop_front();
} }
...@@ -42,7 +42,7 @@ template<typename T> ...@@ -42,7 +42,7 @@ template<typename T>
void void
BasicStringView<T>::StripRight() noexcept BasicStringView<T>::StripRight() noexcept
{ {
while (!IsEmpty() && IsWhitespaceOrNull(back())) while (!empty() && IsWhitespaceOrNull(back()))
pop_back(); pop_back();
} }
......
...@@ -58,7 +58,7 @@ struct BasicStringView : ConstBuffer<T> { ...@@ -58,7 +58,7 @@ struct BasicStringView : ConstBuffer<T> {
constexpr BasicStringView(std::nullptr_t n) noexcept constexpr BasicStringView(std::nullptr_t n) noexcept
:ConstBuffer<T>(n) {} :ConstBuffer<T>(n) {}
using ConstBuffer<T>::IsEmpty; using ConstBuffer<T>::empty;
using ConstBuffer<T>::front; using ConstBuffer<T>::front;
using ConstBuffer<T>::back; using ConstBuffer<T>::back;
using ConstBuffer<T>::pop_front; using ConstBuffer<T>::pop_front;
......
...@@ -41,7 +41,7 @@ gcc_pure ...@@ -41,7 +41,7 @@ gcc_pure
static bool static bool
IsValidScheme(StringView p) noexcept IsValidScheme(StringView p) noexcept
{ {
if (p.IsEmpty() || !IsValidSchemeStart(p.front())) if (p.empty() || !IsValidSchemeStart(p.front()))
return false; return false;
for (size_t i = 1; i < p.size; ++i) for (size_t i = 1; i < p.size; ++i)
......
...@@ -76,7 +76,7 @@ struct WritableBuffer<void> { ...@@ -76,7 +76,7 @@ struct WritableBuffer<void> {
return data != nullptr; return data != nullptr;
} }
constexpr bool IsEmpty() const { constexpr bool empty() const {
return size == 0; return size == 0;
} }
}; };
...@@ -161,7 +161,7 @@ struct WritableBuffer { ...@@ -161,7 +161,7 @@ struct WritableBuffer {
return data != nullptr; return data != nullptr;
} }
constexpr bool IsEmpty() const { constexpr bool empty() const {
return size == 0; return size == 0;
} }
...@@ -201,7 +201,7 @@ struct WritableBuffer { ...@@ -201,7 +201,7 @@ struct WritableBuffer {
#endif #endif
reference_type front() const { reference_type front() const {
#ifndef NDEBUG #ifndef NDEBUG
assert(!IsEmpty()); assert(!empty());
#endif #endif
return data[0]; return data[0];
} }
...@@ -215,7 +215,7 @@ struct WritableBuffer { ...@@ -215,7 +215,7 @@ struct WritableBuffer {
#endif #endif
reference_type back() const { reference_type back() const {
#ifndef NDEBUG #ifndef NDEBUG
assert(!IsEmpty()); assert(!empty());
#endif #endif
return data[size - 1]; return data[size - 1];
} }
...@@ -225,7 +225,7 @@ struct WritableBuffer { ...@@ -225,7 +225,7 @@ struct WritableBuffer {
* not actually modify the buffer). Buffer must not be empty. * not actually modify the buffer). Buffer must not be empty.
*/ */
void pop_front() { void pop_front() {
assert(!IsEmpty()); assert(!empty());
++data; ++data;
--size; --size;
...@@ -236,7 +236,7 @@ struct WritableBuffer { ...@@ -236,7 +236,7 @@ struct WritableBuffer {
* not actually modify the buffer). Buffer must not be empty. * not actually modify the buffer). Buffer must not be empty.
*/ */
void pop_back() { void pop_back() {
assert(!IsEmpty()); assert(!empty());
--size; --size;
} }
......
...@@ -23,7 +23,7 @@ public: ...@@ -23,7 +23,7 @@ public:
constexpr char input[] = "foo.bar"; constexpr char input[] = "foo.bar";
const DivideString ds(input, '.'); const DivideString ds(input, '.');
CPPUNIT_ASSERT(ds.IsDefined()); CPPUNIT_ASSERT(ds.IsDefined());
CPPUNIT_ASSERT(!ds.IsEmpty()); CPPUNIT_ASSERT(!ds.empty());
CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), "foo")); CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), "foo"));
CPPUNIT_ASSERT_EQUAL(input + 4, ds.GetSecond()); CPPUNIT_ASSERT_EQUAL(input + 4, ds.GetSecond());
} }
...@@ -32,7 +32,7 @@ public: ...@@ -32,7 +32,7 @@ public:
constexpr char input[] = ".bar"; constexpr char input[] = ".bar";
const DivideString ds(input, '.'); const DivideString ds(input, '.');
CPPUNIT_ASSERT(ds.IsDefined()); CPPUNIT_ASSERT(ds.IsDefined());
CPPUNIT_ASSERT(ds.IsEmpty()); CPPUNIT_ASSERT(ds.empty());
CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), "")); CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), ""));
CPPUNIT_ASSERT_EQUAL(input + 1, ds.GetSecond()); CPPUNIT_ASSERT_EQUAL(input + 1, ds.GetSecond());
} }
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
constexpr char input[] = " foo\t.\nbar\r"; constexpr char input[] = " foo\t.\nbar\r";
const DivideString ds(input, '.', true); const DivideString ds(input, '.', true);
CPPUNIT_ASSERT(ds.IsDefined()); CPPUNIT_ASSERT(ds.IsDefined());
CPPUNIT_ASSERT(!ds.IsEmpty()); CPPUNIT_ASSERT(!ds.empty());
CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), "foo")); CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), "foo"));
CPPUNIT_ASSERT_EQUAL(input + 7, ds.GetSecond()); CPPUNIT_ASSERT_EQUAL(input + 7, ds.GetSecond());
} }
......
...@@ -25,52 +25,52 @@ public: ...@@ -25,52 +25,52 @@ public:
/* checks on empty buffer */ /* checks on empty buffer */
/* [.......X] */ /* [.......X] */
CPPUNIT_ASSERT_EQUAL(true, buffer.IsEmpty()); CPPUNIT_ASSERT_EQUAL(true, buffer.empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull()); CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull());
CPPUNIT_ASSERT_EQUAL(size_t(0), buffer.GetSize()); CPPUNIT_ASSERT_EQUAL(size_t(0), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.GetSpace()); CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(true, buffer.Read().IsEmpty()); CPPUNIT_ASSERT_EQUAL(true, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.Write().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Write().empty());
CPPUNIT_ASSERT_EQUAL(&data[0], buffer.Write().data); CPPUNIT_ASSERT_EQUAL(&data[0], buffer.Write().data);
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.Write().size); CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.Write().size);
/* append one element */ /* append one element */
/* [O......X] */ /* [O......X] */
buffer.Append(1); buffer.Append(1);
CPPUNIT_ASSERT_EQUAL(false, buffer.IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull()); CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.GetSize()); CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.GetSpace()); CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.Read().size); CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.Read().size);
CPPUNIT_ASSERT_EQUAL(&data[0], buffer.Read().data); CPPUNIT_ASSERT_EQUAL(&data[0], buffer.Read().data);
CPPUNIT_ASSERT_EQUAL(false, buffer.Write().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Write().empty());
CPPUNIT_ASSERT_EQUAL(&data[1], buffer.Write().data); CPPUNIT_ASSERT_EQUAL(&data[1], buffer.Write().data);
CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.Write().size); CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.Write().size);
/* append 6 elements, buffer is now full */ /* append 6 elements, buffer is now full */
/* [OOOOOOOX] */ /* [OOOOOOOX] */
buffer.Append(6); buffer.Append(6);
CPPUNIT_ASSERT_EQUAL(false, buffer.IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.empty());
CPPUNIT_ASSERT_EQUAL(true, buffer.IsFull()); CPPUNIT_ASSERT_EQUAL(true, buffer.IsFull());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.GetSize()); CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(0), buffer.GetSpace()); CPPUNIT_ASSERT_EQUAL(size_t(0), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.Read().size); CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.Read().size);
CPPUNIT_ASSERT_EQUAL(&data[0], buffer.Read().data); CPPUNIT_ASSERT_EQUAL(&data[0], buffer.Read().data);
CPPUNIT_ASSERT_EQUAL(true, buffer.Write().IsEmpty()); CPPUNIT_ASSERT_EQUAL(true, buffer.Write().empty());
/* consume [0]; can append one at [7] */ /* consume [0]; can append one at [7] */
/* [XOOOOOO.] */ /* [XOOOOOO.] */
buffer.Consume(1); buffer.Consume(1);
CPPUNIT_ASSERT_EQUAL(false, buffer.IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull()); CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.GetSize()); CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.GetSpace()); CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.Read().size); CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.Read().size);
CPPUNIT_ASSERT_EQUAL(&data[1], buffer.Read().data); CPPUNIT_ASSERT_EQUAL(&data[1], buffer.Read().data);
CPPUNIT_ASSERT_EQUAL(false, buffer.Write().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Write().empty());
CPPUNIT_ASSERT_EQUAL(&data[7], buffer.Write().data); CPPUNIT_ASSERT_EQUAL(&data[7], buffer.Write().data);
CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.Write().size); CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.Write().size);
...@@ -78,66 +78,66 @@ public: ...@@ -78,66 +78,66 @@ public:
be written to because head==1 */ be written to because head==1 */
/* [XOOOOOOO] */ /* [XOOOOOOO] */
buffer.Append(1); buffer.Append(1);
CPPUNIT_ASSERT_EQUAL(false, buffer.IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.empty());
CPPUNIT_ASSERT_EQUAL(true, buffer.IsFull()); CPPUNIT_ASSERT_EQUAL(true, buffer.IsFull());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.GetSize()); CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(0), buffer.GetSpace()); CPPUNIT_ASSERT_EQUAL(size_t(0), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.Read().size); CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.Read().size);
CPPUNIT_ASSERT_EQUAL(&data[1], buffer.Read().data); CPPUNIT_ASSERT_EQUAL(&data[1], buffer.Read().data);
CPPUNIT_ASSERT_EQUAL(true, buffer.Write().IsEmpty()); CPPUNIT_ASSERT_EQUAL(true, buffer.Write().empty());
/* consume [1..3]; can append [0..2] */ /* consume [1..3]; can append [0..2] */
/* [...XOOOO] */ /* [...XOOOO] */
buffer.Consume(3); buffer.Consume(3);
CPPUNIT_ASSERT_EQUAL(false, buffer.IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull()); CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.GetSize()); CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(3), buffer.GetSpace()); CPPUNIT_ASSERT_EQUAL(size_t(3), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.Read().size); CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.Read().size);
CPPUNIT_ASSERT_EQUAL(&data[4], buffer.Read().data); CPPUNIT_ASSERT_EQUAL(&data[4], buffer.Read().data);
CPPUNIT_ASSERT_EQUAL(false, buffer.Write().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Write().empty());
CPPUNIT_ASSERT_EQUAL(&data[0], buffer.Write().data); CPPUNIT_ASSERT_EQUAL(&data[0], buffer.Write().data);
CPPUNIT_ASSERT_EQUAL(size_t(3), buffer.Write().size); CPPUNIT_ASSERT_EQUAL(size_t(3), buffer.Write().size);
/* append [0..1] */ /* append [0..1] */
/* [OO.XOOOO] */ /* [OO.XOOOO] */
buffer.Append(2); buffer.Append(2);
CPPUNIT_ASSERT_EQUAL(false, buffer.IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull()); CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.GetSize()); CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.GetSpace()); CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.Read().size); CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.Read().size);
CPPUNIT_ASSERT_EQUAL(&data[4], buffer.Read().data); CPPUNIT_ASSERT_EQUAL(&data[4], buffer.Read().data);
CPPUNIT_ASSERT_EQUAL(false, buffer.Write().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Write().empty());
CPPUNIT_ASSERT_EQUAL(&data[2], buffer.Write().data); CPPUNIT_ASSERT_EQUAL(&data[2], buffer.Write().data);
CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.Write().size); CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.Write().size);
/* append [2] */ /* append [2] */
/* [OOOXOOOO] */ /* [OOOXOOOO] */
buffer.Append(1); buffer.Append(1);
CPPUNIT_ASSERT_EQUAL(false, buffer.IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.empty());
CPPUNIT_ASSERT_EQUAL(true, buffer.IsFull()); CPPUNIT_ASSERT_EQUAL(true, buffer.IsFull());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.GetSize()); CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(0), buffer.GetSpace()); CPPUNIT_ASSERT_EQUAL(size_t(0), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.Read().size); CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.Read().size);
CPPUNIT_ASSERT_EQUAL(&data[4], buffer.Read().data); CPPUNIT_ASSERT_EQUAL(&data[4], buffer.Read().data);
CPPUNIT_ASSERT_EQUAL(true, buffer.Write().IsEmpty()); CPPUNIT_ASSERT_EQUAL(true, buffer.Write().empty());
/* consume [4..7] */ /* consume [4..7] */
/* [OOO....X] */ /* [OOO....X] */
buffer.Consume(4); buffer.Consume(4);
CPPUNIT_ASSERT_EQUAL(false, buffer.IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull()); CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(3), buffer.GetSize()); CPPUNIT_ASSERT_EQUAL(size_t(3), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.GetSpace()); CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(3), buffer.Read().size); CPPUNIT_ASSERT_EQUAL(size_t(3), buffer.Read().size);
CPPUNIT_ASSERT_EQUAL(&data[0], buffer.Read().data); CPPUNIT_ASSERT_EQUAL(&data[0], buffer.Read().data);
CPPUNIT_ASSERT_EQUAL(false, buffer.Write().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Write().empty());
CPPUNIT_ASSERT_EQUAL(&data[3], buffer.Write().data); CPPUNIT_ASSERT_EQUAL(&data[3], buffer.Write().data);
CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.Write().size); CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.Write().size);
...@@ -146,12 +146,12 @@ public: ...@@ -146,12 +146,12 @@ public:
special code to rewind/reset an empty buffer */ special code to rewind/reset an empty buffer */
/* [..X.....] */ /* [..X.....] */
buffer.Consume(3); buffer.Consume(3);
CPPUNIT_ASSERT_EQUAL(true, buffer.IsEmpty()); CPPUNIT_ASSERT_EQUAL(true, buffer.empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull()); CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull());
CPPUNIT_ASSERT_EQUAL(size_t(0), buffer.GetSize()); CPPUNIT_ASSERT_EQUAL(size_t(0), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.GetSpace()); CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(true, buffer.Read().IsEmpty()); CPPUNIT_ASSERT_EQUAL(true, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.Write().IsEmpty()); CPPUNIT_ASSERT_EQUAL(false, buffer.Write().empty());
CPPUNIT_ASSERT_EQUAL(&data[3], buffer.Write().data); CPPUNIT_ASSERT_EQUAL(&data[3], buffer.Write().data);
CPPUNIT_ASSERT_EQUAL(size_t(5), buffer.Write().size); CPPUNIT_ASSERT_EQUAL(size_t(5), buffer.Write().size);
} }
......
...@@ -62,7 +62,7 @@ try { ...@@ -62,7 +62,7 @@ try {
while (true) { while (true) {
{ {
const auto dest = buffer.Write(); const auto dest = buffer.Write();
assert(!dest.IsEmpty()); assert(!dest.empty());
ssize_t nbytes = read(0, dest.data, dest.size); ssize_t nbytes = read(0, dest.data, dest.size);
if (nbytes <= 0) if (nbytes <= 0)
...@@ -72,10 +72,10 @@ try { ...@@ -72,10 +72,10 @@ try {
} }
auto src = buffer.Read(); auto src = buffer.Read();
assert(!src.IsEmpty()); assert(!src.empty());
src.size -= src.size % in_frame_size; src.size -= src.size % in_frame_size;
if (src.IsEmpty()) if (src.empty())
continue; continue;
buffer.Consume(src.size); buffer.Consume(src.size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment