Artist: The ArtistTag should inherit from GenericTag

The GenericTag class provides most of the implementation, so use it!

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-08 20:08:42 -05:00
parent fb4f523206
commit a9fc53964c
7 changed files with 21 additions and 86 deletions

View File

@ -161,7 +161,7 @@ void Track :: read(File &f)
genre = genre_db.at(genre_id);
title_lower = filter :: add(title, index());
filter :: add(artist->name, index());
filter :: add(artist->name(), index());
filter :: add(album->name, index());
library->count++;
set_length_str();
@ -228,7 +228,7 @@ bool Track :: tag()
title_lower = filter :: add(title, index());
set_length_str();
filter :: add(artist->name, index());
filter :: add(artist->name(), index());
filter :: add(album->name, index());
return true;
@ -281,7 +281,7 @@ int Track :: less_than(Track *rhs, sort_t field)
int ret;
switch (field) {
case SORT_ARTIST:
return compare_string(artist->lower, rhs->artist->lower);
return compare_string(artist->lowercase(), rhs->artist->lowercase());
case SORT_ALBUM:
return compare_string(album->lower, rhs->album->lower);
case SORT_COUNT:

View File

@ -2,28 +2,11 @@
* @file
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/filter.h>
#include <core/tags/artist.h>
Artist :: Artist() {}
Artist :: Artist() : GenericTag() {}
Artist :: Artist(const std::string &s)
: name(s), lower(filter :: lowercase(name))
Artist :: Artist(const std::string &name)
: GenericTag(name)
{
}
const std::string Artist :: primary_key() const
{
return name;
}
void Artist :: read(File &f)
{
name = f.getline();
lower = filter :: lowercase(name);
}
void Artist :: write(File &f)
{
f << name;
}

View File

@ -47,7 +47,7 @@ static void on_track_loaded(Track *track)
Gtk::Label *duration = lib :: get_widget<Gtk::Label>("o_total_time");
set_label_text(title, "xx-large", track->title);
set_label_text(artist, "x-large", "By: " + track->artist->name);
set_label_text(artist, "x-large", "By: " + track->artist->name());
set_label_text(album, "x-large", "From: " + track->album->name);
duration->set_text(track->length_str);

View File

@ -5,54 +5,22 @@
#ifndef OCARINA_CORE_TAGS_ARTIST_H
#define OCARINA_CORE_TAGS_ARTIST_H
#include <core/database.h>
#include <core/tags/generic.h>
/**
* The Artist tag is used to store the name of artists added
* to the tag database.
*
* When writing an Artist tag to disk, only the artist name
* needs to be written.
*
* ... << name1
* ... << name2
* ... << name3
*/
class Artist : public DatabaseEntry {
class Artist : public GenericTag {
public:
std::string name; /**< Artist name. */
std::string lower; /**< Artist name (lowercase). */
Artist(); /**< Artist tag constructor */
Artist(); /**< Artist tag constructor. */
/**
* Artist tag constructor
*
* @param name Artist name
* @param name Artist name.
*/
Artist(const std::string &);
/**
* Called to access the artist tag's primary key
*
* @return Artist::name
*/
const std::string primary_key() const;
/**
* Read the artist name from file and
* find the lowercase form.
*
* @param file The file to read from.
*/
void read(File &);
/**
* Write the artist name to file.
*
* @param file The file to write to.
*/
void write(File &);
};
#endif /* OCARINA_CORE_TAGS_ARTIST_H */

View File

@ -38,19 +38,19 @@ public:
/**
* Called to access the generic tag's primary key.
*
* @return ::_name.
* @return GenericTag::_name.
*/
virtual const std::string primary_key() const;
/**
* Read ::_name from file and find the lowercase form.
* Read GenericTag::_name from file and find the lowercase form.
*
* @param file The file to read from.
*/
virtual void read(File &);
/**
* Write ::_name to file.
* Write GenericTag::_name to file.
*
* @param file The file to write to.
*/
@ -59,14 +59,14 @@ public:
/**
* Called to access the name associated with this tag.
*
* @return ::_name.
* @return GenericTag::_name.
*/
const std::string &name();
/**
* Called to access the lowercase form of ::_name.
*
* @return ::_lower.
* @return GenericTag::_lower.
*/
const std::string &lowercase();
};

View File

@ -146,7 +146,7 @@ void QueueModel::get_value_str(Track *track, int column,
specific.set(track->length_str);
break;
case 3:
specific.set(track->artist->name);
specific.set(track->artist->name());
break;
case 4:
specific.set(track->album->name);

View File

@ -2,35 +2,19 @@
* @file
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/file.h>
#include <core/tags/artist.h>
#include <tests/test.h>
static void test_artist_tag()
{
Artist artist;
File f("artist_tag", 0);
test_equal(artist.name, (std::string)"");
test_equal(artist.lower, (std::string)"");
test_equal(artist.name(), (std::string)"");
test_equal(artist.lowercase(), (std::string)"");
test_equal(artist.primary_key(), (std::string)"");
artist = Artist("Koji Kondo");
test_equal(artist.name, (std::string)"Koji Kondo");
test_equal(artist.lower, (std::string)"koji kondo");
test_equal(artist.primary_key(), (std::string)"Koji Kondo");
f.open(OPEN_WRITE);
artist.write(f);
f.close();
artist = Artist();
f.open(OPEN_READ);
artist.read(f);
f.close();
test_equal(artist.name, (std::string)"Koji Kondo");
test_equal(artist.lower, (std::string)"koji kondo");
test_equal(artist.name(), (std::string)"Koji Kondo");
test_equal(artist.lowercase(), (std::string)"koji kondo");
test_equal(artist.primary_key(), (std::string)"Koji Kondo");
}