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/types.h"
18 #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 position to the given change
61 void set(Change const & change, lyx::pos_type pos);
63 /// set the position to the given change
64 void set(Change::Type, lyx::pos_type pos);
66 /// set the range to the given change
67 void set(Change::Type, lyx::pos_type start, lyx::pos_type end);
69 /// set the range to the given change
70 void set(Change const & change, lyx::pos_type start, lyx::pos_type end);
72 /// mark the given change and adjust
73 void record(Change const & change, lyx::pos_type pos);
75 /// return the change at the given position
76 Change const lookup(lyx::pos_type pos) const;
78 /// return true if there is a change in the given range
79 bool isChange(lyx::pos_type start, lyx::pos_type end) const;
81 /// remove the given entry. This implies that a character was
82 /// deleted at pos, and will adjust all range bounds past it
83 void erase(lyx::pos_type pos);
85 /// output latex to mark a transition between two changetypes
86 /// returns length of text outputted
87 static int latexMarkChange(std::ostream & os, Change::Type old,
88 Change::Type change, bool const & output);
90 /// output .lyx file format for transitions between changes
91 static void lyxMarkChange(std::ostream & os, int & column,
92 lyx::time_type curtime, Change const & old, Change const & change);
97 Range(lyx::pos_type s, lyx::pos_type e)
100 // does this range contain r ?
101 bool contains(Range const & r) const;
103 // does this range contain pos ?
104 bool contains(lyx::pos_type pos) const;
106 // does this range contain pos, or can it be appended ?
107 bool containsOrPrecedes(lyx::pos_type pos) const;
109 // is this range contained within r ?
110 bool contained(Range const & r) const;
112 // do the ranges intersect ?
113 bool intersects(Range const & r) const;
119 friend bool operator==(Range const & r1, Range const & r2);
120 friend bool operator!=(Range const & r1, Range const & r2);
124 ChangeRange(lyx::pos_type s, lyx::pos_type e, Change const & c)
125 : range(Range(s, e)), change(c) {}
130 typedef std::vector<ChangeRange> ChangeTable;
132 /// our table of changes, every row a range and change descriptor
135 /// change type for an empty paragraph
136 Change::Type empty_type_;
138 /// handle a delete, either logical or physical (see erase)
139 void del(Change const & change, ChangeTable::size_type pos);
141 /// handle an add, adjusting range bounds past it
142 void add(Change const & change, ChangeTable::size_type pos);
144 /// merge neighbouring ranges, assuming that they are abutting
145 /// (as done by set())
148 /// consistency check, needed before merge()