database: Begin database code

I've been excited about this!  I think it'll be a better design than
what I had for Ocarina 5.x.

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2013-08-10 23:38:57 -04:00 committed by Anna Schumaker
parent 857598dea7
commit fee08b1f94
9 changed files with 66 additions and 14 deletions

21
config
View File

@ -21,23 +21,26 @@ env.Append(LINKCOMSTR = "Linking $TARGET")
class Config:
# Set up reasonable defaults
def __init__(self):
self.VERSION = CONFIG_VERSION
self.DEBUG = CONFIG_DEBUG
self.ENV = CONFIG_ENV
self.FILE = False
self.TEST = False
self.VERSION = CONFIG_VERSION
self.DEBUG = CONFIG_DEBUG
self.ENV = CONFIG_ENV
self.DATABASE = False
self.FILE = False
self.TEST = False
def package(self, name):
env.ParseConfig("pkg-config --cflags --libs %s" % name)
def reconfigure(self):
env.Replace( CCFLAGS = self.ENV )
if self.FILE: env.Append( CCFLAGS = "-DCONFIG_FILE" )
if self.TEST: env.Append( CCFLAGS = "-DCONFIG_TEST" )
if self.DATABASE: env.Append( CCFLAGS = "-DCONFIG_DATABASE" )
if self.FILE: env.Append( CCFLAGS = "-DCONFIG_FILE" )
if self.TEST: env.Append( CCFLAGS = "-DCONFIG_TEST" )
def reset(self):
self.FILE = False
self.TEST = False
self.DATABASE = False
self.FILE = False
self.TEST = False
self.reconfigure()
CONFIG = Config()

View File

@ -321,8 +321,7 @@ Database: (lib/database.cpp)
- API:
Database.Database(filename);
Initializes database to use ~/.ocarina{-debug}/filename. Pass
an empty string if you do not want this database to be saved.
Initializes database to use ~/.ocarina{-debug}/filename.
void Database.load();
Reads data from file. Call after static initialization of

View File

@ -65,8 +65,7 @@ Database: (lib/database.cpp)
- API:
Database.Database(filename);
Initializes database to use ~/.ocarina{-debug}/filename. Pass
an empty string if you do not want this database to be saved.
Initializes database to use ~/.ocarina{-debug}/filename.
void Database.load();
Reads data from file. Call after static initialization of

18
include/database.h Normal file
View File

@ -0,0 +1,18 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#ifndef OCARINA_DATABASE_H
#define OCARINA_DATABASE_H
#include <file.h>
class Database {
private:
File file;
public:
Database(std::string);
~Database();
};
#endif /* OCARINA_DATABASE_H */

View File

@ -3,6 +3,10 @@ Import("env", "CONFIG")
build = []
if CONFIG.DATABASE:
CONFIG.FILE = True
build += [ env.Object("database.cpp") ]
if CONFIG.FILE:
CONFIG.package("glib-2.0")
build += [ env.Object("file.cpp") ]

13
lib/database.cpp Normal file
View File

@ -0,0 +1,13 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <database.h>
Database :: Database(std::string filepath)
: file(filepath, FILE_TYPE_DATA)
{
}
Database :: ~Database()
{
}

View File

@ -43,7 +43,7 @@ Export("Test")
# Read SConscript files
scripts = [ "basic", "file" ]
scripts = [ "basic", "file", "database" ]
for s in scripts:
CONFIG.reset()
CONFIG.TEST = True

View File

@ -0,0 +1,6 @@
#!/usr/bin/python
Import("Test", "CONFIG")
CONFIG.DATABASE = True
Test("database", "database.cpp")

View File

@ -0,0 +1,10 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <database.h>
int main(int argc, char **argv)
{
Database db("test.db");
return 0;
}