core/index: Move index_init() out of the Index class

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-09-29 16:25:16 -04:00
parent a580e5cdb5
commit 7dcfc2ba78
14 changed files with 34 additions and 16 deletions

View File

@ -4,6 +4,7 @@
#include <core/audio.h>
#include <core/core.h>
#include <core/deck.h>
#include <core/filter.h>
#include <core/library.h>
#include <core/playlist.h>
#include <core/tags/tags.h>
@ -11,6 +12,7 @@
void core :: init()
{
filter_init();
tags :: init();
library :: init();
playlist :: init();

View File

@ -11,7 +11,10 @@ extern "C" {
#include <algorithm>
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)
{

View File

@ -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)

View File

@ -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<unsigned int>::iterator it;
index_init(&playlist_db, "playlist.db", true);
db_load(&playlist_db);
index_entry *ent = get_tracks("Banned");

View File

@ -57,4 +57,7 @@ namespace filter {
};
void filter_init();
void filter_deinit();
#endif /* OCARINA_CORE_FILTER_H */

View File

@ -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<index_entry> {
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<index_entry> {};
/* 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);

View File

@ -2,6 +2,7 @@
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/audio.h>
#include <core/filter.h>
#include <core/library.h>
#include <core/tags/tags.h>
#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();

View File

@ -2,6 +2,7 @@
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/deck.h>
#include <core/filter.h>
#include <core/library.h>
#include <core/tags/tags.h>
#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();

View File

@ -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(

View File

@ -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); }

View File

@ -1,6 +1,7 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/filter.h>
#include <core/idle.h>
#include <core/library.h>
#include <core/tags/tags.h>
@ -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();

View File

@ -1,6 +1,7 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/filter.h>
#include <core/library.h>
#include <core/playlist.h>
#include <core/tags/tags.h>
@ -23,6 +24,7 @@ static void test_init()
playlist :: init();
test_cp_data_dir();
filter_init();
tags :: init();
library :: init();
playlist :: init();

View File

@ -1,6 +1,7 @@
/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/filter.h>
#include <core/queue.h>
extern "C" {
#include <core/random.h>
@ -90,6 +91,7 @@ void test_add_remove()
Track *track;
test_cp_data_dir();
filter_init();
tags :: init();
test_equal(q.length(), expected);

View File

@ -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");