From a9fc53964c9f7fdc74bfe7f4867cdb92d8ac36e9 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 8 Nov 2014 20:08:42 -0500 Subject: [PATCH] Artist: The ArtistTag should inherit from GenericTag The GenericTag class provides most of the implementation, so use it! Signed-off-by: Anna Schumaker --- core/tags.cpp | 6 +++--- core/tags/artist.cpp | 23 +++------------------ gui/gui.cpp | 2 +- include/core/tags/artist.h | 40 ++++--------------------------------- include/core/tags/generic.h | 10 +++++----- lib/model.cpp | 2 +- tests/core/tags/artist.cpp | 24 ++++------------------ 7 files changed, 21 insertions(+), 86 deletions(-) diff --git a/core/tags.cpp b/core/tags.cpp index 4bba3ccc..663e561c 100644 --- a/core/tags.cpp +++ b/core/tags.cpp @@ -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: diff --git a/core/tags/artist.cpp b/core/tags/artist.cpp index 7f36c75a..204d468a 100644 --- a/core/tags/artist.cpp +++ b/core/tags/artist.cpp @@ -2,28 +2,11 @@ * @file * Copyright 2014 (c) Anna Schumaker. */ -#include #include -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; -} diff --git a/gui/gui.cpp b/gui/gui.cpp index ced6dcf8..19c413ce 100644 --- a/gui/gui.cpp +++ b/gui/gui.cpp @@ -47,7 +47,7 @@ static void on_track_loaded(Track *track) Gtk::Label *duration = lib :: get_widget("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); diff --git a/include/core/tags/artist.h b/include/core/tags/artist.h index ac36e517..ad443da5 100644 --- a/include/core/tags/artist.h +++ b/include/core/tags/artist.h @@ -5,54 +5,22 @@ #ifndef OCARINA_CORE_TAGS_ARTIST_H #define OCARINA_CORE_TAGS_ARTIST_H -#include +#include /** * 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 */ diff --git a/include/core/tags/generic.h b/include/core/tags/generic.h index 4ca77dc9..2c5f4f27 100644 --- a/include/core/tags/generic.h +++ b/include/core/tags/generic.h @@ -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(); }; diff --git a/lib/model.cpp b/lib/model.cpp index 60dfb741..764c7c95 100644 --- a/lib/model.cpp +++ b/lib/model.cpp @@ -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); diff --git a/tests/core/tags/artist.cpp b/tests/core/tags/artist.cpp index 5062c4a7..d521cc0a 100644 --- a/tests/core/tags/artist.cpp +++ b/tests/core/tags/artist.cpp @@ -2,35 +2,19 @@ * @file * Copyright 2014 (c) Anna Schumaker. */ -#include #include #include 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"); }