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

This commit is contained in:
Max Kellermann 2017-11-10 19:24:33 +01:00
parent 523051132d
commit 49784513b1
51 changed files with 142 additions and 142 deletions

View File

@ -50,7 +50,7 @@ public:
* object is inaccessible to other threads.
*/
bool IsEmptyUnsafe() const {
return buffer.IsEmpty();
return buffer.empty();
}
#endif

View File

@ -109,7 +109,7 @@ tag_file_scan(Path path, TagBuilder &builder)
if (!tag_file_scan(path, full_tag_handler, &builder))
return false;
if (builder.IsEmpty())
if (builder.empty())
ScanGenericTags(path, full_tag_handler, &builder);
return true;

View File

@ -94,7 +94,7 @@ tag_stream_scan(InputStream &is, TagBuilder &builder)
if (!tag_stream_scan(is, full_tag_handler, &builder))
return false;
if (builder.IsEmpty())
if (builder.empty())
ScanGenericTags(is, full_tag_handler, &builder);
return true;

View File

@ -58,7 +58,7 @@ handle_password(Client &client, Request args, Response &r)
static TagMask
ParseTagMask(Request request)
{
if (request.IsEmpty())
if (request.empty())
throw ProtocolError(ACK_ERROR_ARG, "Not enough arguments");
TagMask result = TagMask::None();
@ -77,14 +77,14 @@ ParseTagMask(Request request)
CommandResult
handle_tagtypes(Client &client, Request request, Response &r)
{
if (request.IsEmpty()) {
if (request.empty()) {
tag_print_types(r);
return CommandResult::OK;
}
const char *cmd = request.shift();
if (StringIsEqual(cmd, "all")) {
if (!request.IsEmpty()) {
if (!request.empty()) {
r.Error(ACK_ERROR_ARG, "Too many arguments");
return CommandResult::ERROR;
}
@ -92,7 +92,7 @@ handle_tagtypes(Client &client, Request request, Response &r)
client.tag_mask = TagMask::All();
return CommandResult::OK;
} else if (StringIsEqual(cmd, "clear")) {
if (!request.IsEmpty()) {
if (!request.empty()) {
r.Error(ACK_ERROR_ARG, "Too many arguments");
return CommandResult::ERROR;
}

View File

@ -169,7 +169,7 @@ handle_count(Client &client, Request args, Response &r)
}
SongFilter filter;
if (!args.IsEmpty() && !filter.Parse(args, false)) {
if (!args.empty() && !filter.Parse(args, false)) {
r.Error(ACK_ERROR_ARG, "incorrect arguments");
return CommandResult::ERROR;
}
@ -235,7 +235,7 @@ handle_list(Client &client, Request args, Response &r)
args.pop_back();
}
if (!args.IsEmpty()) {
if (!args.empty()) {
filter.reset(new SongFilter());
if (!filter->Parse(args, false)) {
r.Error(ACK_ERROR_ARG, "not able to parse args");

View File

@ -76,7 +76,7 @@ handle_unsubscribe(Client &client, Request args, Response &r)
CommandResult
handle_channels(Client &client, gcc_unused Request args, Response &r)
{
assert(args.IsEmpty());
assert(args.empty());
std::set<std::string> channels;
for (const auto &c : *client.GetInstance().client_list)
@ -93,7 +93,7 @@ CommandResult
handle_read_messages(Client &client,
gcc_unused Request args, Response &r)
{
assert(args.IsEmpty());
assert(args.empty());
while (!client.messages.empty()) {
const ClientMessage &msg = client.messages.front();

View File

@ -284,7 +284,7 @@ handle_update(Client &client, Request args, Response &r, bool discard)
const char *path = "";
assert(args.size <= 1);
if (!args.IsEmpty()) {
if (!args.empty()) {
path = args.front();
if (*path == 0 || StringIsEqual(path, "/"))

View File

@ -71,7 +71,7 @@ handle_toggleoutput(Client &client, Request args, Response &r)
CommandResult
handle_devices(Client &client, gcc_unused Request args, Response &r)
{
assert(args.IsEmpty());
assert(args.empty());
printAudioDevices(r, client.GetPartition().outputs);
return CommandResult::OK;

View File

@ -95,7 +95,7 @@ handle_pause(Client &client, Request args, gcc_unused Response &r)
{
auto &pc = client.GetPlayerControl();
if (!args.IsEmpty()) {
if (!args.empty()) {
bool pause_flag = args.ParseBool(0);
pc.LockSetPause(pause_flag);
} else

View File

@ -242,7 +242,7 @@ handle_playlistinfo(Client &client, Request args, Response &r)
CommandResult
handle_playlistid(Client &client, Request args, Response &r)
{
if (!args.IsEmpty()) {
if (!args.empty()) {
unsigned id = args.ParseUnsigned(0);
playlist_print_id(r, client.GetPlaylist(), id);
} else {

View File

@ -801,7 +801,7 @@ ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection,
TagBuilder tag;
tag.AddItem(tag_type, pair->value);
if (tag.IsEmpty())
if (tag.empty())
/* if no tag item has been added, then the
given value was not acceptable
(e.g. empty); forcefully insert an empty

View File

@ -496,7 +496,7 @@ DecoderBridge::SubmitData(InputStream *is,
SongTime::FromS(timestamp) -
dc.song->GetStartTime(),
kbit_rate);
if (dest.IsEmpty()) {
if (dest.empty()) {
/* the chunk is full, flush it */
FlushChunk();
continue;

View File

@ -25,7 +25,7 @@ bool
DecoderBuffer::Fill()
{
auto w = buffer.Write();
if (w.IsEmpty())
if (w.empty())
/* buffer is full */
return false;

View File

@ -127,7 +127,7 @@ adts_song_duration(DecoderBuffer &buffer)
if (frames == 0) {
auto data = ConstBuffer<uint8_t>::FromVoid(buffer.Read());
assert(!data.IsEmpty());
assert(!data.empty());
assert(frame_length <= data.size);
sample_rate = adts_sample_rates[(data.data[2] & 0x3c) >> 2];
@ -255,7 +255,7 @@ faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer &buffer,
AudioFormat &audio_format)
{
auto data = ConstBuffer<uint8_t>::FromVoid(buffer.Read());
if (data.IsEmpty())
if (data.empty())
throw std::runtime_error("Empty file");
uint8_t channels;
@ -283,7 +283,7 @@ faad_decoder_decode(NeAACDecHandle decoder, DecoderBuffer &buffer,
NeAACDecFrameInfo *frame_info)
{
auto data = ConstBuffer<uint8_t>::FromVoid(buffer.Read());
if (data.IsEmpty())
if (data.empty())
return nullptr;
return NeAACDecDecode(decoder, frame_info,

View File

@ -617,7 +617,7 @@ FfmpegCheckTag(DecoderClient &client, InputStream &is,
TagBuilder tag;
FfmpegScanTag(format_context, audio_stream, tag);
if (!tag.IsEmpty())
if (!tag.empty())
client.SubmitTag(is, tag.Commit());
}

View File

@ -97,7 +97,7 @@ flac_scan_comment(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
if (handler.pair != nullptr) {
const char *comment = (const char *)entry->entry;
const DivideString split(comment, '=');
if (split.IsDefined() && !split.IsEmpty())
if (split.IsDefined() && !split.empty())
tag_handler_invoke_pair(handler, handler_ctx,
split.GetFirst(),
split.GetSecond());

View File

@ -211,7 +211,7 @@ MPDOpusDecoder::HandleTags(const ogg_packet &packet)
if (ScanOpusTags(packet.packet, packet.bytes,
&rgi,
add_tag_handler, &tag_builder) &&
!tag_builder.IsEmpty()) {
!tag_builder.empty()) {
client.SubmitReplayGain(&rgi);
Tag tag = tag_builder.Commit();

View File

@ -44,7 +44,7 @@ FillBuffer(DecoderClient &client, InputStream &is, B &buffer)
{
buffer.Shift();
auto w = buffer.Write();
if (w.IsEmpty())
if (w.empty())
return true;
size_t nbytes = decoder_read(client, is, w.data, w.size);
@ -185,7 +185,7 @@ pcm_stream_decode(DecoderClient &client, InputStream &is)
r.size = (r.size / 3) * 4;
}
cmd = !r.IsEmpty()
cmd = !r.empty()
? client.SubmitData(is, r.data, r.size, 0)
: client.GetCommand();
if (cmd == DecoderCommand::SEEK) {

View File

@ -53,7 +53,7 @@ BufferedSocket::ReadToBuffer()
assert(IsDefined());
const auto buffer = input.Write();
assert(!buffer.IsEmpty());
assert(!buffer.empty());
const auto nbytes = DirectRead(buffer.data, buffer.size);
if (nbytes > 0)
@ -69,7 +69,7 @@ BufferedSocket::ResumeInput()
while (true) {
const auto buffer = input.Read();
if (buffer.IsEmpty()) {
if (buffer.empty()) {
ScheduleRead();
return true;
}

View File

@ -52,7 +52,7 @@ FullyBufferedSocket::Flush()
assert(IsDefined());
const auto data = output.Read();
if (data.IsEmpty()) {
if (data.empty()) {
IdleMonitor::Cancel();
CancelWrite();
return true;
@ -64,7 +64,7 @@ FullyBufferedSocket::Flush()
output.Consume(nbytes);
if (output.IsEmpty()) {
if (output.empty()) {
IdleMonitor::Cancel();
CancelWrite();
}
@ -80,7 +80,7 @@ FullyBufferedSocket::Write(const void *data, size_t length)
if (length == 0)
return true;
const bool was_empty = output.IsEmpty();
const bool was_empty = output.empty();
if (!output.Append(data, length)) {
OnSocketError(std::make_exception_ptr(std::runtime_error("Output buffer is full")));
@ -96,7 +96,7 @@ bool
FullyBufferedSocket::OnSocketReady(unsigned flags)
{
if (flags & WRITE) {
assert(!output.IsEmpty());
assert(!output.empty());
assert(!IdleMonitor::IsActive());
if (!Flush())
@ -112,6 +112,6 @@ FullyBufferedSocket::OnSocketReady(unsigned flags)
void
FullyBufferedSocket::OnIdle()
{
if (Flush() && !output.IsEmpty())
if (Flush() && !output.empty())
ScheduleWrite();
}

View File

@ -70,7 +70,7 @@ void
BufferedOutputStream::Format(const char *fmt, ...)
{
auto r = buffer.Write();
if (r.IsEmpty()) {
if (r.empty()) {
Flush();
r = buffer.Write();
}
@ -123,7 +123,7 @@ BufferedOutputStream::WriteWideToUTF8(const wchar_t *src, size_t src_length)
return;
auto r = buffer.Write();
if (r.IsEmpty()) {
if (r.empty()) {
Flush();
r = buffer.Write();
}
@ -158,7 +158,7 @@ void
BufferedOutputStream::Flush()
{
auto r = buffer.Read();
if (r.IsEmpty())
if (r.empty())
return;
os.Write(r.data, r.size);

View File

@ -34,13 +34,13 @@ BufferedReader::Fill(bool need_more)
return !need_more;
auto w = buffer.Write();
if (w.IsEmpty()) {
if (w.empty()) {
if (buffer.GetCapacity() >= MAX_SIZE)
return !need_more;
buffer.Grow(buffer.GetCapacity() * 2);
w = buffer.Write();
assert(!w.IsEmpty());
assert(!w.empty());
}
size_t nbytes = reader.Read(w.data, w.size);
@ -104,14 +104,14 @@ BufferedReader::ReadLine()
}
} while (Fill(true));
if (!eof || buffer.IsEmpty())
if (!eof || buffer.empty())
return nullptr;
auto w = buffer.Write();
if (w.IsEmpty()) {
if (w.empty()) {
buffer.Grow(buffer.GetCapacity() + 1);
w = buffer.Write();
assert(!w.IsEmpty());
assert(!w.empty());
}
/* terminate the last line */

View File

@ -39,7 +39,7 @@ inline bool
GunzipReader::FillBuffer()
{
auto w = buffer.Write();
assert(!w.IsEmpty());
assert(!w.empty());
size_t nbytes = next.Read(w.data, w.size);
if (nbytes == 0)
@ -62,7 +62,7 @@ GunzipReader::Read(void *data, size_t size)
int flush = Z_NO_FLUSH;
auto r = buffer.Read();
if (r.IsEmpty()) {
if (r.empty()) {
if (FillBuffer())
r = buffer.Read();
else

View File

@ -88,7 +88,7 @@ bool
AsyncInputStream::IsEOF() noexcept
{
return (KnownSize() && offset >= size) ||
(!open && buffer.IsEmpty());
(!open && buffer.empty());
}
void
@ -108,7 +108,7 @@ AsyncInputStream::Seek(offset_type new_offset)
while (new_offset > offset) {
auto r = buffer.Read();
if (r.IsEmpty())
if (r.empty())
break;
const size_t nbytes =
@ -162,7 +162,7 @@ AsyncInputStream::IsAvailable() noexcept
{
return postponed_exception ||
IsEOF() ||
!buffer.IsEmpty();
!buffer.empty();
}
size_t
@ -176,7 +176,7 @@ AsyncInputStream::Read(void *ptr, size_t read_size)
Check();
r = buffer.Read();
if (!r.IsEmpty() || IsEOF())
if (!r.empty() || IsEOF())
break;
cond.wait(mutex);
@ -209,7 +209,7 @@ void
AsyncInputStream::AppendToBuffer(const void *data, size_t append_size) noexcept
{
auto w = buffer.Write();
assert(!w.IsEmpty());
assert(!w.empty());
size_t nbytes = std::min(w.size, append_size);
memcpy(w.data, data, nbytes);
@ -218,7 +218,7 @@ AsyncInputStream::AppendToBuffer(const void *data, size_t append_size) noexcept
const size_t remaining = append_size - nbytes;
if (remaining > 0) {
w = buffer.Write();
assert(!w.IsEmpty());
assert(!w.empty());
assert(w.size >= remaining);
memcpy(w.data, (const uint8_t *)data + nbytes, remaining);

View File

@ -114,7 +114,7 @@ protected:
}
bool IsBufferEmpty() const noexcept {
return buffer.IsEmpty();
return buffer.empty();
}
bool IsBufferFull() const noexcept {

View File

@ -47,7 +47,7 @@ TextInputStream::ReadLine()
/* line too long: terminate the current
line */
assert(!dest.IsEmpty());
assert(!dest.empty());
dest[0] = 0;
line = buffer.Read().data;
buffer.Clear();
@ -79,12 +79,12 @@ TextInputStream::ReadLine()
line */
dest = buffer.Write();
assert(!dest.IsEmpty());
assert(!dest.empty());
dest[0] = 0;
auto r = buffer.Read();
buffer.Clear();
return r.IsEmpty()
return r.empty()
? nullptr
: r.data;
}

View File

@ -80,7 +80,7 @@ ThreadInputStream::ThreadFunc()
assert(!postponed_exception);
auto w = buffer.Write();
if (w.IsEmpty()) {
if (w.empty()) {
wake_cond.wait(mutex);
} else {
size_t nbytes;
@ -122,7 +122,7 @@ ThreadInputStream::IsAvailable() noexcept
{
assert(!thread.IsInside());
return !buffer.IsEmpty() || eof || postponed_exception;
return !buffer.empty() || eof || postponed_exception;
}
inline size_t
@ -135,7 +135,7 @@ ThreadInputStream::Read(void *ptr, size_t read_size)
std::rethrow_exception(postponed_exception);
auto r = buffer.Read();
if (!r.IsEmpty()) {
if (!r.empty()) {
size_t nbytes = std::min(read_size, r.size);
memcpy(ptr, r.data, nbytes);
buffer.Consume(nbytes);

View File

@ -71,7 +71,7 @@ vorbis_scan_comment(const char *comment,
{
if (handler.pair != nullptr) {
const DivideString split(comment, '=');
if (split.IsDefined() && !split.IsEmpty())
if (split.IsDefined() && !split.empty())
tag_handler_invoke_pair(handler, handler_ctx,
split.GetFirst(),
split.GetSecond());
@ -104,7 +104,7 @@ vorbis_comments_to_tag(char **comments)
{
TagBuilder tag_builder;
vorbis_comments_scan(comments, add_tag_handler, &tag_builder);
return tag_builder.IsEmpty()
return tag_builder.empty()
? nullptr
: tag_builder.CommitNew();
}

View File

@ -138,7 +138,7 @@ AudioOutputSource::GetChunkData(const MusicChunk &chunk,
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_mode);
@ -161,7 +161,7 @@ AudioOutputSource::FilterChunk(const MusicChunk &chunk)
{
auto data = GetChunkData(chunk, replay_gain_filter_instance,
&replay_gain_serial);
if (data.IsEmpty())
if (data.empty())
return data;
/* cross-fade */
@ -170,7 +170,7 @@ AudioOutputSource::FilterChunk(const MusicChunk &chunk)
auto other_data = GetChunkData(*chunk.other,
other_replay_gain_filter_instance,
&other_replay_gain_serial);
if (other_data.IsEmpty())
if (other_data.empty())
return data;
/* if the "other" chunk is longer, then that trailer
@ -211,7 +211,7 @@ bool
AudioOutputSource::Fill(Mutex &mutex)
{
if (current_chunk != nullptr && pending_tag == nullptr &&
pending_data.IsEmpty())
pending_data.empty())
pipe.Consume(*std::exchange(current_chunk, nullptr));
if (current_chunk != nullptr)
@ -242,6 +242,6 @@ AudioOutputSource::ConsumeData(size_t nbytes) noexcept
{
pending_data.skip_front(nbytes);
if (pending_data.IsEmpty())
if (pending_data.empty())
pipe.Consume(*std::exchange(current_chunk, nullptr));
}

View File

@ -259,7 +259,7 @@ AudioOutputControl::PlayChunk() noexcept
while (command == Command::NONE) {
const auto data = source.PeekData();
if (data.IsEmpty())
if (data.empty())
break;
if (skip_delay)

View File

@ -48,7 +48,7 @@ ConstBuffer<float>
PcmDsd::ToFloat(unsigned channels, ConstBuffer<uint8_t> src)
{
assert(!src.IsNull());
assert(!src.IsEmpty());
assert(!src.empty());
assert(src.size % channels == 0);
assert(channels <= dsd2pcm.max_size());

View File

@ -191,7 +191,7 @@ TagBuilder::Complement(const Tag &other)
inline void
TagBuilder::AddItemInternal(TagType type, StringView value)
{
assert(!value.IsEmpty());
assert(!value.empty());
auto f = FixTagString(value);
if (!f.IsNull())
@ -209,7 +209,7 @@ TagBuilder::AddItemInternal(TagType type, StringView value)
void
TagBuilder::AddItem(TagType type, StringView value)
{
if (value.IsEmpty() || !IsTagEnabled(type))
if (value.empty() || !IsTagEnabled(type))
return;
AddItemInternal(type, value);

View File

@ -74,7 +74,7 @@ public:
* Returns true if the tag contains no items. This ignores
* the "duration" attribute.
*/
bool IsEmpty() const {
bool empty() const {
return items.empty();
}
@ -83,7 +83,7 @@ public:
*/
gcc_pure
bool IsDefined() const noexcept {
return !duration.IsNegative() || has_playlist || !IsEmpty();
return !duration.IsNegative() || has_playlist || !empty();
}
void Clear();

View File

@ -334,7 +334,7 @@ tag_id3_import(struct id3_tag *tag)
{
TagBuilder tag_builder;
scan_id3_tag(tag, add_tag_handler, &tag_builder);
return tag_builder.IsEmpty()
return tag_builder.empty()
? nullptr
: tag_builder.CommitNew();
}

View File

@ -112,7 +112,7 @@ public:
* Returns true if no memory was allocated so far.
*/
constexpr bool empty() const {
return buffer.IsEmpty();
return buffer.empty();
}
/**

View File

@ -90,7 +90,7 @@ public:
return capacity;
}
constexpr bool IsEmpty() const {
constexpr bool empty() const {
return head == tail;
}

View File

@ -84,7 +84,7 @@ struct ConstBuffer<void> {
return data != nullptr;
}
constexpr bool IsEmpty() const {
constexpr bool empty() const {
return size == 0;
}
};
@ -167,7 +167,7 @@ struct ConstBuffer {
return data != nullptr;
}
constexpr bool IsEmpty() const {
constexpr bool empty() const {
return size == 0;
}
@ -217,7 +217,7 @@ struct ConstBuffer {
#endif
reference_type front() const {
#ifndef NDEBUG
assert(!IsEmpty());
assert(!empty());
#endif
return data[0];
}
@ -231,7 +231,7 @@ struct ConstBuffer {
#endif
reference_type back() const {
#ifndef NDEBUG
assert(!IsEmpty());
assert(!empty());
#endif
return data[size - 1];
}
@ -242,7 +242,7 @@ struct ConstBuffer {
*/
void pop_front() {
#ifndef NDEBUG
assert(!IsEmpty());
assert(!empty());
#endif
++data;
@ -255,7 +255,7 @@ struct ConstBuffer {
*/
void pop_back() {
#ifndef NDEBUG
assert(!IsEmpty());
assert(!empty());
#endif
--size;

View File

@ -53,7 +53,7 @@ public:
/**
* Is the first part empty?
*/
bool IsEmpty() const {
bool empty() const {
assert(IsDefined());
return *first == 0;

View File

@ -55,7 +55,7 @@ public:
using ForeignFifoBuffer<T>::GetCapacity;
using ForeignFifoBuffer<T>::Clear;
using ForeignFifoBuffer<T>::IsEmpty;
using ForeignFifoBuffer<T>::empty;
using ForeignFifoBuffer<T>::IsFull;
using ForeignFifoBuffer<T>::GetAvailable;
using ForeignFifoBuffer<T>::Read;

View File

@ -134,7 +134,7 @@ public:
head = tail = 0;
}
constexpr bool IsEmpty() const {
constexpr bool empty() const {
return head == tail;
}
@ -147,7 +147,7 @@ public:
* When you are finished, call Append().
*/
Range Write() {
if (IsEmpty())
if (empty())
Clear();
else if (tail == capacity)
Shift();

View File

@ -32,10 +32,10 @@ PeakBuffer::~PeakBuffer()
}
bool
PeakBuffer::IsEmpty() const noexcept
PeakBuffer::empty() const noexcept
{
return (normal_buffer == nullptr || normal_buffer->IsEmpty()) &&
(peak_buffer == nullptr || peak_buffer->IsEmpty());
return (normal_buffer == nullptr || normal_buffer->empty()) &&
(peak_buffer == nullptr || peak_buffer->empty());
}
WritableBuffer<void>
@ -43,13 +43,13 @@ PeakBuffer::Read() const noexcept
{
if (normal_buffer != nullptr) {
const auto p = normal_buffer->Read();
if (!p.IsEmpty())
if (!p.empty())
return p.ToVoid();
}
if (peak_buffer != nullptr) {
const auto p = peak_buffer->Read();
if (!p.IsEmpty())
if (!p.empty())
return p.ToVoid();
}
@ -59,14 +59,14 @@ PeakBuffer::Read() const noexcept
void
PeakBuffer::Consume(size_t length) noexcept
{
if (normal_buffer != nullptr && !normal_buffer->IsEmpty()) {
if (normal_buffer != nullptr && !normal_buffer->empty()) {
normal_buffer->Consume(length);
return;
}
if (peak_buffer != nullptr && !peak_buffer->IsEmpty()) {
if (peak_buffer != nullptr && !peak_buffer->empty()) {
peak_buffer->Consume(length);
if (peak_buffer->IsEmpty()) {
if (peak_buffer->empty()) {
delete peak_buffer;
peak_buffer = nullptr;
}
@ -86,7 +86,7 @@ AppendTo(DynamicFifoBuffer<uint8_t> &buffer,
do {
const auto p = buffer.Write();
if (p.IsEmpty())
if (p.empty())
break;
const size_t nbytes = std::min(length, p.size);
@ -107,7 +107,7 @@ PeakBuffer::Append(const void *data, size_t length)
if (length == 0)
return true;
if (peak_buffer != nullptr && !peak_buffer->IsEmpty()) {
if (peak_buffer != nullptr && !peak_buffer->empty()) {
size_t nbytes = AppendTo(*peak_buffer, data, length);
return nbytes == length;
}

View File

@ -57,7 +57,7 @@ public:
PeakBuffer &operator=(const PeakBuffer &) = delete;
gcc_pure
bool IsEmpty() const noexcept;
bool empty() const noexcept;
gcc_pure
WritableBuffer<void> Read() const noexcept;

View File

@ -79,7 +79,7 @@ public:
return buffer.size();
}
bool IsEmpty() const {
bool empty() const {
return n_allocated == 0;
}

View File

@ -78,7 +78,7 @@ public:
head = tail = 0;
}
bool IsEmpty() const {
bool empty() const {
return head == tail;
}
@ -91,7 +91,7 @@ public:
* When you are finished, call Append().
*/
Range Write() {
if (IsEmpty())
if (empty())
Clear();
else if (tail == size)
Shift();

View File

@ -34,7 +34,7 @@ template<typename T>
void
BasicStringView<T>::StripLeft() noexcept
{
while (!IsEmpty() && IsWhitespaceOrNull(front()))
while (!empty() && IsWhitespaceOrNull(front()))
pop_front();
}
@ -42,7 +42,7 @@ template<typename T>
void
BasicStringView<T>::StripRight() noexcept
{
while (!IsEmpty() && IsWhitespaceOrNull(back()))
while (!empty() && IsWhitespaceOrNull(back()))
pop_back();
}

View File

@ -58,7 +58,7 @@ struct BasicStringView : ConstBuffer<T> {
constexpr BasicStringView(std::nullptr_t n) noexcept
:ConstBuffer<T>(n) {}
using ConstBuffer<T>::IsEmpty;
using ConstBuffer<T>::empty;
using ConstBuffer<T>::front;
using ConstBuffer<T>::back;
using ConstBuffer<T>::pop_front;

View File

@ -41,7 +41,7 @@ gcc_pure
static bool
IsValidScheme(StringView p) noexcept
{
if (p.IsEmpty() || !IsValidSchemeStart(p.front()))
if (p.empty() || !IsValidSchemeStart(p.front()))
return false;
for (size_t i = 1; i < p.size; ++i)

View File

@ -76,7 +76,7 @@ struct WritableBuffer<void> {
return data != nullptr;
}
constexpr bool IsEmpty() const {
constexpr bool empty() const {
return size == 0;
}
};
@ -161,7 +161,7 @@ struct WritableBuffer {
return data != nullptr;
}
constexpr bool IsEmpty() const {
constexpr bool empty() const {
return size == 0;
}
@ -201,7 +201,7 @@ struct WritableBuffer {
#endif
reference_type front() const {
#ifndef NDEBUG
assert(!IsEmpty());
assert(!empty());
#endif
return data[0];
}
@ -215,7 +215,7 @@ struct WritableBuffer {
#endif
reference_type back() const {
#ifndef NDEBUG
assert(!IsEmpty());
assert(!empty());
#endif
return data[size - 1];
}
@ -225,7 +225,7 @@ struct WritableBuffer {
* not actually modify the buffer). Buffer must not be empty.
*/
void pop_front() {
assert(!IsEmpty());
assert(!empty());
++data;
--size;
@ -236,7 +236,7 @@ struct WritableBuffer {
* not actually modify the buffer). Buffer must not be empty.
*/
void pop_back() {
assert(!IsEmpty());
assert(!empty());
--size;
}

View File

@ -23,7 +23,7 @@ public:
constexpr char input[] = "foo.bar";
const DivideString ds(input, '.');
CPPUNIT_ASSERT(ds.IsDefined());
CPPUNIT_ASSERT(!ds.IsEmpty());
CPPUNIT_ASSERT(!ds.empty());
CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), "foo"));
CPPUNIT_ASSERT_EQUAL(input + 4, ds.GetSecond());
}
@ -32,7 +32,7 @@ public:
constexpr char input[] = ".bar";
const DivideString ds(input, '.');
CPPUNIT_ASSERT(ds.IsDefined());
CPPUNIT_ASSERT(ds.IsEmpty());
CPPUNIT_ASSERT(ds.empty());
CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), ""));
CPPUNIT_ASSERT_EQUAL(input + 1, ds.GetSecond());
}
@ -47,7 +47,7 @@ public:
constexpr char input[] = " foo\t.\nbar\r";
const DivideString ds(input, '.', true);
CPPUNIT_ASSERT(ds.IsDefined());
CPPUNIT_ASSERT(!ds.IsEmpty());
CPPUNIT_ASSERT(!ds.empty());
CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), "foo"));
CPPUNIT_ASSERT_EQUAL(input + 7, ds.GetSecond());
}

View File

@ -25,52 +25,52 @@ public:
/* checks on empty buffer */
/* [.......X] */
CPPUNIT_ASSERT_EQUAL(true, buffer.IsEmpty());
CPPUNIT_ASSERT_EQUAL(true, buffer.empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull());
CPPUNIT_ASSERT_EQUAL(size_t(0), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(true, buffer.Read().IsEmpty());
CPPUNIT_ASSERT_EQUAL(false, buffer.Write().IsEmpty());
CPPUNIT_ASSERT_EQUAL(true, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.Write().empty());
CPPUNIT_ASSERT_EQUAL(&data[0], buffer.Write().data);
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.Write().size);
/* append one element */
/* [O......X] */
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.Read().IsEmpty());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.Read().size);
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(size_t(6), buffer.Write().size);
/* append 6 elements, buffer is now full */
/* [OOOOOOOX] */
buffer.Append(6);
CPPUNIT_ASSERT_EQUAL(false, buffer.IsEmpty());
CPPUNIT_ASSERT_EQUAL(false, buffer.empty());
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(0), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.Read().size);
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] */
/* [XOOOOOO.] */
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.Read().IsEmpty());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.Read().size);
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(size_t(1), buffer.Write().size);
@ -78,66 +78,66 @@ public:
be written to because head==1 */
/* [XOOOOOOO] */
buffer.Append(1);
CPPUNIT_ASSERT_EQUAL(false, buffer.IsEmpty());
CPPUNIT_ASSERT_EQUAL(false, buffer.empty());
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(0), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.Read().size);
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] */
/* [...XOOOO] */
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.Read().IsEmpty());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(3), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.Read().size);
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(size_t(3), buffer.Write().size);
/* append [0..1] */
/* [OO.XOOOO] */
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.Read().IsEmpty());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(6), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(1), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.Read().size);
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(size_t(1), buffer.Write().size);
/* append [2] */
/* [OOOXOOOO] */
buffer.Append(1);
CPPUNIT_ASSERT_EQUAL(false, buffer.IsEmpty());
CPPUNIT_ASSERT_EQUAL(false, buffer.empty());
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(0), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.Read().size);
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] */
/* [OOO....X] */
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.Read().IsEmpty());
CPPUNIT_ASSERT_EQUAL(false, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(size_t(3), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(4), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(size_t(3), buffer.Read().size);
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(size_t(4), buffer.Write().size);
@ -146,12 +146,12 @@ public:
special code to rewind/reset an empty buffer */
/* [..X.....] */
buffer.Consume(3);
CPPUNIT_ASSERT_EQUAL(true, buffer.IsEmpty());
CPPUNIT_ASSERT_EQUAL(true, buffer.empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.IsFull());
CPPUNIT_ASSERT_EQUAL(size_t(0), buffer.GetSize());
CPPUNIT_ASSERT_EQUAL(size_t(7), buffer.GetSpace());
CPPUNIT_ASSERT_EQUAL(true, buffer.Read().IsEmpty());
CPPUNIT_ASSERT_EQUAL(false, buffer.Write().IsEmpty());
CPPUNIT_ASSERT_EQUAL(true, buffer.Read().empty());
CPPUNIT_ASSERT_EQUAL(false, buffer.Write().empty());
CPPUNIT_ASSERT_EQUAL(&data[3], buffer.Write().data);
CPPUNIT_ASSERT_EQUAL(size_t(5), buffer.Write().size);
}

View File

@ -62,7 +62,7 @@ try {
while (true) {
{
const auto dest = buffer.Write();
assert(!dest.IsEmpty());
assert(!dest.empty());
ssize_t nbytes = read(0, dest.data, dest.size);
if (nbytes <= 0)
@ -72,10 +72,10 @@ try {
}
auto src = buffer.Read();
assert(!src.IsEmpty());
assert(!src.empty());
src.size -= src.size % in_frame_size;
if (src.IsEmpty())
if (src.empty())
continue;
buffer.Consume(src.size);