core/tags/album: Convert Album class to a struct
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
75d4bd2af3
commit
e6bdf65606
|
@ -8,7 +8,7 @@ extern "C" {
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
|
||||||
static database<Album> album_db;
|
static database<album> album_db;
|
||||||
|
|
||||||
static const std::string make_key(const std::string &name, unsigned int year)
|
static const std::string make_key(const std::string &name, unsigned int year)
|
||||||
{
|
{
|
||||||
|
@ -20,17 +20,17 @@ static const std::string make_key(const std::string &name, unsigned int year)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Album :: Album() : GenericTag(), _year(0) {}
|
album :: album() : GenericTag(), al_year(0) {}
|
||||||
|
|
||||||
Album :: Album(const std::string &name, unsigned int year)
|
album :: album(const std::string &name, unsigned int year)
|
||||||
: GenericTag(name), _year(year)
|
: GenericTag(name), al_year(year)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Album :: Album(const std::string &key)
|
album :: album(const std::string &key)
|
||||||
{
|
{
|
||||||
gchar *name, *lower;
|
gchar *name, *lower;
|
||||||
sscanf(key.c_str(), "%u/%m[^\n]", &_year, &name);
|
sscanf(key.c_str(), "%u/%m[^\n]", &al_year, &name);
|
||||||
|
|
||||||
lower = string_lowercase(name);
|
lower = string_lowercase(name);
|
||||||
_name = name;
|
_name = name;
|
||||||
|
@ -40,26 +40,26 @@ Album :: Album(const std::string &key)
|
||||||
g_free(lower);
|
g_free(lower);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Album :: primary_key() const
|
const std::string album :: primary_key() const
|
||||||
{
|
{
|
||||||
return make_key(GenericTag :: primary_key(), _year);
|
return make_key(GenericTag :: primary_key(), al_year);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Album :: read(file &file)
|
void album :: read(file &file)
|
||||||
{
|
{
|
||||||
file_readf(&file, "%u", &_year);
|
file_readf(&file, "%u", &al_year);
|
||||||
GenericTag :: read(file);
|
GenericTag :: read(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Album :: write(file &file)
|
void album :: write(file &file)
|
||||||
{
|
{
|
||||||
file_writef(&file, "%u ", _year);
|
file_writef(&file, "%u ", al_year);
|
||||||
GenericTag :: write(file);
|
GenericTag :: write(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Album :: year()
|
unsigned int album :: year()
|
||||||
{
|
{
|
||||||
return _year;
|
return al_year;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,12 +69,12 @@ void tags :: init_album_db()
|
||||||
db_load(&album_db);
|
db_load(&album_db);
|
||||||
}
|
}
|
||||||
|
|
||||||
Album *tags :: get_album(const std::string &name, unsigned int year)
|
struct album *tags :: get_album(const std::string &name, unsigned int year)
|
||||||
{
|
{
|
||||||
return db_find(&album_db, make_key(name, year).c_str());
|
return db_find(&album_db, make_key(name, year).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
Album *tags ::get_album(const unsigned int index)
|
struct album *tags ::get_album(const unsigned int index)
|
||||||
{
|
{
|
||||||
return db_at(&album_db, index);
|
return db_at(&album_db, index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ Track :: Track()
|
||||||
_count(0), _length(0), _track(0)
|
_count(0), _length(0), _track(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library,
|
Track :: Track(struct album *album, Artist *artist, Genre *genre, Library *library,
|
||||||
const std::string &filepath, const std::string &name,
|
const std::string &filepath, const std::string &name,
|
||||||
unsigned int length, unsigned int track)
|
unsigned int length, unsigned int track)
|
||||||
: GenericTag(name),
|
: GenericTag(name),
|
||||||
|
@ -59,7 +59,7 @@ Track :: ~Track()
|
||||||
_library->dec_size();
|
_library->dec_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Album *Track :: album() { return _album; }
|
struct album *Track :: album() { return _album; }
|
||||||
Artist *Track :: artist() { return _artist; }
|
Artist *Track :: artist() { return _artist; }
|
||||||
Genre *Track :: genre() { return _genre; }
|
Genre *Track :: genre() { return _genre; }
|
||||||
Library *Track :: library() { return _library; }
|
Library *Track :: library() { return _library; }
|
||||||
|
@ -148,7 +148,7 @@ void tags :: init_track_db()
|
||||||
db_load(&track_db);
|
db_load(&track_db);
|
||||||
}
|
}
|
||||||
|
|
||||||
Track *tags :: add_track(Album *album, Artist *artist, Genre *genre,
|
Track *tags :: add_track(struct album *album, Artist *artist, Genre *genre,
|
||||||
Library *library, const std::string &filepath,
|
Library *library, const std::string &filepath,
|
||||||
const std::string &name, unsigned int length,
|
const std::string &name, unsigned int length,
|
||||||
unsigned int track)
|
unsigned int track)
|
||||||
|
|
|
@ -17,12 +17,10 @@
|
||||||
* ... << year2 << GenericTag::write()
|
* ... << year2 << GenericTag::write()
|
||||||
* ... << year3 << GenericTag::write()
|
* ... << year3 << GenericTag::write()
|
||||||
*/
|
*/
|
||||||
class Album : public GenericTag {
|
struct album : public GenericTag {
|
||||||
private:
|
unsigned int al_year; /* Ths album's year. */
|
||||||
unsigned int _year; /**< The year associated with this Album. */
|
|
||||||
|
|
||||||
public:
|
album(); /**< Album tag constructor */
|
||||||
Album(); /**< Album tag constructor */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Album tag constructor
|
* Album tag constructor
|
||||||
|
@ -30,8 +28,8 @@ public:
|
||||||
* @param name Album name
|
* @param name Album name
|
||||||
* @param year Album year
|
* @param year Album year
|
||||||
*/
|
*/
|
||||||
Album(const std::string &, unsigned int);
|
album(const std::string &, unsigned int);
|
||||||
Album(const std::string &);
|
album(const std::string &);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The album's primary key is the concatenation of year
|
* The album's primary key is the concatenation of year
|
||||||
|
@ -79,7 +77,7 @@ namespace tags
|
||||||
* @param year The year of the album.
|
* @param year The year of the album.
|
||||||
* @return A matching Album tag.
|
* @return A matching Album tag.
|
||||||
*/
|
*/
|
||||||
Album *get_album(const std::string &, unsigned int);
|
struct album *get_album(const std::string &, unsigned int);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to look up an Album tag by tag index.
|
* Called to look up an Album tag by tag index.
|
||||||
|
@ -87,7 +85,7 @@ namespace tags
|
||||||
* @param index The index of the Album tag.
|
* @param index The index of the Album tag.
|
||||||
* @return A matching Album tag or NULL.
|
* @return A matching Album tag or NULL.
|
||||||
*/
|
*/
|
||||||
Album *get_album(const unsigned int);
|
struct album *get_album(const unsigned int);
|
||||||
|
|
||||||
} /* Namespace: tags */
|
} /* Namespace: tags */
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
class Track : public GenericTag {
|
class Track : public GenericTag {
|
||||||
private:
|
private:
|
||||||
Album *_album; /**< Pointer to the Album containing this track. */
|
struct album *_album; /**< Pointer to the Album containing this track. */
|
||||||
Artist *_artist; /**< Pointer to the Artist performing this track. */
|
Artist *_artist; /**< Pointer to the Artist performing this track. */
|
||||||
Genre *_genre; /**< Pointer to the Genre describing this track. */
|
Genre *_genre; /**< Pointer to the Genre describing this track. */
|
||||||
Library *_library; /**< Pointer to the Library containing this track. */
|
Library *_library; /**< Pointer to the Library containing this track. */
|
||||||
|
@ -45,7 +45,7 @@ public:
|
||||||
* @param length The length of this track (in seconds).
|
* @param length The length of this track (in seconds).
|
||||||
* @param track The track number of this track.
|
* @param track The track number of this track.
|
||||||
*/
|
*/
|
||||||
Track(Album *, Artist *, Genre *, Library *, const std::string &,
|
Track(struct album *, Artist *, Genre *, Library *, const std::string &,
|
||||||
const std::string &, unsigned int, unsigned int);
|
const std::string &, unsigned int, unsigned int);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,7 +59,7 @@ public:
|
||||||
~Track(); /**< Track destructor. */
|
~Track(); /**< Track destructor. */
|
||||||
|
|
||||||
|
|
||||||
Album *album(); /**< @return Track::_album. */
|
struct album *album(); /**< @return Track::_album. */
|
||||||
Artist *artist(); /**< @return Track::_artist. */
|
Artist *artist(); /**< @return Track::_artist. */
|
||||||
Genre *genre(); /**< @return Track::_genre. */
|
Genre *genre(); /**< @return Track::_genre. */
|
||||||
Library *library(); /**< @return Track::_library. */
|
Library *library(); /**< @return Track::_library. */
|
||||||
|
@ -135,7 +135,7 @@ namespace tags
|
||||||
* @return A new Track tag, or NULL if this Track is already in
|
* @return A new Track tag, or NULL if this Track is already in
|
||||||
* the track_db.
|
* the track_db.
|
||||||
*/
|
*/
|
||||||
Track *add_track(Album *, Artist *, Genre *, Library *,
|
Track *add_track(album *, Artist *, Genre *, Library *,
|
||||||
const std::string &, const std::string &,
|
const std::string &, const std::string &,
|
||||||
unsigned int, unsigned int);
|
unsigned int, unsigned int);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <core/tags/album.h>
|
#include <core/tags/album.h>
|
||||||
#include "../test.h"
|
#include "../test.h"
|
||||||
|
|
||||||
static void test_verify_empty(Album *album)
|
static void test_verify_empty(struct album *album)
|
||||||
{
|
{
|
||||||
test_equal(album->name(), "");
|
test_equal(album->name(), "");
|
||||||
test_equal(album->lowercase(), "");
|
test_equal(album->lowercase(), "");
|
||||||
|
@ -12,7 +12,7 @@ static void test_verify_empty(Album *album)
|
||||||
test_equal(album->primary_key(), "0/");
|
test_equal(album->primary_key(), "0/");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_verify_hyrule(Album *album)
|
static void test_verify_hyrule(struct album *album)
|
||||||
{
|
{
|
||||||
test_equal(album->name(), "Hyrule Symphony");
|
test_equal(album->name(), "Hyrule Symphony");
|
||||||
test_equal(album->lowercase(), "hyrule symphony");
|
test_equal(album->lowercase(), "hyrule symphony");
|
||||||
|
@ -22,7 +22,7 @@ static void test_verify_hyrule(Album *album)
|
||||||
|
|
||||||
static void test_album()
|
static void test_album()
|
||||||
{
|
{
|
||||||
Album *album = new Album("Hyrule Symphony", 1998);
|
struct album *album = new struct album("Hyrule Symphony", 1998);
|
||||||
file f;
|
file f;
|
||||||
|
|
||||||
test_verify_hyrule(album);
|
test_verify_hyrule(album);
|
||||||
|
@ -34,7 +34,7 @@ static void test_album()
|
||||||
file_close(&f);
|
file_close(&f);
|
||||||
delete album;
|
delete album;
|
||||||
|
|
||||||
album = new Album();
|
album = new struct album();
|
||||||
test_verify_empty(album);
|
test_verify_empty(album);
|
||||||
|
|
||||||
file_open(&f, OPEN_READ);
|
file_open(&f, OPEN_READ);
|
||||||
|
@ -49,8 +49,8 @@ static void test_album()
|
||||||
|
|
||||||
static void test_album_compare()
|
static void test_album_compare()
|
||||||
{
|
{
|
||||||
Album *twilight = new Album("Twilight Princess", 2006);
|
struct album *twilight = new struct album("Twilight Princess", 2006);
|
||||||
Album *skyward = new Album("skyward sword", 2011);
|
struct album *skyward = new struct album("skyward sword", 2011);
|
||||||
|
|
||||||
test_equal(twilight->compare(twilight), 0);
|
test_equal(twilight->compare(twilight), 0);
|
||||||
test_equal(twilight->compare(skyward), 1);
|
test_equal(twilight->compare(skyward), 1);
|
||||||
|
@ -62,8 +62,8 @@ static void test_album_compare()
|
||||||
|
|
||||||
static void test_album_db()
|
static void test_album_db()
|
||||||
{
|
{
|
||||||
database<Album> album_db;
|
database<struct album> album_db;
|
||||||
Album *album;
|
struct album *album;
|
||||||
|
|
||||||
tags :: init_album_db();
|
tags :: init_album_db();
|
||||||
album = tags :: get_album("Hyrule Symphony", 1998);
|
album = tags :: get_album("Hyrule Symphony", 1998);
|
||||||
|
@ -72,7 +72,7 @@ static void test_album_db()
|
||||||
|
|
||||||
test_equal(tags :: get_album("Hyrule Symphony", 1998), album);
|
test_equal(tags :: get_album("Hyrule Symphony", 1998), album);
|
||||||
test_equal(tags :: get_album(0), album);
|
test_equal(tags :: get_album(0), album);
|
||||||
test_equal(tags :: get_album(1), (Album *)NULL);
|
test_equal(tags :: get_album(1), (struct album *)NULL);
|
||||||
|
|
||||||
db_init(&album_db, "album.db", false);
|
db_init(&album_db, "album.db", false);
|
||||||
db_load(&album_db);
|
db_load(&album_db);
|
||||||
|
|
|
@ -14,7 +14,7 @@ extern "C" {
|
||||||
|
|
||||||
|
|
||||||
static Artist *artist = NULL;
|
static Artist *artist = NULL;
|
||||||
static Album *album = NULL;
|
static struct album *album = NULL;
|
||||||
static Genre *genre = NULL;
|
static Genre *genre = NULL;
|
||||||
static Library *library = NULL;
|
static Library *library = NULL;
|
||||||
const std::string MUSIC_DIR = "/home/Zelda/Music";
|
const std::string MUSIC_DIR = "/home/Zelda/Music";
|
||||||
|
@ -24,7 +24,7 @@ static void test_track_tag_default()
|
||||||
{
|
{
|
||||||
Track track;
|
Track track;
|
||||||
|
|
||||||
test_equal(track.album(), (Album *)NULL);
|
test_equal(track.album(), (struct album *)NULL);
|
||||||
test_equal(track.artist(), (Artist *)NULL);
|
test_equal(track.artist(), (Artist *)NULL);
|
||||||
test_equal(track.genre(), (Genre *)NULL);
|
test_equal(track.genre(), (Genre *)NULL);
|
||||||
test_equal(track.library(), (Library *)NULL);
|
test_equal(track.library(), (Library *)NULL);
|
||||||
|
|
Loading…
Reference in New Issue