Design: Create a preferences namespace

This will be used to store various values for the user.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2013-06-28 00:12:56 -04:00 committed by Anna Schumaker
parent 5312853b86
commit 310c9ad395
1 changed files with 44 additions and 23 deletions

View File

@ -24,6 +24,7 @@ Files:
index.h
library.h
playlist.h
prefs.h
ocarina/lib/
database.cpp
file.cpp
@ -31,6 +32,7 @@ Files:
index.cpp
library.cpp
playlist.cpp
prefs.cpp
ocarina/tests/
$HOME/.ocarina{-debug}/
@ -57,19 +59,19 @@ On-disk files: (lib/file.cpp)
Items should be written to a file with either a space or new line
separating multiple values.
Notation:
- Notation:
File << aaaaa << bbbbb << endl is translated into "aaaaa bbbbb\n"
File version:
- File version:
#define FILE_VERSION 4
Open mode:
- Open mode:
enum OpenMode {
OPEN_READ,
OPEN_WRITE,
}
File:
- File:
class File {
private:
union {
@ -87,10 +89,10 @@ File:
getline(string &);
}
File format:
- File format:
File << FILE_VERSION << <OTHER_DATA>
API:
- API:
File : File(filepath)
Resolve filepath to ~/.ocarina{-debug}/filepath
File : open(mode)
@ -127,7 +129,7 @@ Database: (lib/database.cpp)
include/database.hpp, which will be included by database.h. Any
function not relying on a template can be written in lib/database.cpp.
DatabaseEntry:
- DatabaseEntry:
class DatabaseEntry { /* let database modify valid flag */
private:
bool valid;
@ -139,7 +141,7 @@ DatabaseEntry:
File << <CHILD_CLASS_DATA>
Database:
- Database:
template <class T>
class Database {
private:
@ -161,7 +163,7 @@ Database:
File << Index_1 << db[INDEX_1].valid << db[INDEX_1] << endl;
...
API:
- API:
Database.Database(filename);
Initializes database to use ~/.ocarina{-debug}/filename
Database.load();
@ -183,7 +185,7 @@ API:
Index: (lib/index.cpp)
An inverted index allows me to map multiple values to a single key.
Index:
- Index:
class Index {
private:
map<string, set<int>>
@ -194,14 +196,15 @@ Index:
void save();
void insert(key, int);
void delete(key, int);
void replace(key, int);
const set<string> &keys();
const set<int> &operator[](string);
};
File << key << map[key].size() << endl;
File << int_0 << int_1 << ... << int_n << endl;
File << key << endl;
File << map[key].size() << int_0 << int_1 << ... << int_n << endl;
API:
- API:
Index.Index(filename);
Initializes an index using ~/.ocarina{-debug}/filename
Index.load();
@ -217,6 +220,9 @@ API:
1) Remove int from the set of values associated with key
2) Do not delete key if set is empty
3) Index.save()
Index.replace(key, int)
1) map[key].clear()
2) insert(key, int)
Index.keys();
Return a set of index keys
Index.operator[](string key);
@ -233,7 +239,7 @@ Library: (lib/library.cpp)
When a library : Track is created, it should be added to the "Library"
group if it is NOT a member of the banned songs group.
Album:
- Album:
class library :: Album : public DatabaseEntry {
string name;
short year;
@ -241,21 +247,21 @@ Album:
File << year << name
Artist:
- Artist:
class library :: Artist : public DatabaseEntry {
string name;
};
File << name
Genre:
- Genre:
class library :: Genre : public DatabaseEntry {
string name;
};
File << name
Path:
- Path:
class library :: Path : public DatabaseEntry {
string root_path;
bool enabled;
@ -263,7 +269,7 @@ Path:
File << enabled << root_path
Track:
- Track:
class library :: Track : public DatabaseEntry {
unsigned int artist_id;
unsigned int album_id;
@ -286,7 +292,7 @@ Track:
File << title << endl;
File << filepath << endl;
Track: /* This struct lies outside the library namespace */
- Track: /* This struct lies outside the library namespace */
struct Track {
library :: Album *album;
library :: Artist *artist;
@ -295,14 +301,14 @@ Track: /* This struct lies outside the library namespace */
library :: Track *track;
};
Databases:
- Databases:
Database<library :: Album> album_db(album.db);
Database<library :: Artist> artist_db(artist.db);
Database<library :: Album> genre_db(genre.db);
Database<library :: Library> library_db(library.db);
Database<library :: Track> track_db(track.db);
Updating algorithm:
- Updating algorithm:
set<pair<lib_id, track_path>> known_tracks;
1) For each track currently in the library, check if the track exists
@ -345,10 +351,10 @@ Groups: (lib/group.cpp)
that cannot be deleted by the user based on library status. Similar
to the library, groups should exist in their own namespace.
Index:
- Index:
Index group_idx(groups.idx)
Default groups:
- Default groups:
All music
All tracks are added to this group
Library
@ -372,6 +378,21 @@ Default groups:
Preferences: (lib/prefs.cpp)
Preferences make use of a special index where the set<int> is always
size 1. Preferences will be in the prefs namespace.
- Index:
Index prefs(prefs.idx);
- API:
prefs :: set(string, val);
prefs.replace(string, val);
prefs :: get(string)
return prefs[string].begin()
Playlist: (lib/playlist.cpp)
A playlist is a simple list of songs that can be played either randomly
or in a user-defined order. It would probably be best to use a linked