core/index: Move index_init() out of the Index class
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
a580e5cdb5
commit
7dcfc2ba78
|
@ -4,6 +4,7 @@
|
||||||
#include <core/audio.h>
|
#include <core/audio.h>
|
||||||
#include <core/core.h>
|
#include <core/core.h>
|
||||||
#include <core/deck.h>
|
#include <core/deck.h>
|
||||||
|
#include <core/filter.h>
|
||||||
#include <core/library.h>
|
#include <core/library.h>
|
||||||
#include <core/playlist.h>
|
#include <core/playlist.h>
|
||||||
#include <core/tags/tags.h>
|
#include <core/tags/tags.h>
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
|
|
||||||
void core :: init()
|
void core :: init()
|
||||||
{
|
{
|
||||||
|
filter_init();
|
||||||
tags :: init();
|
tags :: init();
|
||||||
library :: init();
|
library :: init();
|
||||||
playlist :: init();
|
playlist :: init();
|
||||||
|
|
|
@ -11,7 +11,10 @@ extern "C" {
|
||||||
|
|
||||||
#include <algorithm>
|
#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)
|
const std::string filter :: add(const std::string &text, unsigned int index)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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)
|
index_entry *index_insert(Index *index, const gchar *key, unsigned int value)
|
||||||
|
|
|
@ -78,7 +78,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static Index playlist_db("playlist.db", true);
|
static Index playlist_db;
|
||||||
static PlaylistQueue playlist_q;
|
static PlaylistQueue playlist_q;
|
||||||
static std::string cur_plist;
|
static std::string cur_plist;
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@ void playlist :: init()
|
||||||
{
|
{
|
||||||
std::set<unsigned int>::iterator it;
|
std::set<unsigned int>::iterator it;
|
||||||
|
|
||||||
|
index_init(&playlist_db, "playlist.db", true);
|
||||||
db_load(&playlist_db);
|
db_load(&playlist_db);
|
||||||
|
|
||||||
index_entry *ent = get_tracks("Banned");
|
index_entry *ent = get_tracks("Banned");
|
||||||
|
|
|
@ -57,4 +57,7 @@ namespace filter {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void filter_init();
|
||||||
|
void filter_deinit();
|
||||||
|
|
||||||
#endif /* OCARINA_CORE_FILTER_H */
|
#endif /* OCARINA_CORE_FILTER_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
|
* An Index is a special Database for mapping std::strings to a std::set of
|
||||||
* integer identifiers.
|
* integer identifiers.
|
||||||
*/
|
*/
|
||||||
class Index : public database<index_entry> {
|
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);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
/* Initialize an Index. */
|
||||||
|
void index_init(Index *, const gchar *, bool);
|
||||||
|
|
||||||
/* Add a value to an index item with the specified key. */
|
/* Add a value to an index item with the specified key. */
|
||||||
index_entry *index_insert(Index *, const gchar *, unsigned int);
|
index_entry *index_insert(Index *, const gchar *, unsigned int);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* Copyright 2013 (c) Anna Schumaker.
|
* Copyright 2013 (c) Anna Schumaker.
|
||||||
*/
|
*/
|
||||||
#include <core/audio.h>
|
#include <core/audio.h>
|
||||||
|
#include <core/filter.h>
|
||||||
#include <core/library.h>
|
#include <core/library.h>
|
||||||
#include <core/tags/tags.h>
|
#include <core/tags/tags.h>
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
@ -82,6 +83,7 @@ void test_init()
|
||||||
track = audio :: current_track();
|
track = audio :: current_track();
|
||||||
test_equal(track, TRACK_NULL);
|
test_equal(track, TRACK_NULL);
|
||||||
|
|
||||||
|
filter_init();
|
||||||
tags :: init();
|
tags :: init();
|
||||||
library :: init();
|
library :: init();
|
||||||
audio :: init();
|
audio :: init();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* Copyright 2013 (c) Anna Schumaker.
|
* Copyright 2013 (c) Anna Schumaker.
|
||||||
*/
|
*/
|
||||||
#include <core/deck.h>
|
#include <core/deck.h>
|
||||||
|
#include <core/filter.h>
|
||||||
#include <core/library.h>
|
#include <core/library.h>
|
||||||
#include <core/tags/tags.h>
|
#include <core/tags/tags.h>
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
@ -18,6 +19,7 @@ static void test_init()
|
||||||
test_equal(deck :: next(), TRACK_NULL);
|
test_equal(deck :: next(), TRACK_NULL);
|
||||||
|
|
||||||
test_cp_data_dir();
|
test_cp_data_dir();
|
||||||
|
filter_init();
|
||||||
tags :: init();
|
tags :: init();
|
||||||
library :: init();
|
library :: init();
|
||||||
deck :: init();
|
deck :: init();
|
||||||
|
|
|
@ -14,6 +14,7 @@ static void do_test_add(const std::string &text, const std::string &lc)
|
||||||
|
|
||||||
static void test_addition()
|
static void test_addition()
|
||||||
{
|
{
|
||||||
|
filter_init();
|
||||||
do_test_add("It's dangerous to go alone! Take this...",
|
do_test_add("It's dangerous to go alone! Take this...",
|
||||||
"its dangerous to go alone take this");
|
"its dangerous to go alone take this");
|
||||||
do_test_add("DODONGO DISLIKES SMOKE.",
|
do_test_add("DODONGO DISLIKES SMOKE.",
|
||||||
|
@ -80,6 +81,7 @@ static void test_search()
|
||||||
|
|
||||||
unsigned int res6[] = {0, 1, 8};
|
unsigned int res6[] = {0, 1, 8};
|
||||||
do_test_search("d", 3, res6);
|
do_test_search("d", 3, res6);
|
||||||
|
filter_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLARE_UNIT_TESTS(
|
DECLARE_UNIT_TESTS(
|
||||||
|
|
|
@ -54,12 +54,14 @@ static void test_entry()
|
||||||
|
|
||||||
static void test_stress(unsigned int N)
|
static void test_stress(unsigned int N)
|
||||||
{
|
{
|
||||||
Index index("stress.idx", false);
|
|
||||||
index_entry *ie, *ie2;
|
index_entry *ie, *ie2;
|
||||||
std::string key;
|
std::string key;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
Index index;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
|
index_init(&index, "stress.idx", false);
|
||||||
|
|
||||||
/* index_insert() */
|
/* index_insert() */
|
||||||
for (c = 'a'; c <= 'z'; c++) {
|
for (c = 'a'; c <= 'z'; c++) {
|
||||||
key = c;
|
key = c;
|
||||||
|
@ -95,6 +97,8 @@ static void test_stress(unsigned int N)
|
||||||
} test_loop_passed();
|
} test_loop_passed();
|
||||||
index_remove(&index, "ZZ", 42);
|
index_remove(&index, "ZZ", 42);
|
||||||
test_equal(index.db_size, 26);
|
test_equal(index.db_size, 26);
|
||||||
|
|
||||||
|
db_deinit(&index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_basics() { test_stress(10); }
|
static void test_basics() { test_stress(10); }
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2013 (c) Anna Schumaker.
|
* Copyright 2013 (c) Anna Schumaker.
|
||||||
*/
|
*/
|
||||||
|
#include <core/filter.h>
|
||||||
#include <core/idle.h>
|
#include <core/idle.h>
|
||||||
#include <core/library.h>
|
#include <core/library.h>
|
||||||
#include <core/tags/tags.h>
|
#include <core/tags/tags.h>
|
||||||
|
@ -18,6 +19,7 @@ static void test_init()
|
||||||
test_equal(q->has_flag(Q_REPEAT), true);
|
test_equal(q->has_flag(Q_REPEAT), true);
|
||||||
|
|
||||||
test_cp_data_dir();
|
test_cp_data_dir();
|
||||||
|
filter_init();
|
||||||
tags :: init();
|
tags :: init();
|
||||||
library :: init();
|
library :: init();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2013 (c) Anna Schumaker.
|
* Copyright 2013 (c) Anna Schumaker.
|
||||||
*/
|
*/
|
||||||
|
#include <core/filter.h>
|
||||||
#include <core/library.h>
|
#include <core/library.h>
|
||||||
#include <core/playlist.h>
|
#include <core/playlist.h>
|
||||||
#include <core/tags/tags.h>
|
#include <core/tags/tags.h>
|
||||||
|
@ -23,6 +24,7 @@ static void test_init()
|
||||||
playlist :: init();
|
playlist :: init();
|
||||||
|
|
||||||
test_cp_data_dir();
|
test_cp_data_dir();
|
||||||
|
filter_init();
|
||||||
tags :: init();
|
tags :: init();
|
||||||
library :: init();
|
library :: init();
|
||||||
playlist :: init();
|
playlist :: init();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2014 (c) Anna Schumaker.
|
* Copyright 2014 (c) Anna Schumaker.
|
||||||
*/
|
*/
|
||||||
|
#include <core/filter.h>
|
||||||
#include <core/queue.h>
|
#include <core/queue.h>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <core/random.h>
|
#include <core/random.h>
|
||||||
|
@ -90,6 +91,7 @@ void test_add_remove()
|
||||||
Track *track;
|
Track *track;
|
||||||
|
|
||||||
test_cp_data_dir();
|
test_cp_data_dir();
|
||||||
|
filter_init();
|
||||||
tags :: init();
|
tags :: init();
|
||||||
|
|
||||||
test_equal(q.length(), expected);
|
test_equal(q.length(), expected);
|
||||||
|
|
|
@ -63,6 +63,7 @@ static void test_track_tag_constructor()
|
||||||
{
|
{
|
||||||
file f;
|
file f;
|
||||||
|
|
||||||
|
filter_init();
|
||||||
tags :: init();
|
tags :: init();
|
||||||
album = tags :: get_album("Hyrule Symphony", 1998);
|
album = tags :: get_album("Hyrule Symphony", 1998);
|
||||||
artist = tags :: get_artist("Koji Kondo");
|
artist = tags :: get_artist("Koji Kondo");
|
||||||
|
|
Loading…
Reference in New Issue