X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fchanges.C;h=3d86ce666bee88ccb057a62f299dcfadb938ca9f;hb=368f6a53a87eb5997433ecd0f51e854c99360d28;hp=c60357718b1ab17385541124168eec26bac65473;hpb=36980dce968ce572c66ed15848c923d22c8aa858;p=lyx.git diff --git a/src/changes.C b/src/changes.C index c60357718b..3d86ce666b 100644 --- a/src/changes.C +++ b/src/changes.C @@ -1,26 +1,28 @@ /** * \file changes.C - * Copyright 2002 the LyX Team - * Read the file COPYING + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * Record changes in a paragraph. + * \author John Levon + * + * Full author contact details are available in file CREDITS. * - * \author John Levon + * Record changes in a paragraph. */ #include #include "changes.h" #include "debug.h" -#include "author.h" -#include "support/LAssert.h" -#include "support/LOstream.h" +#include -using std::vector; -using std::endl; using lyx::pos_type; +using std::endl; +using std::string; + + bool operator==(Change const & l, Change const & r) { return l.type == r.type && l.author == r.author @@ -58,13 +60,13 @@ bool Changes::Range::contained(Range const & r) const } -bool Changes::Range::contains(pos_type pos) const +bool Changes::Range::contains(pos_type const pos) const { return pos >= start && pos < end; } -bool Changes::Range::loose_contains(pos_type pos) const +bool Changes::Range::containsOrPrecedes(pos_type const pos) const { return pos >= start && pos <= end; } @@ -77,7 +79,7 @@ bool Changes::Range::intersects(Range const & r) const } -Changes::Changes(Change::Type type) +Changes::Changes(Change::Type const type) : empty_type_(type) { } @@ -94,7 +96,7 @@ Changes::Changes(Changes const & c) } -void Changes::record(Change change, pos_type pos) +void Changes::record(Change const change, pos_type const pos) { if (lyxerr.debugging(Debug::CHANGES)) { lyxerr[Debug::CHANGES] << "record " << change.type @@ -116,25 +118,27 @@ void Changes::record(Change change, pos_type pos) } -void Changes::set(Change change, pos_type pos) +void Changes::set(Change const change, pos_type const pos) { set(change, pos, pos + 1); } -void Changes::set(Change::Type type, pos_type pos) +void Changes::set(Change::Type const type, pos_type const pos) { set(type, pos, pos + 1); } -void Changes::set(Change::Type type, pos_type start, pos_type end) +void Changes::set(Change::Type const type, + pos_type const start, pos_type const end) { set(Change(type), start, end); } -void Changes::set(Change change, pos_type start, pos_type end) +void Changes::set(Change const change, + pos_type const start, pos_type const end) { ChangeTable::iterator it = table_.begin(); @@ -160,7 +164,7 @@ void Changes::set(Change change, pos_type start, pos_type end) } it = table_.begin(); - ChangeTable::iterator itend = table_.end(); + ChangeTable::iterator const itend = table_.end(); // find a super-range for (; it != itend; ++it) { @@ -219,7 +223,7 @@ void Changes::set(Change change, pos_type start, pos_type end) } -void Changes::erase(pos_type pos) +void Changes::erase(pos_type const pos) { ChangeTable::iterator it = table_.begin(); ChangeTable::iterator end = table_.end(); @@ -250,7 +254,7 @@ void Changes::erase(pos_type pos) } -void Changes::del(Change change, ChangeTable::size_type pos) +void Changes::del(Change const change, ChangeTable::size_type const pos) { // this case happens when building from .lyx if (table_.empty()) { @@ -270,7 +274,7 @@ void Changes::del(Change change, ChangeTable::size_type pos) erase(pos); } break; - } else if (range.loose_contains(pos) && it + 1 == table_.end()) { + } else if (range.containsOrPrecedes(pos) && it + 1 == table_.end()) { // this case happens when building from .lyx set(change, pos); break; @@ -279,7 +283,7 @@ void Changes::del(Change change, ChangeTable::size_type pos) } -void Changes::add(Change change, ChangeTable::size_type pos) +void Changes::add(Change const change, ChangeTable::size_type const pos) { ChangeTable::iterator it = table_.begin(); ChangeTable::iterator end = table_.end(); @@ -289,7 +293,7 @@ void Changes::add(Change change, ChangeTable::size_type pos) for (; it != end; ++it) { Range & range(it->range); - if (!found && range.loose_contains(pos)) { + if (!found && range.containsOrPrecedes(pos)) { found = true; if (lyxerr.debugging(Debug::CHANGES)) { lyxerr[Debug::CHANGES] << "Found range of " @@ -308,7 +312,7 @@ void Changes::add(Change change, ChangeTable::size_type pos) } -Change const Changes::lookupFull(pos_type pos) const +Change const Changes::lookup(pos_type const pos) const { if (!table_.size()) { if (lyxerr.debugging(Debug::CHANGES)) @@ -317,7 +321,7 @@ Change const Changes::lookupFull(pos_type pos) const } ChangeTable::const_iterator it = table_.begin(); - ChangeTable::const_iterator end = table_.end(); + ChangeTable::const_iterator const end = table_.end(); for (; it != end; ++it) { if (it->range.contains(pos)) @@ -325,34 +329,12 @@ Change const Changes::lookupFull(pos_type pos) const } check(); - lyx::Assert(0); + BOOST_ASSERT(false && "missing changes for pos"); return Change(Change::UNCHANGED); } -Change::Type Changes::lookup(pos_type pos) const -{ - if (!table_.size()) { - if (lyxerr.debugging(Debug::CHANGES)) - lyxerr[Debug::CHANGES] << "Empty, type is " << empty_type_ << endl; - return empty_type_; - } - - ChangeTable::const_iterator it = table_.begin(); - ChangeTable::const_iterator end = table_.end(); - - for (; it != end; ++it) { - if (it->range.contains(pos)) - return it->change.type; - } - - check(); - lyx::Assert(0); - return Change::UNCHANGED; -} - - -bool Changes::isChange(pos_type start, pos_type end) const +bool Changes::isChange(pos_type const start, pos_type const end) const { if (!table_.size()) { if (lyxerr.debugging(Debug::CHANGES)) @@ -361,7 +343,7 @@ bool Changes::isChange(pos_type start, pos_type end) const } ChangeTable::const_iterator it = table_.begin(); - ChangeTable::const_iterator itend = table_.end(); + ChangeTable::const_iterator const itend = table_.end(); for (; it != itend; ++it) { if (lyxerr.debugging(Debug::CHANGES)) { @@ -386,7 +368,8 @@ bool Changes::isChange(pos_type start, pos_type end) const } -bool Changes::isChangeEdited(lyx::pos_type start, lyx::pos_type end) const +bool Changes::isChangeEdited(lyx::pos_type const start, + lyx::pos_type const end) const { if (!table_.size()) { if (lyxerr.debugging(Debug::CHANGES)) @@ -395,7 +378,7 @@ bool Changes::isChangeEdited(lyx::pos_type start, lyx::pos_type end) const } ChangeTable::const_iterator it = table_.begin(); - ChangeTable::const_iterator itend = table_.end(); + ChangeTable::const_iterator const itend = table_.end(); for (; it != itend; ++it) { if (it->range.intersects(Range(start, end ? end - 1 : 0)) @@ -463,7 +446,7 @@ void Changes::check() const ChangeTable::const_iterator it = table_.begin(); ChangeTable::const_iterator end = table_.end(); - bool dont_assert(true); + bool dont_assert = true; lyxerr[Debug::CHANGES] << "Changelist:" << endl; for (; it != end; ++it) { @@ -485,13 +468,15 @@ void Changes::check() const if (lyxerr.debugging(Debug::CHANGES)) lyxerr[Debug::CHANGES] << "End" << endl; - lyx::Assert(dont_assert); + BOOST_ASSERT(dont_assert); } -int Changes::latexMarkChange(std::ostream & os, Change::Type old, Change::Type change) +int Changes::latexMarkChange(std::ostream & os, + Change::Type const old, Change::Type const change, + bool const & output) { - if (old == change) + if (!output || old == change) return 0; string const start("\\changestart{}"); @@ -533,8 +518,9 @@ int Changes::latexMarkChange(std::ostream & os, Change::Type old, Change::Type c } -void Changes::lyxMarkChange(std::ostream & os, int & column, lyx::time_type curtime, - Change const & old, Change const & change) +void Changes::lyxMarkChange(std::ostream & os, int & column, + lyx::time_type const curtime, + Change const & old, Change const & change) { if (old == change) return; @@ -547,7 +533,7 @@ void Changes::lyxMarkChange(std::ostream & os, int & column, lyx::time_type curt break; case Change::DELETED: { - lyx::time_type t(change.changetime); + lyx::time_type t = change.changetime; if (!t) t = curtime; os << "\n\\change_deleted " << change.author @@ -556,12 +542,13 @@ void Changes::lyxMarkChange(std::ostream & os, int & column, lyx::time_type curt break; } - case Change::INSERTED: - lyx::time_type t(change.changetime); + case Change::INSERTED: { + lyx::time_type t = change.changetime; if (!t) t = curtime; os << "\n\\change_inserted " << change.author << " " << t << "\n"; break; } + } }