Permalink
Browse files

#9 TI-1: Rename undoTxn*-functions

  • Loading branch information...
lauft committed Jul 18, 2018
1 parent f031bd9 commit b8b0bbfeaf276a78f8b20e5912f185eff43175f6
Showing with 34 additions and 34 deletions.
  1. +16 −16 src/Database.cpp
  2. +3 −3 src/Database.h
  3. +15 −15 src/commands/CmdConfig.cpp
@@ -96,15 +96,15 @@ std::vector <std::string> Database::allLines ()
////////////////////////////////////////////////////////////////////////////////
void Database::addInterval (const Interval& interval)
{
undoTxnStart ();
startTransaction ();

if (interval.range.is_open ())
{
// Get the index into _files for the appropriate Datafile, which may be
// 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,10 +212,10 @@ void Database::undoTxnEnd ()
// Record undoable transactions. There are several types:
// interval changes to stored intervals
// config changes to configuration
void Database::undoTxn (
const std::string& type,
const std::string& before,
const std::string& after)
void Database::recordUndoAction (
const std::string &type,
const std::string &before,
const std::string &after)
{
_currentTransaction->addUndoAction (type, before, after);
}
@@ -49,9 +49,9 @@ class Database
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;

@@ -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;

0 comments on commit b8b0bbf

Please sign in to comment.