From 4224d898137e463d3c316f845ccd62f456f390e0 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 1 Dec 2014 09:44:32 -0500 Subject: [PATCH] Track: Add a function for finding track_db size This returns the actual size of the database, so be careful when using it! The intent of this function is to allow some kind of iteration when loading databases. Signed-off-by: Anna Schumaker --- core/tags/track.cpp | 5 +++++ include/core/tags/track.h | 8 ++++++++ tests/core/tags/track.cpp | 3 +++ 3 files changed, 16 insertions(+) diff --git a/core/tags/track.cpp b/core/tags/track.cpp index a80422ad..43aeeea5 100644 --- a/core/tags/track.cpp +++ b/core/tags/track.cpp @@ -186,6 +186,11 @@ void tags :: remove_library_tracks(Library *library) tags :: commit_track_db(); } +unsigned int tags :: track_size() +{ + return track_db.actual_size(); +} + void tags :: commit_track_db() { track_db.save(); diff --git a/include/core/tags/track.h b/include/core/tags/track.h index 0d2ae068..1955200d 100644 --- a/include/core/tags/track.h +++ b/include/core/tags/track.h @@ -165,6 +165,14 @@ namespace tags */ void remove_library_tracks(Library *); + /** + * Called to find the number of rows in the track_db, + * including NULL rows. + * + * @return The Database::actual_size() of the track_db. + */ + unsigned int track_size(); + /** Called to write the track_db to disk. */ void commit_track_db(); } diff --git a/tests/core/tags/track.cpp b/tests/core/tags/track.cpp index 4e0b8ea9..e808117a 100644 --- a/tests/core/tags/track.cpp +++ b/tests/core/tags/track.cpp @@ -109,6 +109,7 @@ static void test_track_tag_lookup() "Ocarina Medley", 232, 12); test_not_equal(b, a); test_equal(library->size(), (unsigned)2); + test_equal(tags :: track_size(), b->index() + 1); test_equal(tags :: get_track(a->index()), a); @@ -127,6 +128,7 @@ static void test_track_tag_lookup() tags :: commit_track_db(); test_track_tag_load_db(1); test_equal(library->size(), (unsigned)1); + test_equal(tags :: track_size(), b->index() + 1); a = tags :: add_track(album, artist, genre, library, @@ -134,6 +136,7 @@ static void test_track_tag_lookup() "Legend of Zelda Medley", 288, 13); test_not_equal(a, (Track *)NULL); verify_track_tag(a, 2); + test_equal(tags :: track_size(), a->index() + 1); tags :: remove_library_tracks(library); test_track_tag_load_db(0);