Track: Hide the library field from the public

And provide an accessor function.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-20 08:16:13 -05:00
parent 7e52c9b364
commit 37613573e4
5 changed files with 25 additions and 19 deletions

View File

@ -120,7 +120,7 @@ static void validate_library(Library *&library)
for (it = db->begin(); it != db->end(); it = db->next(it)) {
track = *it;
if (track->library != library)
if (track->library() != library)
continue;
if (g_file_test(track->path().c_str(), G_FILE_TEST_EXISTS) == false) {
@ -144,7 +144,7 @@ void library :: init()
library_q.load();
for (it = db->begin(); it != db->end(); it = db->next(it)) {
if ((*it)->library->enabled())
if ((*it)->library()->enabled())
library_q.add(*it);
}
}
@ -205,7 +205,7 @@ void library :: set_enabled(Library *library, bool enabled)
library->set_enabled(enabled);
for (it = db->begin(); it != db->end(); it = db->next(it)) {
if ((*it)->library == library) {
if ((*it)->library() == library) {
if (enabled)
library_q.add(*it);
else

View File

@ -21,18 +21,18 @@ Database<Track> track_db("track.db", false);
*
*/
Track :: Track(const std::string &f, Library *l)
: library(l), artist(NULL), album(NULL), genre(NULL),
Track :: Track(const std::string &f, Library *library)
: _library(library), artist(NULL), album(NULL), genre(NULL),
play_count(0), last_year(0), last_month(0), last_day(0),
filepath(f.substr(l->primary_key().size() + 1))
filepath(f.substr(library->primary_key().size() + 1))
{
library->inc_size();
}
Track :: ~Track()
{
if (library)
library->dec_size();
if (_library)
_library->dec_size();
}
const std::string Track :: primary_key() const
@ -51,7 +51,7 @@ void Track :: read(File &f)
title = f.getline();
filepath = f.getline();
library = tags :: get_library(library_id);
_library = tags :: get_library(library_id);
artist = tags :: get_artist(artist_id);
album = tags :: get_album(album_id);
genre = tags :: get_genre(genre_id);
@ -59,13 +59,13 @@ void Track :: read(File &f)
title_lower = filter :: add(title, index());
filter :: add(artist->name(), index());
filter :: add(album->name(), index());
library->inc_size();
_library->inc_size();
set_length_str();
}
void Track :: write(File &f)
{
f << library->index() << " " << artist->index() << " ";
f << _library->index() << " " << artist->index() << " ";
f << album->index() << " " << genre->index() << " " << track << " ";
f << last_year << " " << last_month << " " << last_day << " ";
f << play_count << " " << length << " " << title << std::endl;
@ -105,7 +105,7 @@ bool Track :: tag()
TagLib :: AudioProperties *audio;
TagLib :: FileRef ref(path().c_str(), true, TagLib::AudioProperties::Fast);
library->inc_size();
_library->inc_size();
if (ref.isNull()) {
print("WARNING: Could not read tags for file %s\n", path().c_str());
return false;
@ -132,9 +132,9 @@ bool Track :: tag()
const std::string Track :: path() const
{
if (!library)
if (!_library)
return "";
return library->primary_key() + "/" + filepath;
return _library->primary_key() + "/" + filepath;
}
void Track :: played()
@ -244,7 +244,7 @@ void tagdb :: remove_library(unsigned int library_id)
{
Database<Track>::iterator it;
for (it = track_db.begin(); it != track_db.end(); it = track_db.next(it)) {
if ((*it)->library->index() == library_id)
if ((*it)->library()->index() == library_id)
track_db.remove((*it)->index());
}
tagdb :: commit();

View File

@ -7,6 +7,8 @@
Track :: Track()
: GenericTag(),
library(NULL), artist(NULL), album(NULL), genre(NULL),
_library(NULL), artist(NULL), album(NULL), genre(NULL),
track(0), length(0), play_count(0), last_year(0), last_month(0), last_day(0)
{}
Library *Track :: library() { return _library; }

View File

@ -39,11 +39,11 @@ enum sort_t {
class Track : public GenericTag {
private:
Library *_library; /**< Pointer to the Library containing this track. */
void set_length_str();
public:
/** Pointer to the library containing this track */
Library *library;
/** Pointer to this track's artist information */
Artist *artist;
/** Pointer to this track's album information */
@ -86,6 +86,10 @@ public:
/** Track destructor */
~Track();
Library *library(); /**< @return Track::_library. */
/**
* Called to access a track's primary key
* @return The full path of the track

View File

@ -9,7 +9,7 @@ static void test_track_tag()
{
Track track;
test_equal(track.library, (Library *)NULL);
test_equal(track.library(), (Library *)NULL);
test_equal(track.artist, (Artist *)NULL);
test_equal(track.album, (Album *)NULL);
test_equal(track.genre, (Genre *)NULL);