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"
25 /// the type of change
27 UNCHANGED, // no change
29 DELETED // deleted text
32 Change(Type t = UNCHANGED, 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 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, lyx::pos_type start, lyx::pos_type end);
71 /// mark the given change and adjust
72 void record(Change, lyx::pos_type pos);
74 /// return the change type at the given position
75 Change::Type lookup(lyx::pos_type pos) const;
77 /// return the change at the given position
78 Change const lookupFull(lyx::pos_type pos) const;
80 /// return true if there is a change in the given range
81 bool isChange(lyx::pos_type start, lyx::pos_type end) const;
83 /// return true if there is a deleted or unchanged range contained
84 bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
86 /// remove the given entry
87 void erase(lyx::pos_type pos);
89 /// output latex to mark a transition between two changetypes
90 /// returns length of text outputted
91 static int latexMarkChange(std::ostream & os, Change::Type old, Change::Type change);
93 /// output .lyx file format for transitions between changes
94 static void lyxMarkChange(std::ostream & os, int & column,
95 lyx::time_type curtime, Change const & old, Change const & change);
99 Range(lyx::pos_type s, lyx::pos_type e)
100 : start(s), end(e) {}
102 // does this range contain r ?
103 bool contains(Range const & r) const;
105 // does this range contain pos ?
106 bool contains(lyx::pos_type pos) const;
108 // does this range contain pos, or can it be appended ?
109 bool loose_contains(lyx::pos_type pos) const;
111 // is this range contained within r ?
112 bool contained(Range const & r) const;
114 // do the ranges intersect ?
115 bool intersects(Range const & r) const;
121 friend bool operator==(Range const & r1, Range const & r2);
122 friend bool operator!=(Range const & r1, Range const & r2);
125 ChangeRange(lyx::pos_type s, lyx::pos_type e, Change c)
126 : range(Range(s, e)), change(c) {}
131 typedef std::vector<ChangeRange> ChangeTable;
133 /// our table of changes
136 /// change type for an empty paragraph
137 Change::Type empty_type_;
140 void del(Change change, ChangeTable::size_type pos);
143 void add(Change change, ChangeTable::size_type pos);
145 /// merge neighbouring ranges
148 /// consistency check