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 "ColorCode.h"
20 #include "support/strfwd.h"
21 #include "support/types.h"
22 #include "support/lyxtime.h"
33 /// the type of change
35 UNCHANGED, // no change
37 DELETED // deleted text
40 explicit Change(Type t = UNCHANGED, int a = 0, time_t ct = current_time())
41 : type(t), author(a), changetime(ct) {}
43 /// is the change similar to the given change such that both can be merged?
44 bool isSimilarTo(Change const & change) const;
45 /// The color of this change on screen
46 ColorCode color() const;
48 bool changed() const { return type != UNCHANGED; }
50 void setUnchanged() { type = UNCHANGED; }
52 bool inserted() const { return type == INSERTED; }
54 void setInserted() { type = INSERTED; }
56 bool deleted() const { return type == DELETED; }
58 void setDeleted() { type = DELETED; }
67 bool operator==(Change const & l, Change const & r);
68 bool operator!=(Change const & l, Change const & r);
74 /// set the pos to the given change
75 void set(Change const & change, pos_type pos);
76 /// set the range (excluding end) to the given change
77 void set(Change const & change, pos_type start, pos_type end);
79 /// erase the entry at pos and adjust all range bounds past it
80 /// (assumes that a character was deleted at pos)
81 void erase(lyx::pos_type pos);
83 /// insert a new entry at pos and adjust all range bounds past it
84 /// (assumes that a character was inserted at pos)
85 void insert(Change const & change, lyx::pos_type pos);
89 /// return the change at the given pos
90 Change const & lookup(pos_type pos) const;
92 /// return true if there is a change in the given range (excluding end)
93 bool isChanged(pos_type start, pos_type end) const;
97 /// output latex to mark a transition between two change types
98 /// returns length of text outputted
99 static int latexMarkChange(odocstream & os, BufferParams const & bparams,
100 Change const & oldChange, Change const & change);
102 /// output .lyx file format for transitions between changes
103 static void lyxMarkChange(std::ostream & os, int & column,
104 Change const & old, Change const & change);
107 void checkAuthors(AuthorList const & authorList);
112 Range(pos_type s, pos_type e)
113 : start(s), end(e) {}
115 // does this range contain r ? (inlined as the result of profiling)
116 bool contains(Range const & r) const {
117 return r.start >= start && r.end <= end;
120 // does this range contain pos ? (inlined as the result of profiling)
121 bool contains(pos_type pos) const {
122 return pos >= start && pos < end;
125 // do the ranges intersect ?
126 bool intersects(Range const & r) const;
129 pos_type end; // Caution: end is not in the range!
132 friend bool operator==(Range const & r1, Range const & r2);
133 friend bool operator!=(Range const & r1, Range const & r2);
137 ChangeRange(Change const & c, Range const & r)
138 : change(c), range(r) {}
144 /// merge equal changes with adjoining ranges
147 typedef std::vector<ChangeRange> ChangeTable;
149 /// table of changes, every row a change and range descriptor