X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fchanges.h;h=967a9a6c8d7bc6308827ba632a311068b3c778b4;hb=9e1ce30ff75b0282f428738aa3f3562c21ceb9df;hp=9ef77e03c769426730b70f31c951dd28dcb34eec;hpb=b55f70432cc95b3eadbb8c1deedfc6b819db47ab;p=lyx.git diff --git a/src/changes.h b/src/changes.h index 9ef77e03c7..967a9a6c8d 100644 --- a/src/changes.h +++ b/src/changes.h @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author John Levon + * \author Michael Gerz * * Full author contact details are available in file CREDITS. * @@ -14,11 +15,13 @@ #ifndef CHANGES_H #define CHANGES_H -#include "support/types.h" +#include "support/docstream.h" #include "support/lyxtime.h" #include -#include + + +namespace lyx { class Change { @@ -30,14 +33,17 @@ public: DELETED // deleted text }; - explicit Change(Type t, int a = 0, lyx::time_type ct = 0) + explicit Change(Type t, int a = 0, time_type ct = current_time()) : type(t), author(a), changetime(ct) {} + /// is the change similar to the given change such that both can be merged? + bool isSimilarTo(Change const & change); + Type type; int author; - lyx::time_type changetime; + time_type changetime; }; bool operator==(Change const & l, Change const & r); @@ -45,75 +51,59 @@ bool operator!=(Change const & l, Change const & r); class Changes { public: + /// set the pos to the given change + void set(Change const & change, pos_type pos); + /// set the range (excluding end) to the given change + void set(Change const & change, pos_type start, pos_type end); - Changes(Change::Type type); - - ~Changes(); - - Changes(Changes const &); - - /// reset "default" change type (for empty pars) - void reset(Change::Type type) { - empty_type_ = type; - } - - /// set the position to the given change - void set(Change const & change, lyx::pos_type pos); - - /// set the position to the given change - void set(Change::Type, lyx::pos_type pos); - - /// set the range to the given change - void set(Change::Type, lyx::pos_type start, lyx::pos_type end); + /// erase the entry at pos and adjust all range bounds past it + /// (assumes that a character was deleted at pos) + void erase(lyx::pos_type pos); - /// set the range to the given change - void set(Change const & change, lyx::pos_type start, lyx::pos_type end); + /// insert a new entry at pos and adjust all range bounds past it + /// (assumes that a character was inserted at pos) + void insert(Change const & change, lyx::pos_type pos); - /// mark the given change and adjust - void record(Change const & change, lyx::pos_type pos); + /// - /// return the change at the given position - Change const lookup(lyx::pos_type pos) const; + /// return the change at the given pos + Change const & lookup(pos_type pos) const; - /// return true if there is a change in the given range - bool isChange(lyx::pos_type start, lyx::pos_type end) const; + /// return true if there is a change in the given range (excluding end) + bool isChanged(pos_type start, pos_type end) const; - /// remove the given entry. This implies that a character was - /// deleted at pos, and will adjust all range bounds past it - void erase(lyx::pos_type pos); + /// - /// output latex to mark a transition between two changetypes + /// output latex to mark a transition between two change types /// returns length of text outputted - static int latexMarkChange(std::ostream & os, Change::Type old, - Change::Type change, bool const & output); + static int latexMarkChange(odocstream & os, Change::Type oldChangeType, + Change::Type changeType, bool const & output); /// output .lyx file format for transitions between changes static void lyxMarkChange(std::ostream & os, int & column, - lyx::time_type curtime, Change const & old, Change const & change); + Change const & old, Change const & change); private: class Range { public: - Range(lyx::pos_type s, lyx::pos_type e) + Range(pos_type s, pos_type e) : start(s), end(e) {} - // does this range contain r ? - bool contains(Range const & r) const; - - // does this range contain pos ? - bool contains(lyx::pos_type pos) const; - - // does this range contain pos, or can it be appended ? - bool containsOrPrecedes(lyx::pos_type pos) const; + // does this range contain r ? (inlined as the result of profiling) + bool contains(Range const & r) const { + return r.start >= start && r.end <= end; + } - // is this range contained within r ? - bool contained(Range const & r) const; + // does this range contain pos ? (inlined as the result of profiling) + bool contains(pos_type pos) const { + return pos >= start && pos < end; + } // do the ranges intersect ? bool intersects(Range const & r) const; - lyx::pos_type start; - lyx::pos_type end; + pos_type start; + pos_type end; // Caution: end is not in the range! }; friend bool operator==(Range const & r1, Range const & r2); @@ -121,33 +111,23 @@ private: class ChangeRange { public: - ChangeRange(lyx::pos_type s, lyx::pos_type e, Change const & c) - : range(Range(s, e)), change(c) {} - Range range; + ChangeRange(Change const & c, Range const & r) + : change(c), range(r) {} + Change change; + Range range; }; + /// merge equal changes with adjoining ranges + void merge(); + typedef std::vector ChangeTable; - /// our table of changes, every row a range and change descriptor + /// table of changes, every row a change and range descriptor ChangeTable table_; +}; - /// change type for an empty paragraph - Change::Type empty_type_; - - /// handle a delete, either logical or physical (see erase) - void del(Change const & change, ChangeTable::size_type pos); - - /// handle an add, adjusting range bounds past it - void add(Change const & change, ChangeTable::size_type pos); - - /// merge neighbouring ranges, assuming that they are abutting - /// (as done by set()) - void merge(); - - /// consistency check, needed before merge() - void check() const; -}; +} // namespace lyx #endif // CHANGES_H