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"
24 #include "texstream.h"
38 /// the type of change
40 UNCHANGED, // no change
42 DELETED // deleted text
45 explicit Change(Type t = UNCHANGED, int a = 0, time_t ct = support::current_time())
46 : type(t), author(a), changetime(ct) {}
48 /// is the change similar to the given change such that both can be merged?
49 bool isSimilarTo(Change const & change) const;
50 /// The color of this change on screen
53 bool changed() const { return type != UNCHANGED; }
55 void setUnchanged() { type = UNCHANGED; }
57 bool inserted() const { return type == INSERTED; }
59 void setInserted() { type = INSERTED; }
61 bool deleted() const { return type == DELETED; }
63 void setDeleted() { type = DELETED; }
64 /// Is this change made by the current author ?
65 bool currentAuthor() const { return author == 0; }
74 bool operator==(Change const & l, Change const & r);
75 bool operator!=(Change const & l, Change const & r);
81 /// set the pos to the given change
82 void set(Change const & change, pos_type pos);
83 /// set the range (excluding end) to the given change
84 void set(Change const & change, pos_type start, pos_type end);
86 /// erase the entry at pos and adjust all range bounds past it
87 /// (assumes that a character was deleted at pos)
88 void erase(lyx::pos_type pos);
90 /// insert a new entry at pos and adjust all range bounds past it
91 /// (assumes that a character was inserted at pos)
92 void insert(Change const & change, lyx::pos_type pos);
96 /// return the change at the given pos
97 Change const & lookup(pos_type pos) const;
99 /// return true if there is a change in the given range (excluding end)
100 bool isChanged(pos_type start, pos_type end) const;
102 /// return true if the whole range is deleted
103 bool isDeleted(pos_type start, pos_type end) const;
105 /// output latex to mark a transition between two change types
106 /// returns length of text outputted
107 static int latexMarkChange(otexstream & os, BufferParams const & bparams,
108 Change const & oldChange, Change const & change,
109 OutputParams const & runparams);
111 /// output .lyx file format for transitions between changes
112 static void lyxMarkChange(std::ostream & os, BufferParams const & bparams,
113 int & column, Change const & old, Change const & change);
116 void checkAuthors(AuthorList const & authorList);
119 void addToToc(DocIterator const & cdit, Buffer const & buffer,
120 bool output_active) const;
125 Range(pos_type s, pos_type e)
126 : start(s), end(e) {}
128 // does this range contain r ? (inlined as the result of profiling)
129 bool contains(Range const & r) const {
130 return r.start >= start && r.end <= end;
133 // does this range contain pos ? (inlined as the result of profiling)
134 bool contains(pos_type pos) const {
135 return pos >= start && pos < end;
138 // do the ranges intersect ?
139 bool intersects(Range const & r) const;
142 pos_type end; // Caution: end is not in the range!
145 friend bool operator==(Range const & r1, Range const & r2);
146 friend bool operator!=(Range const & r1, Range const & r2);
150 ChangeRange(Change const & c, Range const & r)
151 : change(c), range(r) {}
157 /// merge equal changes with adjoining ranges
160 typedef std::vector<ChangeRange> ChangeTable;
162 /// table of changes, every row a change and range descriptor