sticker/Database: return Sticker by value

This commit is contained in:
Max Kellermann 2019-04-24 15:05:05 +02:00
parent 7b48ae4f85
commit 5a915eb0e6
5 changed files with 13 additions and 32 deletions

View File

@ -21,6 +21,7 @@
#include "Request.hxx"
#include "SongPrint.hxx"
#include "db/Interface.hxx"
#include "sticker/Sticker.hxx"
#include "sticker/SongSticker.hxx"
#include "sticker/StickerPrint.hxx"
#include "sticker/StickerDatabase.hxx"
@ -76,11 +77,8 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
assert(song != nullptr);
AtScopeExit(&db, song) { db.ReturnSong(song); };
Sticker *sticker = sticker_song_get(*song);
if (sticker) {
sticker_print(r, *sticker);
sticker_free(sticker);
}
const auto sticker = sticker_song_get(*song);
sticker_print(r, sticker);
return CommandResult::OK;
/* set song song_id id key */

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2018 The Music Player Daemon Project
* Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@ -18,6 +18,7 @@
*/
#include "SongSticker.hxx"
#include "Sticker.hxx"
#include "StickerDatabase.hxx"
#include "song/LightSong.hxx"
#include "db/Interface.hxx"
@ -61,7 +62,7 @@ sticker_song_delete_value(const LightSong &song, const char *name)
return sticker_delete_value("song", uri.c_str(), name);
}
Sticker *
Sticker
sticker_song_get(const LightSong &song)
{
const auto uri = song.GetURI();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2018 The Music Player Daemon Project
* Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@ -72,9 +72,9 @@ sticker_song_delete_value(const LightSong &song, const char *name);
* Throws #SqliteError on error.
*
* @param song the song object
* @return a sticker object, or nullptr if there is no sticker
* @return a sticker object
*/
Sticker *
Sticker
sticker_song_get(const LightSong &song);
/**

View File

@ -314,12 +314,6 @@ sticker_delete_value(const char *type, const char *uri, const char *name)
return modified;
}
void
sticker_free(Sticker *sticker) noexcept
{
delete sticker;
}
const char *
sticker_get_value(const Sticker &sticker, const char *name) noexcept
{
@ -340,18 +334,14 @@ sticker_foreach(const Sticker &sticker,
func(i.first.c_str(), i.second.c_str(), user_data);
}
Sticker *
Sticker
sticker_load(const char *type, const char *uri)
{
Sticker s;
sticker_list_values(s.table, type, uri);
if (s.table.empty())
/* don't return empty sticker objects */
return nullptr;
return new Sticker(std::move(s));
return s;
}
static sqlite3_stmt *

View File

@ -108,14 +108,6 @@ sticker_delete(const char *type, const char *uri);
bool
sticker_delete_value(const char *type, const char *uri, const char *name);
/**
* Frees resources held by the sticker object.
*
* @param sticker the sticker object to be freed
*/
void
sticker_free(Sticker *sticker) noexcept;
/**
* Determines a single value in a sticker.
*
@ -147,9 +139,9 @@ sticker_foreach(const Sticker &sticker,
*
* @param type the resource type, e.g. "song"
* @param uri the URI of the resource, e.g. the song path
* @return a sticker object, or nullptr if there is no sticker
* @return a sticker object
*/
Sticker *
Sticker
sticker_load(const char *type, const char *uri);
/**