design: Update design
- Save recent database changes - Move the idle queue after the database - Put file class definition notation - Update the todo list Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
13313482d4
commit
8ef1e2f8e6
193
design.txt
193
design.txt
|
@ -180,10 +180,10 @@ On-disk files: (lib/file.cpp)
|
|||
File : ~File()
|
||||
Close the file stream if it is open.
|
||||
|
||||
const char *get_filepath()
|
||||
const char *File : get_filepath()
|
||||
Return the full filepath to the file.
|
||||
|
||||
const unsigned int get_version()
|
||||
const unsigned int File : get_version()
|
||||
Return the file version number.
|
||||
|
||||
bool File : exists()
|
||||
|
@ -217,6 +217,107 @@ On-disk files: (lib/file.cpp)
|
|||
|
||||
|
||||
|
||||
Database: (lib/database.cpp)
|
||||
Ocarina 5.x created a different save file format for each type of
|
||||
data that needed to be stored (preferences, library paths, playlists).
|
||||
I intend to unify everything into a generic file format that can be
|
||||
accessed through a generic database interface. The database code will
|
||||
be in charge of printing the "valid" bit for each DatabaseEntry so that
|
||||
child classes do not need to call into the parent class. If valid ==
|
||||
true, the DatabaseEntry will be streamed out followed by a newline. If
|
||||
valid == false the database will print the next entry in the vector.
|
||||
|
||||
Modules should inherit from the DatabasEntry class and implement their
|
||||
own read() and write() functions. The "valid" field will be stored
|
||||
before these functions are called, and the entry will be skipped if
|
||||
valid is set to false.
|
||||
|
||||
The Database class is a templated class, so code could potentially
|
||||
get messy. Normal class declarations can still exist in the file
|
||||
include/database.h and member functions can be written in the file
|
||||
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:
|
||||
class DatabaseEntry { /* let database modify valid flag */
|
||||
private:
|
||||
bool valid;
|
||||
public:
|
||||
virtual void write(File &) = 0;
|
||||
virtual void read(File &) = 0;
|
||||
};
|
||||
|
||||
File << <CHILD_CLASS_DATA>
|
||||
|
||||
- Database:
|
||||
template <class T>
|
||||
class Database {
|
||||
private:
|
||||
unsigned int _size; /* Number of valid rows */
|
||||
File filename;
|
||||
vector<T> db;
|
||||
public:
|
||||
Database::Database(filename);
|
||||
void load();
|
||||
void save();
|
||||
|
||||
unsigned int insert(T);
|
||||
void delete(unsigned int);
|
||||
unsigned int size();
|
||||
unsigned int num_rows();
|
||||
|
||||
unsigned int first();
|
||||
unsigned int last();
|
||||
unsigned int next();
|
||||
T &operator[](unsigned int);
|
||||
};
|
||||
|
||||
File << db.size() << endl
|
||||
File << INDEX_0 << db[INDEX_0].valid << db[INDEX_0] << endl;
|
||||
File << Index_1 << db[INDEX_1].valid << db[INDEX_1] << endl;
|
||||
...
|
||||
|
||||
- API:
|
||||
Database : Database(filename);
|
||||
Initializes database to use ~/.ocarina{-debug}/filename.
|
||||
|
||||
void Database : load();
|
||||
Reads data from file.
|
||||
|
||||
void Database : save();
|
||||
Saves data to file.
|
||||
|
||||
template <class T>
|
||||
unsigned int Database : insert(T &);
|
||||
Adds a new item to the db, returns the id of the item.
|
||||
|
||||
void Database : delete(unsigned int index);
|
||||
Mark db[index] as invalid (quick deletion).
|
||||
|
||||
unsigned int Database : size();
|
||||
Returns number of valid rows in the database.
|
||||
|
||||
unsigned int Database : num_rows();
|
||||
Return db.size().
|
||||
|
||||
unsigned int Database : first();
|
||||
Return the id to the first valid row or return db.size()
|
||||
if there are no valid rows.
|
||||
|
||||
unsigned int Database : last();
|
||||
Return the id of the last valid row or return db.size()
|
||||
if there are no valid rows.
|
||||
|
||||
unsigned int Database : next(unsigned int &id)
|
||||
Return the id of the next valid row or return db.size()
|
||||
if there are no remaining valid rows.
|
||||
|
||||
template <class T>
|
||||
T &Database : operator[unsigned int index]
|
||||
Return a reference to db[index].
|
||||
|
||||
|
||||
|
||||
Idle queue: (lib/idle.cpp)
|
||||
The idle queue is used to schedule tasks to run at a later time. Idle
|
||||
tasks must inherit from the IdleBase class so that multiple templated
|
||||
|
@ -269,89 +370,6 @@ Idle queue: (lib/idle.cpp)
|
|||
|
||||
|
||||
|
||||
Database: (lib/database.cpp)
|
||||
Ocarina 5.x created a different save file format for each type of
|
||||
data that needed to be stored (preferences, library paths, playlists).
|
||||
I intend to unify everything into a generic file format that can be
|
||||
accessed through a generic database interface. The database code will
|
||||
be in charge of printing the "valid" bit for each DatabaseEntry so that
|
||||
child classes do not need to call into the parent class. If valid ==
|
||||
true, the DatabaseEntry will be streamed out followed by a newline. If
|
||||
valid == false the database will print the next entry in the vector.
|
||||
|
||||
Modules should inherit from the DatabasEntry class and implement their
|
||||
own read() and write() functions. The "valid" field will be stored
|
||||
before these functions are called, and the entry will be skipped if
|
||||
valid is set to false.
|
||||
|
||||
The Database class is a templated class, so code could potentially
|
||||
get messy. Normal class declarations can still exist in the file
|
||||
include/database.h and member functions can be written in the file
|
||||
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:
|
||||
class DatabaseEntry { /* let database modify valid flag */
|
||||
private:
|
||||
bool valid;
|
||||
public:
|
||||
virtual File &operator>>(File &) = 0;
|
||||
virtual File &operator<<(File &) = 0;
|
||||
friend class Database;
|
||||
};
|
||||
|
||||
File << <CHILD_CLASS_DATA>
|
||||
|
||||
- Database:
|
||||
template <class T>
|
||||
class Database {
|
||||
private:
|
||||
unsigned int _size; /* Number of valid rows */
|
||||
File filename;
|
||||
vector<T> db;
|
||||
public:
|
||||
Database::Database(filename);
|
||||
void load();
|
||||
void save();
|
||||
unsigned int insert(T);
|
||||
void delete(unsigned int);
|
||||
const unsigned int &size();
|
||||
T &operator[](unsigned int);
|
||||
};
|
||||
|
||||
File << db.size() << endl
|
||||
File << INDEX_0 << db[INDEX_0].valid << db[INDEX_0] << endl;
|
||||
File << Index_1 << db[INDEX_1].valid << db[INDEX_1] << endl;
|
||||
...
|
||||
|
||||
- API:
|
||||
Database.Database(filename);
|
||||
Initializes database to use ~/.ocarina{-debug}/filename.
|
||||
|
||||
void Database.load();
|
||||
Reads data from file. Call after static initialization of
|
||||
Ocarina to ensure idle tasks are configured so loading can
|
||||
happen at a later time.
|
||||
|
||||
void Database.save();
|
||||
Saves data to file.
|
||||
|
||||
template <class T>
|
||||
unsigned int Database.insert(T &);
|
||||
Adds a new item to the db, returns the id of the item
|
||||
|
||||
void Database.delete(unsigned int index);
|
||||
Mark db[index] as invalid (quick deletion)
|
||||
|
||||
unsigned Database.size();
|
||||
Returns number of valid rows in the database
|
||||
|
||||
template <class T>
|
||||
T &Database.operator[unsigned int index]
|
||||
Return a reference to db[index]
|
||||
|
||||
|
||||
|
||||
Index: (lib/index.cpp)
|
||||
An inverted index allows me to map multiple values to a single key.
|
||||
|
||||
|
@ -749,3 +767,8 @@ Future work:
|
|||
Keep a list of fields that the user has selected and place new
|
||||
fields in the front of this list. Use a recursive stable sort
|
||||
to do the sorting.
|
||||
|
||||
- Better design file format: (6.1)
|
||||
Todo list in each document instead of all at once in the footer
|
||||
XML?
|
||||
Code formatting?
|
||||
|
|
|
@ -84,10 +84,10 @@ On-disk files: (lib/file.cpp)
|
|||
File : ~File()
|
||||
Close the file stream if it is open.
|
||||
|
||||
const char *get_filepath()
|
||||
const char *File : get_filepath()
|
||||
Return the full filepath to the file.
|
||||
|
||||
const unsigned int get_version()
|
||||
const unsigned int File : get_version()
|
||||
Return the file version number.
|
||||
|
||||
bool File : exists()
|
||||
|
|
|
@ -52,3 +52,8 @@ Future work:
|
|||
Keep a list of fields that the user has selected and place new
|
||||
fields in the front of this list. Use a recursive stable sort
|
||||
to do the sorting.
|
||||
|
||||
- Better design file format: (6.1)
|
||||
Todo list in each document instead of all at once in the footer
|
||||
XML?
|
||||
Code formatting?
|
||||
|
|
Loading…
Reference in New Issue