Database: Now tracks the need to write data with ::_dirty

This commit is contained in:
Paul Beckingham 2016-03-20 12:39:57 -04:00
parent 2cd945e440
commit 8c74b0e1e9
2 changed files with 17 additions and 0 deletions

View file

@ -60,6 +60,16 @@ void Database::initialize (const std::string& location)
// TODO If there is no data file named YYYY—MM.data, then create it. // TODO If there is no data file named YYYY—MM.data, then create it.
} }
////////////////////////////////////////////////////////////////////////////////
void Database::commit ()
{
if (_dirty)
{
_dirty = false;
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Interval Database::getLatestInterval () const Interval Database::getLatestInterval () const
{ {
@ -70,18 +80,21 @@ Interval Database::getLatestInterval () const
void Database::addExclusion (const std::string& exclusion) void Database::addExclusion (const std::string& exclusion)
{ {
_files[0].addExclusion (exclusion); _files[0].addExclusion (exclusion);
_dirty = true;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Database::addInterval (const Interval& interval) void Database::addInterval (const Interval& interval)
{ {
_files[0].addInterval (interval); _files[0].addInterval (interval);
_dirty = true;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Database::modifyInterval (const Interval& interval) void Database::modifyInterval (const Interval& interval)
{ {
_files[0].modifyInterval (interval); _files[0].modifyInterval (interval);
_dirty = true;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -94,6 +107,8 @@ std::string Database::dump () const
<< (file.name () == _current ? " (current)" : "") << (file.name () == _current ? " (current)" : "")
<< "\n"; << "\n";
out << " Dirty: " << (_dirty ? "true" : "false") << "\n";
return out.str (); return out.str ();
} }

View file

@ -37,6 +37,7 @@ class Database
public: public:
Database () = default; Database () = default;
void initialize (const std::string&); void initialize (const std::string&);
void commit ();
Interval getLatestInterval () const; Interval getLatestInterval () const;
@ -53,6 +54,7 @@ private:
std::string _location {"~/.timewarrior/data"}; std::string _location {"~/.timewarrior/data"};
std::string _current {}; std::string _current {};
std::vector <Datafile> _files {}; std::vector <Datafile> _files {};
bool _dirty {false};
}; };
#endif #endif