From 7dcfc2ba78a4c622e194991596000c1fdede42af Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 29 Sep 2015 16:25:16 -0400 Subject: [PATCH] core/index: Move index_init() out of the Index class Signed-off-by: Anna Schumaker --- core/core.cpp | 2 ++ core/filter.cpp | 5 ++++- core/index.cpp | 4 ++-- core/playlist.cpp | 3 ++- include/core/filter.h | 3 +++ include/core/index.h | 14 +++----------- tests/core/audio.cpp | 2 ++ tests/core/deck.cpp | 2 ++ tests/core/filter.cpp | 2 ++ tests/core/index.cpp | 6 +++++- tests/core/library.cpp | 2 ++ tests/core/playlist.cpp | 2 ++ tests/core/queue.cpp | 2 ++ tests/core/tags/track.cpp | 1 + 14 files changed, 34 insertions(+), 16 deletions(-) diff --git a/core/core.cpp b/core/core.cpp index 637979e1..0a1197cd 100644 --- a/core/core.cpp +++ b/core/core.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -11,6 +12,7 @@ void core :: init() { + filter_init(); tags :: init(); library :: init(); playlist :: init(); diff --git a/core/filter.cpp b/core/filter.cpp index 3dbe2d30..be8fb14c 100644 --- a/core/filter.cpp +++ b/core/filter.cpp @@ -11,7 +11,10 @@ extern "C" { #include -static Index filter_index("", false); +static Index filter_index; + +void filter_init() { index_init(&filter_index, "", false); } +void filter_deinit() { db_deinit(&filter_index); } const std::string filter :: add(const std::string &text, unsigned int index) { diff --git a/core/index.cpp b/core/index.cpp index 2933ffc3..291052ac 100644 --- a/core/index.cpp +++ b/core/index.cpp @@ -59,9 +59,9 @@ void index_entry :: read(file &file) -Index :: Index(const std::string &filepath, bool autosave) +void index_init(Index *index, const gchar *filepath, bool autosave) { - db_init(this, filepath.c_str(), autosave); + db_init(index, filepath, autosave); } index_entry *index_insert(Index *index, const gchar *key, unsigned int value) diff --git a/core/playlist.cpp b/core/playlist.cpp index ea916f72..8d4bcef6 100644 --- a/core/playlist.cpp +++ b/core/playlist.cpp @@ -78,7 +78,7 @@ public: }; -static Index playlist_db("playlist.db", true); +static Index playlist_db; static PlaylistQueue playlist_q; static std::string cur_plist; @@ -87,6 +87,7 @@ void playlist :: init() { std::set::iterator it; + index_init(&playlist_db, "playlist.db", true); db_load(&playlist_db); index_entry *ent = get_tracks("Banned"); diff --git a/include/core/filter.h b/include/core/filter.h index 95744f50..9b9127d7 100644 --- a/include/core/filter.h +++ b/include/core/filter.h @@ -57,4 +57,7 @@ namespace filter { }; +void filter_init(); +void filter_deinit(); + #endif /* OCARINA_CORE_FILTER_H */ diff --git a/include/core/index.h b/include/core/index.h index 7580cc63..47f3de3c 100644 --- a/include/core/index.h +++ b/include/core/index.h @@ -86,18 +86,10 @@ struct index_entry : public DatabaseEntry { * An Index is a special Database for mapping std::strings to a std::set of * integer identifiers. */ -class Index : public database { -public: - /** - * Index constructor. This simply passes the filepath and autosave - * parameters to the Database constructor. - * - * @param filepath Where to store the file on disk. - * @param autosave True if changes should automatically be saved. - */ - Index(const std::string &, bool); -}; +class Index : public database {}; +/* Initialize an Index. */ +void index_init(Index *, const gchar *, bool); /* Add a value to an index item with the specified key. */ index_entry *index_insert(Index *, const gchar *, unsigned int); diff --git a/tests/core/audio.cpp b/tests/core/audio.cpp index 23cbf506..5d712f52 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.cpp @@ -2,6 +2,7 @@ * Copyright 2013 (c) Anna Schumaker. */ #include +#include #include #include #include "test.h" @@ -82,6 +83,7 @@ void test_init() track = audio :: current_track(); test_equal(track, TRACK_NULL); + filter_init(); tags :: init(); library :: init(); audio :: init(); diff --git a/tests/core/deck.cpp b/tests/core/deck.cpp index 70d2a6ba..c19fa12f 100644 --- a/tests/core/deck.cpp +++ b/tests/core/deck.cpp @@ -2,6 +2,7 @@ * Copyright 2013 (c) Anna Schumaker. */ #include +#include #include #include #include "test.h" @@ -18,6 +19,7 @@ static void test_init() test_equal(deck :: next(), TRACK_NULL); test_cp_data_dir(); + filter_init(); tags :: init(); library :: init(); deck :: init(); diff --git a/tests/core/filter.cpp b/tests/core/filter.cpp index c657ac40..c12d80e8 100644 --- a/tests/core/filter.cpp +++ b/tests/core/filter.cpp @@ -14,6 +14,7 @@ static void do_test_add(const std::string &text, const std::string &lc) static void test_addition() { + filter_init(); do_test_add("It's dangerous to go alone! Take this...", "its dangerous to go alone take this"); do_test_add("DODONGO DISLIKES SMOKE.", @@ -80,6 +81,7 @@ static void test_search() unsigned int res6[] = {0, 1, 8}; do_test_search("d", 3, res6); + filter_deinit(); } DECLARE_UNIT_TESTS( diff --git a/tests/core/index.cpp b/tests/core/index.cpp index 6ac586da..450a32f4 100644 --- a/tests/core/index.cpp +++ b/tests/core/index.cpp @@ -54,12 +54,14 @@ static void test_entry() static void test_stress(unsigned int N) { - Index index("stress.idx", false); index_entry *ie, *ie2; std::string key; unsigned int i; + Index index; char c; + index_init(&index, "stress.idx", false); + /* index_insert() */ for (c = 'a'; c <= 'z'; c++) { key = c; @@ -95,6 +97,8 @@ static void test_stress(unsigned int N) } test_loop_passed(); index_remove(&index, "ZZ", 42); test_equal(index.db_size, 26); + + db_deinit(&index); } static void test_basics() { test_stress(10); } diff --git a/tests/core/library.cpp b/tests/core/library.cpp index 5cfc8e49..5fd8e874 100644 --- a/tests/core/library.cpp +++ b/tests/core/library.cpp @@ -1,6 +1,7 @@ /* * Copyright 2013 (c) Anna Schumaker. */ +#include #include #include #include @@ -18,6 +19,7 @@ static void test_init() test_equal(q->has_flag(Q_REPEAT), true); test_cp_data_dir(); + filter_init(); tags :: init(); library :: init(); diff --git a/tests/core/playlist.cpp b/tests/core/playlist.cpp index a33305fd..7f4c7688 100644 --- a/tests/core/playlist.cpp +++ b/tests/core/playlist.cpp @@ -1,6 +1,7 @@ /* * Copyright 2013 (c) Anna Schumaker. */ +#include #include #include #include @@ -23,6 +24,7 @@ static void test_init() playlist :: init(); test_cp_data_dir(); + filter_init(); tags :: init(); library :: init(); playlist :: init(); diff --git a/tests/core/queue.cpp b/tests/core/queue.cpp index 0758cbf8..16b0cd82 100644 --- a/tests/core/queue.cpp +++ b/tests/core/queue.cpp @@ -1,6 +1,7 @@ /* * Copyright 2014 (c) Anna Schumaker. */ +#include #include extern "C" { #include @@ -90,6 +91,7 @@ void test_add_remove() Track *track; test_cp_data_dir(); + filter_init(); tags :: init(); test_equal(q.length(), expected); diff --git a/tests/core/tags/track.cpp b/tests/core/tags/track.cpp index 165db865..19d6e271 100644 --- a/tests/core/tags/track.cpp +++ b/tests/core/tags/track.cpp @@ -63,6 +63,7 @@ static void test_track_tag_constructor() { file f; + filter_init(); tags :: init(); album = tags :: get_album("Hyrule Symphony", 1998); artist = tags :: get_artist("Koji Kondo");