From 3eb27debfbb6c93ee2b7339893ee24e112dadf66 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 31 Oct 2015 11:44:29 -0400 Subject: [PATCH] core/database: Convert DatabaseEntry class into a struct Signed-off-by: Anna Schumaker --- core/database.cpp | 10 +++++----- include/core/database.h | 11 +++++------ include/core/database.hpp | 6 +++--- include/core/index.h | 2 +- include/core/tags/album.h | 2 +- include/core/tags/artist.h | 2 +- include/core/tags/genre.h | 2 +- include/core/tags/library.h | 2 +- include/core/tags/track.h | 2 +- tests/core/database.cpp | 4 ++-- 10 files changed, 21 insertions(+), 22 deletions(-) diff --git a/core/database.cpp b/core/database.cpp index 6e509ec1..54d998d1 100644 --- a/core/database.cpp +++ b/core/database.cpp @@ -4,14 +4,14 @@ #include -DatabaseEntry :: DatabaseEntry() - : _index(0) +db_entry :: db_entry() + : dbe_index(0) { } -DatabaseEntry :: ~DatabaseEntry() {} +db_entry :: ~db_entry() {} -const unsigned int DatabaseEntry :: index() +const unsigned int db_entry :: index() { - return _index; + return dbe_index; } diff --git a/include/core/database.h b/include/core/database.h index 3870fbb9..3a49f625 100644 --- a/include/core/database.h +++ b/include/core/database.h @@ -16,13 +16,12 @@ extern "C" { * The DatabaseEntry class is the base class for storing * generic data inside a Database. */ -class DatabaseEntry { -public: - unsigned int _index; /**< The location of an item in the Database. */ +struct db_entry { + unsigned int dbe_index; /* The db_entry's position in the database. */ - DatabaseEntry(); /**< Initialize _index to 0. */ - DatabaseEntry(const std::string); - virtual ~DatabaseEntry() = 0; /**< Virtual destructor */ + db_entry(); /**< Initialize _index to 0. */ + db_entry(const std::string); + virtual ~db_entry() = 0; /**< Virtual destructor */ /** * Called to access a DatabaseEntry's index. diff --git a/include/core/database.hpp b/include/core/database.hpp index 876df7eb..91e5b548 100644 --- a/include/core/database.hpp +++ b/include/core/database.hpp @@ -71,7 +71,7 @@ void db_load(struct database *db) db->db_entries[i] = NULL; } else { db->db_entries[i] = new T; - db->db_entries[i]->_index = i; + db->db_entries[i]->dbe_index = i; db->db_entries[i]->read(db->db_file); str = db->db_entries[i]->primary_key(); db->db_keys[str] = i; @@ -88,13 +88,13 @@ T *db_insert(struct database *db, T *item) if (!item) return NULL; - item->_index = db_actual_size(db); + item->dbe_index = db_actual_size(db); db->db_entries.push_back(item); db->db_keys[item->primary_key()] = item->index(); db->db_size++; db_autosave(db); - return db->db_entries[item->_index]; + return db->db_entries[item->dbe_index]; } template diff --git a/include/core/index.h b/include/core/index.h index 884280d1..76851ebb 100644 --- a/include/core/index.h +++ b/include/core/index.h @@ -16,7 +16,7 @@ extern "C" { * The index_entry struct is used to associate a specific key with a set of * integer identifiers. This lets us use a Database as an inverted index. */ -struct index_entry : public DatabaseEntry { +struct index_entry : public db_entry { std::string ie_key; struct set ie_set; diff --git a/include/core/tags/album.h b/include/core/tags/album.h index 76a8192e..5f88dc32 100644 --- a/include/core/tags/album.h +++ b/include/core/tags/album.h @@ -17,7 +17,7 @@ * ... << year2 << GenericTag::write() * ... << year3 << GenericTag::write() */ -struct album : public DatabaseEntry { +struct album : public db_entry { unsigned int al_year; /* This album's year. */ std::string al_name; /* This album's name. */ std::string al_lower; /* This album's name (lowercased). */ diff --git a/include/core/tags/artist.h b/include/core/tags/artist.h index 0ece1247..0d62164c 100644 --- a/include/core/tags/artist.h +++ b/include/core/tags/artist.h @@ -10,7 +10,7 @@ * The Artist tag is used to store the name of artists added * to the tag database. */ -struct artist : public DatabaseEntry { +struct artist : public db_entry { std::string ar_name; /* This artist's name. */ std::string ar_lower; /* This artist's name (lowercased). */ diff --git a/include/core/tags/genre.h b/include/core/tags/genre.h index fbec588f..154eeed4 100644 --- a/include/core/tags/genre.h +++ b/include/core/tags/genre.h @@ -10,7 +10,7 @@ * The Genre tag is used to store the name of genres added * to the tag database. */ -struct genre : public DatabaseEntry { +struct genre : public db_entry { public: std::string ge_name; /* This genre's name. */ std::string ge_lower; /* This genre's name (lowercased). */ diff --git a/include/core/tags/library.h b/include/core/tags/library.h index 86371ea0..e3fcab18 100644 --- a/include/core/tags/library.h +++ b/include/core/tags/library.h @@ -17,7 +17,7 @@ * ... << enabled2 << path2 * ... << enabled3 << path3 */ -struct library : public DatabaseEntry { +struct library : public db_entry { unsigned int li_size; /* This library's track count. */ bool li_enabled;/* True if this library is enabled. */ std::string li_path; /* This library's root path. */ diff --git a/include/core/tags/track.h b/include/core/tags/track.h index 6495f398..520461a1 100644 --- a/include/core/tags/track.h +++ b/include/core/tags/track.h @@ -18,7 +18,7 @@ extern "C" { * The Track tag is used to store information about tracks that * have been added to the tag database. */ -struct track : public DatabaseEntry { +struct track : public db_entry { struct album *tr_album; /* This track's associated album. */ struct artist *tr_artist; /* This track's associated artist. */ struct genre *tr_genre; /* This track's associated genre. */ diff --git a/tests/core/database.cpp b/tests/core/database.cpp index e593b57b..f47b8dc9 100644 --- a/tests/core/database.cpp +++ b/tests/core/database.cpp @@ -10,9 +10,9 @@ /* - * Derive a DatabaseEntry for storing integerss + * Derive a db_entry for storing integerss */ -struct int_entry : public DatabaseEntry { +struct int_entry : public db_entry { unsigned int ie_val; int_entry() : ie_val(0) {};