From ce8b3ada036bd7093a045852d2cbfebd14bed922 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 13 Nov 2014 08:31:47 -0500 Subject: [PATCH] Library: Rename count -> _size Also make it private and provide accessor functions. Signed-off-by: Anna Schumaker --- core/tags.cpp | 8 ++++---- core/tags/library.cpp | 19 +++++++++++++++++-- include/core/tags/library.h | 22 +++++++++++++++++++--- lib/colmgr.cpp | 4 ++-- tests/core/tags/library.cpp | 16 ++++++++++++---- 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/core/tags.cpp b/core/tags.cpp index 82e0386d..115e3c57 100644 --- a/core/tags.cpp +++ b/core/tags.cpp @@ -31,13 +31,13 @@ Track :: Track(const std::string &f, Library *l) play_count(0), last_year(0), last_month(0), last_day(0), filepath(f.substr(l->primary_key().size() + 1)) { - library->count++; + library->inc_size(); } Track :: ~Track() { if (library) - library->count--; + library->dec_size(); } const std::string Track :: primary_key() const @@ -64,7 +64,7 @@ void Track :: read(File &f) title_lower = filter :: add(title, index()); filter :: add(artist->name(), index()); filter :: add(album->name(), index()); - library->count++; + library->inc_size(); set_length_str(); } @@ -110,7 +110,7 @@ bool Track :: tag() TagLib :: AudioProperties *audio; TagLib :: FileRef ref(path().c_str(), true, TagLib::AudioProperties::Fast); - library->count++; + library->inc_size(); if (ref.isNull()) { print("WARNING: Could not read tags for file %s\n", path().c_str()); return false; diff --git a/core/tags/library.cpp b/core/tags/library.cpp index add7392e..ad1a25a1 100644 --- a/core/tags/library.cpp +++ b/core/tags/library.cpp @@ -5,12 +5,12 @@ #include Library :: Library() - : _enabled(false), count(0) + : _size(0), _enabled(false) { } Library :: Library(const std::string &s) - : _path(s), _enabled(true), count(0) + : _size(0), _path(s), _enabled(true) { } @@ -39,3 +39,18 @@ void Library :: set_enabled(bool enabled) { _enabled = enabled; } + +const unsigned int Library :: size() +{ + return _size; +} + +void Library :: inc_size() +{ + _size++; +} + +void Library :: dec_size() +{ + _size--; +} diff --git a/include/core/tags/library.h b/include/core/tags/library.h index 39d6af65..fa4fe7bd 100644 --- a/include/core/tags/library.h +++ b/include/core/tags/library.h @@ -12,13 +12,11 @@ */ class Library : public DatabaseEntry { private: + unsigned int _size; /**< Number of tracks in this library. */ std::string _path; /**< Path to the root directory of this library. */ bool _enabled; /**< Is this library path enabled? */ public: - /** Number of tracks in this library */ - unsigned int count; - /** Library constructor */ Library(); @@ -60,6 +58,24 @@ public: * @param enabled True if this path should be enabled, false otherwise. */ void set_enabled(bool); + + + /** + * Called to access the number of tracks in this library. + * + * @return Library::_size. + */ + const unsigned int size(); + + /** + * Used to increase _size by 1. + */ + void inc_size(); + + /** + * Used to decrease _size by 1. + */ + void dec_size(); }; #endif /* OCARINA_CORE_TAGS_LIBRARY_H */ diff --git a/lib/colmgr.cpp b/lib/colmgr.cpp index c3318a3f..9b64d662 100644 --- a/lib/colmgr.cpp +++ b/lib/colmgr.cpp @@ -45,7 +45,7 @@ static void list_path(Library *lib) row[c_cols.c_id] = lib->index(); row[c_cols.c_enabled] = lib->enabled(); - row[c_cols.c_size] = lib->count; + row[c_cols.c_size] = lib->size(); row[c_cols.c_path] = lib->primary_key(); } @@ -100,7 +100,7 @@ void colmgr :: update_paths() for (it = c_list->children().begin(); it != c_list->children().end(); it++) { lib = find_library(*it); if (lib) - (*it)[c_cols.c_size] = lib->count; + (*it)[c_cols.c_size] = lib->size(); } } diff --git a/tests/core/tags/library.cpp b/tests/core/tags/library.cpp index 8f2d44c5..a3871f0f 100644 --- a/tests/core/tags/library.cpp +++ b/tests/core/tags/library.cpp @@ -11,10 +11,18 @@ static void test_library_tag() File f("library_tag", 0); test_equal(library.primary_key(), (std::string)"/home/Zelda/Music"); - test_equal(library.count, (unsigned)0); + test_equal(library.size(), (unsigned)0); test_equal(library.enabled(), true); - library.count = 42; /* not saved to disk */ + + for (unsigned int i = 0; i < 42; i++) + library.inc_size(); + test_equal(library.size(), (unsigned)42); + + for (unsigned int i = 0; i < 21; i++) + library.dec_size(); + test_equal(library.size(), (unsigned)21); + f.open(OPEN_WRITE); library.write(f); @@ -22,7 +30,7 @@ static void test_library_tag() library = Library(); test_equal(library.primary_key(), (std::string)""); - test_equal(library.count, (unsigned)0); + test_equal(library.size(), (unsigned)0); test_equal(library.enabled(), false); f.open(OPEN_READ); @@ -30,7 +38,7 @@ static void test_library_tag() f.close(); test_equal(library.primary_key(), (std::string)"/home/Zelda/Music"); - test_equal(library.count, (unsigned)0); + test_equal(library.size(), (unsigned)0); /* _size is not saved to disk. */ test_equal(library.enabled(), true); }