SongSticker: use Song references

This commit is contained in:
Max Kellermann 2014-01-08 00:41:08 +01:00
parent c152a88ff6
commit 6a953394f4
4 changed files with 26 additions and 31 deletions

View File

@ -29,53 +29,48 @@
#include <string.h>
std::string
sticker_song_get_value(const Song *song, const char *name)
sticker_song_get_value(const Song &song, const char *name)
{
assert(song != nullptr);
assert(song->IsInDatabase());
assert(song.IsInDatabase());
const auto uri = song->GetURI();
const auto uri = song.GetURI();
return sticker_load_value("song", uri.c_str(), name);
}
bool
sticker_song_set_value(const Song *song,
sticker_song_set_value(const Song &song,
const char *name, const char *value)
{
assert(song != nullptr);
assert(song->IsInDatabase());
assert(song.IsInDatabase());
const auto uri = song->GetURI();
const auto uri = song.GetURI();
return sticker_store_value("song", uri.c_str(), name, value);
}
bool
sticker_song_delete(const Song *song)
sticker_song_delete(const Song &song)
{
assert(song != nullptr);
assert(song->IsInDatabase());
assert(song.IsInDatabase());
const auto uri = song->GetURI();
const auto uri = song.GetURI();
return sticker_delete("song", uri.c_str());
}
bool
sticker_song_delete_value(const Song *song, const char *name)
sticker_song_delete_value(const Song &song, const char *name)
{
assert(song != nullptr);
assert(song->IsInDatabase());
assert(song.IsInDatabase());
const auto uri = song->GetURI();
const auto uri = song.GetURI();
return sticker_delete_value("song", uri.c_str(), name);
}
struct sticker *
sticker_song_get(const Song *song)
sticker_song_get(const Song &song)
{
assert(song != nullptr);
assert(song->IsInDatabase());
assert(song.IsInDatabase());
const auto uri = song->GetURI();
const auto uri = song.GetURI();
return sticker_load("song", uri.c_str());
}

View File

@ -34,28 +34,28 @@ struct sticker;
*/
gcc_pure
std::string
sticker_song_get_value(const Song *song, const char *name);
sticker_song_get_value(const Song &song, const char *name);
/**
* Sets a sticker value in the specified song. Overwrites existing
* values.
*/
bool
sticker_song_set_value(const Song *song,
sticker_song_set_value(const Song &song,
const char *name, const char *value);
/**
* Deletes a sticker from the database. All values are deleted.
*/
bool
sticker_song_delete(const Song *song);
sticker_song_delete(const Song &song);
/**
* Deletes a sticker value. Does nothing if the sticker did not
* exist.
*/
bool
sticker_song_delete_value(const Song *song, const char *name);
sticker_song_delete_value(const Song &song, const char *name);
/**
* Loads the sticker for the specified song.
@ -64,7 +64,7 @@ sticker_song_delete_value(const Song *song, const char *name);
* @return a sticker object, or NULL on error or if there is no sticker
*/
sticker *
sticker_song_get(const Song *song);
sticker_song_get(const Song &song);
/**
* Finds stickers with the specified name below the specified

View File

@ -57,7 +57,7 @@ song_remove_event(void)
#ifdef ENABLE_SQLITE
/* if the song has a sticker, remove it */
if (sticker_enabled())
sticker_song_delete(removed_song);
sticker_song_delete(*removed_song);
#endif
instance->DeleteSong(*removed_song);

View File

@ -63,7 +63,7 @@ handle_sticker_song(Client &client, int argc, char *argv[])
if (song == nullptr)
return print_error(client, error);
const auto value = sticker_song_get_value(song, argv[4]);
const auto value = sticker_song_get_value(*song, argv[4]);
db->ReturnSong(song);
if (value.empty()) {
command_error(client, ACK_ERROR_NO_EXIST,
@ -80,7 +80,7 @@ handle_sticker_song(Client &client, int argc, char *argv[])
if (song == nullptr)
return print_error(client, error);
sticker *sticker = sticker_song_get(song);
sticker *sticker = sticker_song_get(*song);
db->ReturnSong(song);
if (sticker) {
sticker_print(client, *sticker);
@ -94,7 +94,7 @@ handle_sticker_song(Client &client, int argc, char *argv[])
if (song == nullptr)
return print_error(client, error);
bool ret = sticker_song_set_value(song, argv[4], argv[5]);
bool ret = sticker_song_set_value(*song, argv[4], argv[5]);
db->ReturnSong(song);
if (!ret) {
command_error(client, ACK_ERROR_SYSTEM,
@ -111,8 +111,8 @@ handle_sticker_song(Client &client, int argc, char *argv[])
return print_error(client, error);
bool ret = argc == 4
? sticker_song_delete(song)
: sticker_song_delete_value(song, argv[4]);
? sticker_song_delete(*song)
: sticker_song_delete_value(*song, argv[4]);
db->ReturnSong(song);
if (!ret) {
command_error(client, ACK_ERROR_SYSTEM,