#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)
{
undoTxnStart ();
startTransaction ();
if (interval.range.is_open ())
{
@ -104,7 +104,7 @@ void Database::addInterval (const Interval& interval)
// created on demand.
auto df = getDatafile (interval.range.start.year (), interval.range.start.month ());
_files[df].addInterval (interval);
undoTxn ("interval", "", interval.json ());
recordUndoAction ("interval", "", interval.json ());
}
else
{
@ -123,17 +123,17 @@ void Database::addInterval (const Interval& interval)
_files[df].addInterval (segmentedInterval);
undoTxn ("interval", "", segmentedInterval.json ());
recordUndoAction ("interval", "", segmentedInterval.json ());
}
}
undoTxnEnd ();
endTransaction ();
}
////////////////////////////////////////////////////////////////////////////////
void Database::deleteInterval (const Interval& interval)
{
undoTxnStart ();
startTransaction ();
auto intervalRange = interval.range;
for (auto& segment : segmentRange (intervalRange))
@ -150,10 +150,10 @@ void Database::deleteInterval (const Interval& interval)
_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.
void Database::modifyInterval (const Interval& from, const Interval& to)
{
undoTxnStart ();
startTransaction ();
deleteInterval (from);
addInterval (to);
undoTxnEnd ();
endTransaction ();
}
////////////////////////////////////////////////////////////////////////////////
// The _txn member is a reference count, allowing multiple nested transactions.
// This accommodates the Database::modifyInterval call, that in turn calls
// ::addInterval and ::deleteInterval.
void Database::undoTxnStart ()
void Database::startTransaction ()
{
if (_txn == 0)
{
@ -185,9 +185,9 @@ void Database::undoTxnStart ()
////////////////////////////////////////////////////////////////////////////////
// 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.
void Database::undoTxnEnd ()
void Database::endTransaction ()
{
--_txn;
if (_txn == 0)
@ -212,7 +212,7 @@ void Database::undoTxnEnd ()
// Record undoable transactions. There are several types:
// interval changes to stored intervals
// config changes to configuration
void Database::undoTxn (
void Database::recordUndoAction (
const std::string &type,
const std::string &before,
const std::string &after)

View file

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

View file

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