#9 TI-1: Rename undoTxn*-functions

This commit is contained in:
Thomas Lauf 2018-07-18 21:38:06 +02:00
parent f031bd9d22
commit b8b0bbfeaf
3 changed files with 34 additions and 34 deletions

View file

@ -96,7 +96,7 @@ std::vector <std::string> Database::allLines ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Database::addInterval (const Interval& interval) void Database::addInterval (const Interval& interval)
{ {
undoTxnStart (); startTransaction ();
if (interval.range.is_open ()) if (interval.range.is_open ())
{ {
@ -104,7 +104,7 @@ void Database::addInterval (const Interval& interval)
// created on demand. // created on demand.
auto df = getDatafile (interval.range.start.year (), interval.range.start.month ()); auto df = getDatafile (interval.range.start.year (), interval.range.start.month ());
_files[df].addInterval (interval); _files[df].addInterval (interval);
undoTxn ("interval", "", interval.json ()); recordUndoAction ("interval", "", interval.json ());
} }
else else
{ {
@ -123,17 +123,17 @@ void Database::addInterval (const Interval& interval)
_files[df].addInterval (segmentedInterval); _files[df].addInterval (segmentedInterval);
undoTxn ("interval", "", segmentedInterval.json ()); recordUndoAction ("interval", "", segmentedInterval.json ());
} }
} }
undoTxnEnd (); endTransaction ();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Database::deleteInterval (const Interval& interval) void Database::deleteInterval (const Interval& interval)
{ {
undoTxnStart (); startTransaction ();
auto intervalRange = interval.range; auto intervalRange = interval.range;
for (auto& segment : segmentRange (intervalRange)) for (auto& segment : segmentRange (intervalRange))
@ -150,10 +150,10 @@ void Database::deleteInterval (const Interval& interval)
_files[df].deleteInterval (segmentedInterval); _files[df].deleteInterval (segmentedInterval);
undoTxn ("interval", segmentedInterval.json (), ""); recordUndoAction ("interval", segmentedInterval.json (), "");
} }
undoTxnEnd (); endTransaction ();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -163,17 +163,17 @@ void Database::deleteInterval (const Interval& interval)
// Interval belongs in a different file. // Interval belongs in a different file.
void Database::modifyInterval (const Interval& from, const Interval& to) void Database::modifyInterval (const Interval& from, const Interval& to)
{ {
undoTxnStart (); startTransaction ();
deleteInterval (from); deleteInterval (from);
addInterval (to); addInterval (to);
undoTxnEnd (); endTransaction ();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// The _txn member is a reference count, allowing multiple nested transactions. // The _txn member is a reference count, allowing multiple nested transactions.
// This accommodates the Database::modifyInterval call, that in turn calls // This accommodates the Database::modifyInterval call, that in turn calls
// ::addInterval and ::deleteInterval. // ::addInterval and ::deleteInterval.
void Database::undoTxnStart () void Database::startTransaction ()
{ {
if (_txn == 0) if (_txn == 0)
{ {
@ -185,9 +185,9 @@ void Database::undoTxnStart ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// The _txn member is a reference count. The undo data is only written when // The _txn member is a reference count. The undo data is only written when
// ::undoTxnEnd decrements the counter to zero, therefore the undo command can // ::endTransaction decrements the counter to zero, therefore the undo command can
// perform multiple atomic steps. // perform multiple atomic steps.
void Database::undoTxnEnd () void Database::endTransaction ()
{ {
--_txn; --_txn;
if (_txn == 0) if (_txn == 0)
@ -212,7 +212,7 @@ void Database::undoTxnEnd ()
// Record undoable transactions. There are several types: // Record undoable transactions. There are several types:
// interval changes to stored intervals // interval changes to stored intervals
// config changes to configuration // config changes to configuration
void Database::undoTxn ( void Database::recordUndoAction (
const std::string &type, const std::string &type,
const std::string &before, const std::string &before,
const std::string &after) const std::string &after)

View file

@ -49,9 +49,9 @@ public:
void deleteInterval (const Interval&); void deleteInterval (const Interval&);
void modifyInterval (const Interval&, const Interval&); void modifyInterval (const Interval&, const Interval&);
void undoTxnStart (); void startTransaction ();
void undoTxnEnd (); void endTransaction ();
void undoTxn (const std::string&, const std::string&, const std::string&); void recordUndoAction (const std::string &, const std::string &, const std::string &);
std::string dump () const; std::string dump () const;

View file

@ -72,9 +72,9 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
auto before = line; auto before = line;
line = line.substr (0, pos) + name + " = " + value; line = line.substr (0, pos) + name + " = " + value;
database.undoTxnStart (); database.startTransaction ();
database.undoTxn ("config", before, line); database.recordUndoAction ("config", before, line);
database.undoTxnEnd (); database.endTransaction ();
change = true; change = true;
} }
@ -107,9 +107,9 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
auto before = line; auto before = line;
line = line.substr (0, pos) + leaf + " " + value; line = line.substr (0, pos) + leaf + " " + value;
database.undoTxnStart (); database.startTransaction ();
database.undoTxn ("config", before, line); database.recordUndoAction ("config", before, line);
database.undoTxnEnd (); database.endTransaction ();
change = true; change = true;
} }
@ -132,9 +132,9 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
// Add new line. // Add new line.
lines.push_back (name + " = " + json::encode (value)); lines.push_back (name + " = " + json::encode (value));
database.undoTxnStart (); database.startTransaction ();
database.undoTxn ("config", "", lines.back()); database.recordUndoAction ("config", "", lines.back ());
database.undoTxnEnd (); database.endTransaction ();
change = true; change = true;
} }
@ -155,9 +155,9 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
// Add new line. // Add new line.
lines.push_back (name + " = " + json::encode (value)); lines.push_back (name + " = " + json::encode (value));
database.undoTxnStart (); database.startTransaction ();
database.undoTxn ("config", "", lines.back ()); database.recordUndoAction ("config", "", lines.back ());
database.undoTxnEnd (); database.endTransaction ();
change = true; change = true;
} }
@ -203,9 +203,9 @@ static int unsetConfigVariable (Database& database, const Rules& rules, std::str
if (! confirmation || if (! confirmation ||
confirm (format ("Are you sure you want to remove '{1}'?", name))) confirm (format ("Are you sure you want to remove '{1}'?", name)))
{ {
database.undoTxnStart (); database.startTransaction ();
database.undoTxn ("config", line, ""); database.recordUndoAction ("config", line, "");
database.undoTxnEnd (); database.endTransaction ();
line = ""; line = "";
change = true; change = true;