playlist/cue/CueParser: use std::unique_ptr

This commit is contained in:
Max Kellermann 2016-02-07 08:30:16 +01:00
parent ac9a93261b
commit 5869a4ba2d
2 changed files with 12 additions and 22 deletions

View File

@ -22,20 +22,12 @@
#include "util/Alloc.hxx" #include "util/Alloc.hxx"
#include "util/StringUtil.hxx" #include "util/StringUtil.hxx"
#include "util/CharUtil.hxx" #include "util/CharUtil.hxx"
#include "DetachedSong.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
CueParser::~CueParser()
{
delete current;
delete previous;
delete finished;
}
static const char * static const char *
cue_next_word(char *p, char **pp) cue_next_word(char *p, char **pp)
{ {
@ -160,9 +152,9 @@ CueParser::Commit()
assert(!current->GetTag().IsDefined()); assert(!current->GetTag().IsDefined());
current->SetTag(song_tag.Commit()); current->SetTag(song_tag.Commit());
finished = previous; finished = std::move(previous);
previous = current; previous = std::move(current);
current = nullptr; current.reset();
} }
void void
@ -237,7 +229,7 @@ CueParser::Feed2(char *p)
} }
state = TRACK; state = TRACK;
current = new DetachedSong(filename); current.reset(new DetachedSong(filename));
assert(!current->GetTag().IsDefined()); assert(!current->GetTag().IsDefined());
song_tag = header_tag; song_tag = header_tag;
@ -297,11 +289,9 @@ CueParser::Get()
deliver all remaining (partial) results */ deliver all remaining (partial) results */
assert(current == nullptr); assert(current == nullptr);
finished = previous; finished = std::move(previous);
previous = nullptr; previous.reset();
} }
DetachedSong *song = finished; return finished.release();
finished = nullptr;
return song;
} }

View File

@ -21,10 +21,12 @@
#define MPD_CUE_PARSER_HXX #define MPD_CUE_PARSER_HXX
#include "check.h" #include "check.h"
#include "DetachedSong.hxx"
#include "tag/TagBuilder.hxx" #include "tag/TagBuilder.hxx"
#include "Compiler.h" #include "Compiler.h"
#include <string> #include <string>
#include <memory>
class DetachedSong; class DetachedSong;
struct Tag; struct Tag;
@ -74,19 +76,19 @@ class CueParser {
/** /**
* The song currently being edited. * The song currently being edited.
*/ */
DetachedSong *current = nullptr; std::unique_ptr<DetachedSong> current;
/** /**
* The previous song. It is remembered because its end_time * The previous song. It is remembered because its end_time
* will be set to the current song's start time. * will be set to the current song's start time.
*/ */
DetachedSong *previous = nullptr; std::unique_ptr<DetachedSong> previous;
/** /**
* A song that is completely finished and can be returned to * A song that is completely finished and can be returned to
* the caller via cue_parser_get(). * the caller via cue_parser_get().
*/ */
DetachedSong *finished = nullptr; std::unique_ptr<DetachedSong> finished;
/** /**
* Tracks whether cue_parser_finish() has been called. If * Tracks whether cue_parser_finish() has been called. If
@ -96,8 +98,6 @@ class CueParser {
bool end = false; bool end = false;
public: public:
~CueParser();
/** /**
* Feed a text line from the CUE file into the parser. Call * Feed a text line from the CUE file into the parser. Call
* cue_parser_get() after this to see if a song has been finished. * cue_parser_get() after this to see if a song has been finished.