ocarina/lib/playlist.cpp
Anna Schumaker 114c22bb12 playlist: Implement reachitecting of playlists
I changed the two playlists that are supported, added in exception
handling, and removed the list() function since I will always know the
names of playlists.  I also rename everything to "playlist" from
"group".

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
2014-04-06 19:56:57 -04:00

52 lines
1.0 KiB
C++

/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <database.h>
#include <error.h>
#include <playlist.h>
static std::set<unsigned int> empty_set;
static Database<IndexEntry> playlist_db("playlist.db");
void playlist :: init()
{
playlist_db.load();
}
void playlist :: add(const std::string &name, unsigned int track_id)
{
if ((name == "Banned") || (name == "Favorites")) {
index_insert(playlist_db, name, track_id);
playlist_db.save();
} else
throw -EEXIST;
}
void playlist :: del(const std::string &name, unsigned int track_id)
{
if ((name == "Banned") || (name == "Favorites")) {
index_remove(playlist_db, name, track_id);
playlist_db.save();
} else
throw -EEXIST;
}
const std::set<unsigned int> &playlist :: get_tracks(const std::string &name)
{
if ((name == "Banned") || (name == "Favorites")) {
try {
return playlist_db.find(name).values;
} catch (int error) {
return empty_set;
}
}
throw -EEXIST;
}
#ifdef CONFIG_TEST
void playlist :: clear()
{
playlist_db.clear();
}
#endif /* CONFIG_TEST */