From fee08b1f94e6edf41c2a5880edd8f0f00711afe7 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 10 Aug 2013 23:38:57 -0400 Subject: [PATCH] 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 --- config | 21 ++++++++++++--------- design.txt | 3 +-- design/database.txt | 3 +-- include/database.h | 18 ++++++++++++++++++ lib/Sconscript | 4 ++++ lib/database.cpp | 13 +++++++++++++ tests/Sconscript | 2 +- tests/database/Sconscript | 6 ++++++ tests/database/database.cpp | 10 ++++++++++ 9 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 include/database.h create mode 100644 lib/database.cpp create mode 100644 tests/database/Sconscript create mode 100644 tests/database/database.cpp diff --git a/config b/config index af83e173..57b856a1 100644 --- a/config +++ b/config @@ -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() diff --git a/design.txt b/design.txt index d4c78c79..4d2d29af 100644 --- a/design.txt +++ b/design.txt @@ -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 diff --git a/design/database.txt b/design/database.txt index 009017a6..01ffba57 100644 --- a/design/database.txt +++ b/design/database.txt @@ -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 diff --git a/include/database.h b/include/database.h new file mode 100644 index 00000000..2c351e4c --- /dev/null +++ b/include/database.h @@ -0,0 +1,18 @@ +/* + * Copyright 2013 (c) Anna Schumaker. + */ +#ifndef OCARINA_DATABASE_H +#define OCARINA_DATABASE_H + +#include + +class Database { + private: + File file; + + public: + Database(std::string); + ~Database(); +}; + +#endif /* OCARINA_DATABASE_H */ diff --git a/lib/Sconscript b/lib/Sconscript index 5294eb82..b68075fe 100644 --- a/lib/Sconscript +++ b/lib/Sconscript @@ -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") ] diff --git a/lib/database.cpp b/lib/database.cpp new file mode 100644 index 00000000..f0aa094a --- /dev/null +++ b/lib/database.cpp @@ -0,0 +1,13 @@ +/* + * Copyright 2013 (c) Anna Schumaker. + */ +#include + +Database :: Database(std::string filepath) + : file(filepath, FILE_TYPE_DATA) +{ +} + +Database :: ~Database() +{ +} diff --git a/tests/Sconscript b/tests/Sconscript index 8f89680b..bf975316 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -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 diff --git a/tests/database/Sconscript b/tests/database/Sconscript new file mode 100644 index 00000000..9f79c0c5 --- /dev/null +++ b/tests/database/Sconscript @@ -0,0 +1,6 @@ +#!/usr/bin/python +Import("Test", "CONFIG") + +CONFIG.DATABASE = True + +Test("database", "database.cpp") diff --git a/tests/database/database.cpp b/tests/database/database.cpp new file mode 100644 index 00000000..4903fd79 --- /dev/null +++ b/tests/database/database.cpp @@ -0,0 +1,10 @@ +/* + * Copyright 2013 (c) Anna Schumaker. + */ +#include + +int main(int argc, char **argv) +{ + Database db("test.db"); + return 0; +}