Database: Switched from file names to Datafile objects

This commit is contained in:
Paul Beckingham 2016-03-19 08:55:28 -04:00
parent eebc2afaaf
commit b2f470d113
2 changed files with 16 additions and 9 deletions

View file

@ -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 ();
}

View file

@ -27,6 +27,7 @@
#ifndef INCLUDED_DATABASE
#define INCLUDED_DATABASE
#include <Datafile.h>
#include <vector>
#include <string>
@ -41,9 +42,9 @@ private:
std::string currentDataFile () const;
private:
std::string _location {"~/.timewarrior/data"};
std::string _current {};
std::vector <std::string> _data_files {};
std::string _location {"~/.timewarrior/data"};
std::string _current {};
std::vector <Datafile> _files {};
};
#endif