Tag: add class const_iterator and methods begin(), end()

Enables using range-based "for".
This commit is contained in:
Max Kellermann
2014-07-12 17:22:39 +02:00
parent 543a58bb87
commit 41a7203c28
13 changed files with 89 additions and 47 deletions

View File

@@ -374,20 +374,22 @@ RoarOutput::SendTag(const Tag &tag)
vals[0].key = const_cast<char *>("LENGTH");
vals[0].value = timebuf;
for (unsigned i = 0; i < tag.num_items && cnt < 32; i++)
{
for (const auto &item : tag) {
if (cnt >= 32)
break;
bool is_uuid = false;
const char *key = roar_tag_convert(tag.items[i]->type,
const char *key = roar_tag_convert(item.type,
&is_uuid);
if (key != nullptr) {
vals[cnt].key = const_cast<char *>(key);
if (is_uuid) {
snprintf(uuid_buf[cnt], sizeof(uuid_buf[0]), "{UUID}%s",
tag.items[i]->value);
item.value);
vals[cnt].value = uuid_buf[cnt];
} else {
vals[cnt].value = tag.items[i]->value;
vals[cnt].value = const_cast<char *>(item.value);
}
cnt++;

View File

@@ -470,13 +470,13 @@ shout_tag_to_metadata(const Tag *tag, char *dest, size_t size)
artist[0] = 0;
title[0] = 0;
for (unsigned i = 0; i < tag->num_items; i++) {
switch (tag->items[i]->type) {
for (const auto &item : *tag) {
switch (item.type) {
case TAG_ARTIST:
strncpy(artist, tag->items[i]->value, size);
strncpy(artist, item.value, size);
break;
case TAG_TITLE:
strncpy(title, tag->items[i]->value, size);
strncpy(title, item.value, size);
break;
default: