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/docstream.h"
21 #include "support/strfwd.h"
22 #include "support/types.h"
23 #include "support/lyxtime.h"
37 /// the type of change
39 UNCHANGED, // no change
41 DELETED // deleted text
44 explicit Change(Type t = UNCHANGED, int a = 0, time_t ct = support::current_time())
45 : type(t), author(a), changetime(ct) {}
47 /// is the change similar to the given change such that both can be merged?
48 bool isSimilarTo(Change const & change) const;
49 /// The color of this change on screen
52 bool changed() const { return type != UNCHANGED; }
54 void setUnchanged() { type = UNCHANGED; }
56 bool inserted() const { return type == INSERTED; }
58 void setInserted() { type = INSERTED; }
60 bool deleted() const { return type == DELETED; }
62 void setDeleted() { type = DELETED; }
63 /// Is this change made by the current author ?
64 bool currentAuthor() const { return author == 0; }
73 bool operator==(Change const & l, Change const & r);
74 bool operator!=(Change const & l, Change const & r);
80 /// set the pos to the given change
81 void set(Change const & change, pos_type pos);
82 /// set the range (excluding end) to the given change
83 void set(Change const & change, pos_type start, pos_type end);
85 /// erase the entry at pos and adjust all range bounds past it
86 /// (assumes that a character was deleted at pos)
87 void erase(lyx::pos_type pos);
89 /// insert a new entry at pos and adjust all range bounds past it
90 /// (assumes that a character was inserted at pos)
91 void insert(Change const & change, lyx::pos_type pos);
95 /// return the change at the given pos
96 Change const & lookup(pos_type pos) const;
98 /// return true if there is a change in the given range (excluding end)
99 bool isChanged(pos_type start, pos_type end) const;
101 /// return true if the whole range is deleted
102 bool isDeleted(pos_type start, pos_type end) const;
104 /// output latex to mark a transition between two change types
105 /// returns length of text outputted
106 static int latexMarkChange(otexstream & os, BufferParams const & bparams,
107 Change const & oldChange, Change const & change,
108 OutputParams const & runparams);
110 /// output .lyx file format for transitions between changes
111 static void lyxMarkChange(std::ostream & os, BufferParams const & bparams,
112 int & column, Change const & old, Change const & change);
115 void checkAuthors(AuthorList const & authorList);
118 void addToToc(DocIterator const & cdit, Buffer const & buffer,
119 bool output_active) const;
124 Range(pos_type s, pos_type e)
125 : start(s), end(e) {}
127 // does this range contain r ? (inlined as the result of profiling)
128 bool contains(Range const & r) const {
129 return r.start >= start && r.end <= end;
132 // does this range contain pos ? (inlined as the result of profiling)
133 bool contains(pos_type pos) const {
134 return pos >= start && pos < end;
137 // do the ranges intersect ?
138 bool intersects(Range const & r) const;
141 pos_type end; // Caution: end is not in the range!
144 friend bool operator==(Range const & r1, Range const & r2);
145 friend bool operator!=(Range const & r1, Range const & r2);
149 ChangeRange(Change const & c, Range const & r)
150 : change(c), range(r) {}
156 /// merge equal changes with adjoining ranges
159 typedef std::vector<ChangeRange> ChangeTable;
161 /// table of changes, every row a change and range descriptor