SongSticker: use Song references
This commit is contained in:
parent
c152a88ff6
commit
6a953394f4
@ -29,53 +29,48 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
std::string
|
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);
|
return sticker_load_value("song", uri.c_str(), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sticker_song_set_value(const Song *song,
|
sticker_song_set_value(const Song &song,
|
||||||
const char *name, const char *value)
|
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);
|
return sticker_store_value("song", uri.c_str(), name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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());
|
return sticker_delete("song", uri.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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);
|
return sticker_delete_value("song", uri.c_str(), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sticker *
|
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());
|
return sticker_load("song", uri.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,28 +34,28 @@ struct sticker;
|
|||||||
*/
|
*/
|
||||||
gcc_pure
|
gcc_pure
|
||||||
std::string
|
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
|
* Sets a sticker value in the specified song. Overwrites existing
|
||||||
* values.
|
* values.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
sticker_song_set_value(const Song *song,
|
sticker_song_set_value(const Song &song,
|
||||||
const char *name, const char *value);
|
const char *name, const char *value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a sticker from the database. All values are deleted.
|
* Deletes a sticker from the database. All values are deleted.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
sticker_song_delete(const Song *song);
|
sticker_song_delete(const Song &song);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a sticker value. Does nothing if the sticker did not
|
* Deletes a sticker value. Does nothing if the sticker did not
|
||||||
* exist.
|
* exist.
|
||||||
*/
|
*/
|
||||||
bool
|
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.
|
* 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
|
* @return a sticker object, or NULL on error or if there is no sticker
|
||||||
*/
|
*/
|
||||||
sticker *
|
sticker *
|
||||||
sticker_song_get(const Song *song);
|
sticker_song_get(const Song &song);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds stickers with the specified name below the specified
|
* Finds stickers with the specified name below the specified
|
||||||
|
@ -57,7 +57,7 @@ song_remove_event(void)
|
|||||||
#ifdef ENABLE_SQLITE
|
#ifdef ENABLE_SQLITE
|
||||||
/* if the song has a sticker, remove it */
|
/* if the song has a sticker, remove it */
|
||||||
if (sticker_enabled())
|
if (sticker_enabled())
|
||||||
sticker_song_delete(removed_song);
|
sticker_song_delete(*removed_song);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
instance->DeleteSong(*removed_song);
|
instance->DeleteSong(*removed_song);
|
||||||
|
@ -63,7 +63,7 @@ handle_sticker_song(Client &client, int argc, char *argv[])
|
|||||||
if (song == nullptr)
|
if (song == nullptr)
|
||||||
return print_error(client, error);
|
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);
|
db->ReturnSong(song);
|
||||||
if (value.empty()) {
|
if (value.empty()) {
|
||||||
command_error(client, ACK_ERROR_NO_EXIST,
|
command_error(client, ACK_ERROR_NO_EXIST,
|
||||||
@ -80,7 +80,7 @@ handle_sticker_song(Client &client, int argc, char *argv[])
|
|||||||
if (song == nullptr)
|
if (song == nullptr)
|
||||||
return print_error(client, error);
|
return print_error(client, error);
|
||||||
|
|
||||||
sticker *sticker = sticker_song_get(song);
|
sticker *sticker = sticker_song_get(*song);
|
||||||
db->ReturnSong(song);
|
db->ReturnSong(song);
|
||||||
if (sticker) {
|
if (sticker) {
|
||||||
sticker_print(client, *sticker);
|
sticker_print(client, *sticker);
|
||||||
@ -94,7 +94,7 @@ handle_sticker_song(Client &client, int argc, char *argv[])
|
|||||||
if (song == nullptr)
|
if (song == nullptr)
|
||||||
return print_error(client, error);
|
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);
|
db->ReturnSong(song);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
command_error(client, ACK_ERROR_SYSTEM,
|
command_error(client, ACK_ERROR_SYSTEM,
|
||||||
@ -111,8 +111,8 @@ handle_sticker_song(Client &client, int argc, char *argv[])
|
|||||||
return print_error(client, error);
|
return print_error(client, error);
|
||||||
|
|
||||||
bool ret = argc == 4
|
bool ret = argc == 4
|
||||||
? sticker_song_delete(song)
|
? sticker_song_delete(*song)
|
||||||
: sticker_song_delete_value(song, argv[4]);
|
: sticker_song_delete_value(*song, argv[4]);
|
||||||
db->ReturnSong(song);
|
db->ReturnSong(song);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
command_error(client, ACK_ERROR_SYSTEM,
|
command_error(client, ACK_ERROR_SYSTEM,
|
||||||
|
Loading…
Reference in New Issue
Block a user