3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * Record changes in a paragraph.
8 * \author John Levon <levon@movementarian.org>
14 #include "support/types.h"
15 #include "support/lyxtime.h"
22 /// the type of change
24 UNCHANGED, // no change
26 DELETED // deleted text
29 Change(Type t = UNCHANGED, int a = 0, lyx::time_type ct = 0)
30 : type(t), author(a), changetime(ct) {}
36 lyx::time_type changetime;
39 bool operator==(Change const & l, Change const & r);
40 bool operator!=(Change const & l, Change const & r);
45 Changes(Change::Type type);
49 Changes(Changes const &);
51 /// reset "default" change type (for empty pars)
52 void reset(Change::Type type) {
56 /// set the position to the given change
57 void set(Change change, lyx::pos_type pos);
59 /// set the position to the given change
60 void set(Change::Type, lyx::pos_type pos);
62 /// set the range to the given change
63 void set(Change::Type, lyx::pos_type start, lyx::pos_type end);
65 /// set the range to the given change
66 void set(Change, lyx::pos_type start, lyx::pos_type end);
68 /// mark the given change and adjust
69 void record(Change, lyx::pos_type pos);
71 /// return the change type at the given position
72 Change::Type lookup(lyx::pos_type pos) const;
74 /// return the change at the given position
75 Change const lookupFull(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 /// return true if there is a deleted or unchanged range contained
81 bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
83 /// remove the given entry
84 void erase(lyx::pos_type pos);
86 /// output latex to mark a transition between two changetypes
87 /// returns length of text outputted
88 static int latexMarkChange(std::ostream & os, Change::Type old, Change::Type change);
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);
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 loose_contains(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);
122 ChangeRange(lyx::pos_type s, lyx::pos_type e, Change c)
123 : range(Range(s, e)), change(c) {}
128 typedef std::vector<ChangeRange> ChangeTable;
130 /// our table of changes
133 /// change type for an empty paragraph
134 Change::Type empty_type_;
137 void del(Change change, ChangeTable::size_type pos);
140 void add(Change change, ChangeTable::size_type pos);
142 /// merge neighbouring ranges
145 /// consistency check