aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-03 12:00:03 +0100
committerMax Kellermann <max@duempel.org>2013-12-03 12:09:21 +0100
commitef68946e74d29f69ede42fa7b6d571a5ed62ebc7 (patch)
treec8f87ccc1fe2dfe8a9c438f645d06d1914725f41 /src
parenta5574f9189f67e673463cde3d4aa629e638cf298 (diff)
downloadmpd-ef68946e74d29f69ede42fa7b6d571a5ed62ebc7.tar.gz
mpd-ef68946e74d29f69ede42fa7b6d571a5ed62ebc7.tar.xz
mpd-ef68946e74d29f69ede42fa7b6d571a5ed62ebc7.zip
CueParser: use class TagBuilder
Diffstat (limited to 'src')
-rw-r--r--src/cue/CueParser.cxx31
-rw-r--r--src/cue/CueParser.hxx12
2 files changed, 27 insertions, 16 deletions
diff --git a/src/cue/CueParser.cxx b/src/cue/CueParser.cxx
index 29c264cb5..7a226c849 100644
--- a/src/cue/CueParser.cxx
+++ b/src/cue/CueParser.cxx
@@ -31,7 +31,7 @@
#include <stdlib.h>
CueParser::CueParser()
- :state(HEADER), header_tag(new Tag()),
+ :state(HEADER),
current(nullptr),
previous(nullptr),
finished(nullptr),
@@ -39,8 +39,6 @@ CueParser::CueParser()
CueParser::~CueParser()
{
- delete header_tag;
-
if (current != nullptr)
current->Free();
@@ -109,7 +107,7 @@ cue_next_value(char **pp)
}
static void
-cue_add_tag(Tag &tag, TagType type, char *p)
+cue_add_tag(TagBuilder &tag, TagType type, char *p)
{
const char *value = cue_next_value(&p);
if (value != nullptr)
@@ -118,7 +116,7 @@ cue_add_tag(Tag &tag, TagType type, char *p)
}
static void
-cue_parse_rem(char *p, Tag &tag)
+cue_parse_rem(char *p, TagBuilder &tag)
{
const char *type = cue_next_token(&p);
if (type == nullptr)
@@ -129,13 +127,13 @@ cue_parse_rem(char *p, Tag &tag)
cue_add_tag(tag, type2, p);
}
-Tag *
+TagBuilder *
CueParser::GetCurrentTag()
{
if (state == HEADER)
- return header_tag;
+ return &header_tag;
else if (state == TRACK)
- return current->tag;
+ return &song_tag;
else
return nullptr;
}
@@ -172,6 +170,9 @@ CueParser::Commit()
if (current == nullptr)
return;
+ assert(current->tag == nullptr);
+ current->tag = song_tag.Commit();
+
finished = previous;
previous = current;
current = nullptr;
@@ -188,7 +189,7 @@ CueParser::Feed2(char *p)
return;
if (strcmp(command, "REM") == 0) {
- Tag *tag = GetCurrentTag();
+ TagBuilder *tag = GetCurrentTag();
if (tag != nullptr)
cue_parse_rem(p, *tag);
} else if (strcmp(command, "PERFORMER") == 0) {
@@ -202,14 +203,14 @@ CueParser::Feed2(char *p)
? TAG_ARTIST
: TAG_ALBUM_ARTIST;
- Tag *tag = GetCurrentTag();
+ TagBuilder *tag = GetCurrentTag();
if (tag != nullptr)
cue_add_tag(*tag, type, p);
} else if (strcmp(command, "TITLE") == 0) {
if (state == HEADER)
- cue_add_tag(*header_tag, TAG_ALBUM, p);
+ cue_add_tag(header_tag, TAG_ALBUM, p);
else if (state == TRACK)
- cue_add_tag(*current->tag, TAG_TITLE, p);
+ cue_add_tag(song_tag, TAG_TITLE, p);
} else if (strcmp(command, "FILE") == 0) {
Commit();
@@ -251,8 +252,10 @@ CueParser::Feed2(char *p)
state = TRACK;
current = Song::NewRemote(filename.c_str());
assert(current->tag == nullptr);
- current->tag = new Tag(*header_tag);
- current->tag->AddItem(TAG_TRACK, nr);
+
+ song_tag = header_tag;
+ song_tag.AddItem(TAG_TRACK, nr);
+
last_updated = false;
} else if (state == IGNORE_TRACK) {
return;
diff --git a/src/cue/CueParser.hxx b/src/cue/CueParser.hxx
index ea25d33cb..bcc759c37 100644
--- a/src/cue/CueParser.hxx
+++ b/src/cue/CueParser.hxx
@@ -21,6 +21,7 @@
#define MPD_CUE_PARSER_HXX
#include "check.h"
+#include "tag/TagBuilder.hxx"
#include "Compiler.h"
#include <string>
@@ -59,7 +60,14 @@ class CueParser {
/**
* Tags read from the CUE header.
*/
- Tag *header_tag;
+ TagBuilder header_tag;
+
+ /**
+ * Tags read for the current song (attribute #current). When
+ * #current gets moved to #previous, TagBuilder::Commit() will
+ * be called.
+ */
+ TagBuilder song_tag;
std::string filename;
@@ -121,7 +129,7 @@ public:
private:
gcc_pure
- Tag *GetCurrentTag();
+ TagBuilder *GetCurrentTag();
/**
* Commit the current song. It will be moved to "previous",