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.
20 #include "support/strfwd.h"
21 #include "support/types.h"
22 #include "support/lyxtime.h"
35 /// the type of change
37 UNCHANGED, // no change
39 DELETED // deleted text
42 explicit Change(Type t = UNCHANGED, int a = 0, time_t ct = current_time())
43 : type(t), author(a), changetime(ct) {}
45 /// is the change similar to the given change such that both can be merged?
46 bool isSimilarTo(Change const & change) const;
47 /// The color of this change on screen
50 bool changed() const { return type != UNCHANGED; }
52 void setUnchanged() { type = UNCHANGED; }
54 bool inserted() const { return type == INSERTED; }
56 void setInserted() { type = INSERTED; }
58 bool deleted() const { return type == DELETED; }
60 void setDeleted() { type = DELETED; }
61 /// Is this change made by the current author ?
62 bool currentAuthor() const { return author == 0; }
71 bool operator==(Change const & l, Change const & r);
72 bool operator!=(Change const & l, Change const & r);
78 /// set the pos to the given change
79 void set(Change const & change, pos_type pos);
80 /// set the range (excluding end) to the given change
81 void set(Change const & change, pos_type start, pos_type end);
83 /// erase the entry at pos and adjust all range bounds past it
84 /// (assumes that a character was deleted at pos)
85 void erase(lyx::pos_type pos);
87 /// insert a new entry at pos and adjust all range bounds past it
88 /// (assumes that a character was inserted at pos)
89 void insert(Change const & change, lyx::pos_type pos);
93 /// return the change at the given pos
94 Change const & lookup(pos_type pos) const;
96 /// return true if there is a change in the given range (excluding end)
97 bool isChanged(pos_type start, pos_type end) const;
99 /// return true if the whole range is deleted
100 bool isDeleted(pos_type start, pos_type end) const;
102 /// output latex to mark a transition between two change types
103 /// returns length of text outputted
104 static int latexMarkChange(odocstream & os, BufferParams const & bparams,
105 Change const & oldChange, Change const & change);
107 /// output .lyx file format for transitions between changes
108 static void lyxMarkChange(std::ostream & os, BufferParams const & bparams,
109 int & column, Change const & old, Change const & change);
112 void checkAuthors(AuthorList const & authorList);
115 void addToToc(DocIterator const & cdit, Buffer const & buffer) const;
120 Range(pos_type s, pos_type e)
121 : start(s), end(e) {}
123 // does this range contain r ? (inlined as the result of profiling)
124 bool contains(Range const & r) const {
125 return r.start >= start && r.end <= end;
128 // does this range contain pos ? (inlined as the result of profiling)
129 bool contains(pos_type pos) const {
130 return pos >= start && pos < end;
133 // do the ranges intersect ?
134 bool intersects(Range const & r) const;
137 pos_type end; // Caution: end is not in the range!
140 friend bool operator==(Range const & r1, Range const & r2);
141 friend bool operator!=(Range const & r1, Range const & r2);
145 ChangeRange(Change const & c, Range const & r)
146 : change(c), range(r) {}
152 /// merge equal changes with adjoining ranges
155 typedef std::vector<ChangeRange> ChangeTable;
157 /// table of changes, every row a change and range descriptor