4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
10 * Full author contact details are available in file CREDITS.
12 * Record changes in a paragraph.
18 #include "support/docstream.h"
19 #include "support/lyxtime.h"
29 /// the type of change
31 UNCHANGED, // no change
33 DELETED // deleted text
36 explicit Change(Type t, int a = 0, time_type ct = current_time())
37 : type(t), author(a), changetime(ct) {}
39 /// is the change similar to the given change such that both can be merged?
40 bool isSimilarTo(Change const & change);
49 bool operator==(Change const & l, Change const & r);
50 bool operator!=(Change const & l, Change const & r);
56 /// set the pos to the given change
57 void set(Change const & change, pos_type pos);
58 /// set the range (excluding end) to the given change
59 void set(Change const & change, pos_type start, pos_type end);
61 /// erase the entry at pos and adjust all range bounds past it
62 /// (assumes that a character was deleted at pos)
63 void erase(lyx::pos_type pos);
65 /// insert a new entry at pos and adjust all range bounds past it
66 /// (assumes that a character was inserted at pos)
67 void insert(Change const & change, lyx::pos_type pos);
71 /// return the change at the given pos
72 Change const & lookup(pos_type pos) const;
74 /// return true if there is a change in the given range (excluding end)
75 bool isChanged(pos_type start, pos_type end) const;
79 /// output latex to mark a transition between two change types
80 /// returns length of text outputted
81 static int latexMarkChange(odocstream & os, BufferParams const & bparams,
82 Change const & oldChange, Change const & change);
84 /// output .lyx file format for transitions between changes
85 static void lyxMarkChange(std::ostream & os, int & column,
86 Change const & old, Change const & change);
91 Range(pos_type s, pos_type e)
94 // does this range contain r ? (inlined as the result of profiling)
95 bool contains(Range const & r) const {
96 return r.start >= start && r.end <= end;
99 // does this range contain pos ? (inlined as the result of profiling)
100 bool contains(pos_type pos) const {
101 return pos >= start && pos < end;
104 // do the ranges intersect ?
105 bool intersects(Range const & r) const;
108 pos_type end; // Caution: end is not in the range!
111 friend bool operator==(Range const & r1, Range const & r2);
112 friend bool operator!=(Range const & r1, Range const & r2);
116 ChangeRange(Change const & c, Range const & r)
117 : change(c), range(r) {}
123 /// merge equal changes with adjoining ranges
126 typedef std::vector<ChangeRange> ChangeTable;
128 /// table of changes, every row a change and range descriptor