From b2f470d113bf97bb73f5ac1386bc1e22d08b6007 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 19 Mar 2016 08:55:28 -0400 Subject: [PATCH] Database: Switched from file names to Datafile objects --- src/Database.cpp | 18 ++++++++++++------ src/Database.h | 7 ++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Database.cpp b/src/Database.cpp index 924fdd76..bc92a70f 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -36,17 +36,23 @@ void Database::initialize (const std::string& location) { _location = location; - // _data_files[0] is always the current one, which may not exist. + // _data_files[0] is always the current file. _current = currentDataFile (); - _data_files.push_back (_current); + Datafile currentFile; + currentFile.initialize (_current); + _files.push_back (currentFile); Directory d (_location); for (const auto& file : d.list ()) { - if (1 /* looks like one of our data files */) + if (1 /* TODO looks like one of our data files */) { if (file != _current) - _data_files.push_back (file); + { + Datafile oldFile; + oldFile.initialize (file); + _files.push_back (oldFile); + } } } @@ -58,8 +64,8 @@ std::string Database::dump () const { std::stringstream out; out << "Database\n"; - for (const auto& file : _data_files) - out << " Data: " << file << "\n"; + for (const auto& file : _files) + out << " Datafile: " << file.name () << "\n"; return out.str (); } diff --git a/src/Database.h b/src/Database.h index 1df2ebd6..095afa17 100644 --- a/src/Database.h +++ b/src/Database.h @@ -27,6 +27,7 @@ #ifndef INCLUDED_DATABASE #define INCLUDED_DATABASE +#include #include #include @@ -41,9 +42,9 @@ private: std::string currentDataFile () const; private: - std::string _location {"~/.timewarrior/data"}; - std::string _current {}; - std::vector _data_files {}; + std::string _location {"~/.timewarrior/data"}; + std::string _current {}; + std::vector _files {}; }; #endif