4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
11 * Record changes in a paragraph.
17 #include "support/docstream.h"
18 #include "support/lyxtime.h"
25 /// the type of change
27 UNCHANGED, // no change
29 DELETED // deleted text
32 explicit Change(Type t, int a = 0, lyx::time_type ct = 0)
33 : type(t), author(a), changetime(ct) {}
39 lyx::time_type changetime;
42 bool operator==(Change const & l, Change const & r);
43 bool operator!=(Change const & l, Change const & r);
48 Changes(Change::Type type);
52 Changes(Changes const &);
54 /// reset "default" change type (for empty pars)
55 void reset(Change::Type type) {
59 /// set the position to the given change
60 void set(Change const & change, lyx::pos_type pos);
62 /// set the position to the given change
63 void set(Change::Type, lyx::pos_type pos);
65 /// set the range to the given change
66 void set(Change::Type, lyx::pos_type start, lyx::pos_type end);
68 /// set the range to the given change
69 void set(Change const & change, lyx::pos_type start, lyx::pos_type end);
71 /// mark the given change and adjust
72 void record(Change const & change, lyx::pos_type pos);
74 /// return the change at the given position
75 Change const lookup(lyx::pos_type pos) const;
77 /// return true if there is a change in the given range
78 bool isChange(lyx::pos_type start, lyx::pos_type end) const;
80 /// remove the given entry. This implies that a character was
81 /// deleted at pos, and will adjust all range bounds past it
82 void erase(lyx::pos_type pos);
84 /// output latex to mark a transition between two changetypes
85 /// returns length of text outputted
86 static int latexMarkChange(lyx::odocstream & os, Change::Type old,
87 Change::Type change, bool const & output);
89 /// output .lyx file format for transitions between changes
90 static void lyxMarkChange(std::ostream & os, int & column,
91 lyx::time_type curtime, Change const & old, Change const & change);
96 Range(lyx::pos_type s, lyx::pos_type e)
99 // does this range contain r ?
100 bool contains(Range const & r) const;
102 // does this range contain pos ?
103 bool contains(lyx::pos_type pos) const;
105 // does this range contain pos, or can it be appended ?
106 bool containsOrPrecedes(lyx::pos_type pos) const;
108 // is this range contained within r ?
109 bool contained(Range const & r) const;
111 // do the ranges intersect ?
112 bool intersects(Range const & r) const;
118 friend bool operator==(Range const & r1, Range const & r2);
119 friend bool operator!=(Range const & r1, Range const & r2);
123 ChangeRange(lyx::pos_type s, lyx::pos_type e, Change const & c)
124 : range(Range(s, e)), change(c) {}
129 typedef std::vector<ChangeRange> ChangeTable;
131 /// our table of changes, every row a range and change descriptor
134 /// change type for an empty paragraph
135 Change::Type empty_type_;
137 /// handle a delete, either logical or physical (see erase)
138 void del(Change const & change, ChangeTable::size_type pos);
140 /// handle an add, adjusting range bounds past it
141 void add(Change const & change, ChangeTable::size_type pos);
143 /// merge neighbouring ranges, assuming that they are abutting
144 /// (as done by set())
147 /// consistency check, needed before merge()