From 8ccbad20cc2d5a26634365f997d327fc5e6ccb39 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sun, 27 Oct 2013 17:39:34 -0400 Subject: [PATCH] database: Mark rows valid when inserted It doesn't make sense to need to set this value outside of the database code like I had been doing. So when a new row is inserted mark it as valid right away. Signed-off-by: Anna Schumaker --- design/database.txt | 6 +++--- include/database.hpp | 1 + tests/database/database.cpp | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/design/database.txt b/design/database.txt index fdb29cc4..6a5f40f8 100644 --- a/design/database.txt +++ b/design/database.txt @@ -100,9 +100,9 @@ Database: (lib/database.cpp) template unsigned int Database :: insert(T &); - Adds a new item to the db, returns the id of the item. - if DB_UNIQUE is set, check if the item already exists in the - DB and return it's ID instead of adding a new item. + Adds a new item to the db, marks it as valid, and returns the + id of the item. if DB_UNIQUE is set, check if the item already + exists in the DB and return it's ID instead of adding a new item. void Database :: delete(unsigned int index); Mark db[index] as invalid (quick deletion). diff --git a/include/database.hpp b/include/database.hpp index 82693961..b91daca1 100644 --- a/include/database.hpp +++ b/include/database.hpp @@ -88,6 +88,7 @@ unsigned int Database :: insert(T val) } } db.push_back(val); + db[_size].valid = true; _size++; return db.size() - 1; } diff --git a/tests/database/database.cpp b/tests/database/database.cpp index 2705e19d..ed31c170 100644 --- a/tests/database/database.cpp +++ b/tests/database/database.cpp @@ -23,7 +23,6 @@ DBTest :: DBTest() DBTest :: DBTest(unsigned int val) { value = val; - valid = true; } void DBTest :: write(File &file)