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 "support/docstream.h"
19 #include "support/lyxtime.h"
26 /// the type of change
28 UNCHANGED, // no change
30 DELETED // deleted text
33 explicit Change(Type t, int a = 0, lyx::time_type ct = 0)
34 : type(t), author(a), changetime(ct) {}
40 lyx::time_type changetime;
43 bool operator==(Change const & l, Change const & r);
44 bool operator!=(Change const & l, Change const & r);
49 Changes(Change::Type type);
53 Changes(Changes const &);
55 /// reset "default" change type (for empty pars)
56 void reset(Change::Type type) {
60 /// set the pos to the given change
61 void set(Change const & change, lyx::pos_type pos);
63 /// set the range to the given change
64 void set(Change const & change, lyx::pos_type start, lyx::pos_type end);
66 /// mark the given change and adjust
67 void record(Change const & change, lyx::pos_type pos);
69 /// return the change at the given position
70 Change const lookup(lyx::pos_type pos) const;
72 /// return true if there is a change in the given range
73 bool isChange(lyx::pos_type start, lyx::pos_type end) const;
75 /// remove the given entry. This implies that a character was
76 /// deleted at pos, and will adjust all range bounds past it
77 void erase(lyx::pos_type pos);
79 /// output latex to mark a transition between two changetypes
80 /// returns length of text outputted
81 static int latexMarkChange(lyx::odocstream & os, Change::Type old,
82 Change::Type change, bool const & output);
84 /// output .lyx file format for transitions between changes
85 static void lyxMarkChange(std::ostream & os, int & column,
86 lyx::time_type curtime, Change const & old, Change const & change);
91 Range(lyx::pos_type s, lyx::pos_type e)
94 // does this range contain r ?
95 bool contains(Range const & r) const;
97 // does this range contain pos ?
98 bool contains(lyx::pos_type pos) const;
100 // do the ranges intersect ?
101 bool intersects(Range const & r) const;
104 lyx::pos_type end; // Caution: end is not in the range!
107 friend bool operator==(Range const & r1, Range const & r2);
108 friend bool operator!=(Range const & r1, Range const & r2);
112 ChangeRange(lyx::pos_type s, lyx::pos_type e, Change const & c)
113 : range(Range(s, e)), change(c) {}
118 typedef std::vector<ChangeRange> ChangeTable;
120 /// our table of changes, every row a range and change descriptor
123 /// change type for an empty paragraph
124 Change::Type empty_type_;
126 /// handle a delete, either logical or physical (see erase)
127 void del(Change const & change, ChangeTable::size_type pos);
129 /// handle an add, adjusting range bounds past it
130 void add(Change const & change, ChangeTable::size_type pos);
132 /// merge neighbouring ranges, assuming that they are abutting
133 /// (as done by set())