Track: Add a function for saving the track_db
The track_db doesn't have autosaving enabled for performance reasons. This lets us add several tracks to the database between saves, but it also means we need to provide a commit() function. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
83cc81c934
commit
d5fc2a4de0
|
@ -169,3 +169,8 @@ Track *tags :: get_track(const unsigned int index)
|
||||||
{
|
{
|
||||||
return track_db.at(index);
|
return track_db.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tags :: commit_track_db()
|
||||||
|
{
|
||||||
|
track_db.save();
|
||||||
|
}
|
||||||
|
|
|
@ -150,6 +150,9 @@ namespace tags
|
||||||
* @return A matching Track tag, or NULL.
|
* @return A matching Track tag, or NULL.
|
||||||
*/
|
*/
|
||||||
Track *get_track(const unsigned int);
|
Track *get_track(const unsigned int);
|
||||||
|
|
||||||
|
/** Called to write the track_db to disk. */
|
||||||
|
void commit_track_db();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* OCARINA_CORE_TAGS_TRACK_H */
|
#endif /* OCARINA_CORE_TAGS_TRACK_H */
|
||||||
|
|
|
@ -83,6 +83,7 @@ static void test_track_tag_destructor()
|
||||||
|
|
||||||
static void test_track_tag_lookup()
|
static void test_track_tag_lookup()
|
||||||
{
|
{
|
||||||
|
Database<Track> track_db("track.db", false);
|
||||||
Track *a, *b;
|
Track *a, *b;
|
||||||
|
|
||||||
a = tags :: add_track(album, artist, genre, library,
|
a = tags :: add_track(album, artist, genre, library,
|
||||||
|
@ -98,6 +99,13 @@ static void test_track_tag_lookup()
|
||||||
|
|
||||||
test_equal(tags :: get_track(a->index()), a);
|
test_equal(tags :: get_track(a->index()), a);
|
||||||
test_equal(tags :: get_track(a->index() + 1), (Track *)NULL);
|
test_equal(tags :: get_track(a->index() + 1), (Track *)NULL);
|
||||||
|
|
||||||
|
track_db.load();
|
||||||
|
test_equal(track_db.size(), (unsigned)0);
|
||||||
|
|
||||||
|
tags :: commit_track_db();
|
||||||
|
track_db.load();
|
||||||
|
test_equal(track_db.size(), (unsigned)1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_track_tag_functional()
|
static void test_track_tag_functional()
|
||||||
|
|
Loading…
Reference in New Issue