Consider the case where there is not any layout name.
[lyx.git] / src / changes.h
blob1103bd2012fe204f962369d6fbb651c4c28513fa
1 // -*- C++ -*-
2 /**
3 * \file changes.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author John Levon
9 * Full author contact details are available in file CREDITS.
11 * Record changes in a paragraph.
14 #ifndef CHANGES_H
15 #define CHANGES_H
17 #include "support/types.h"
18 #include "support/lyxtime.h"
20 #include <vector>
21 #include <iosfwd>
24 class Change {
25 public:
26 /// the type of change
27 enum Type {
28 UNCHANGED, // no change
29 INSERTED, // new text
30 DELETED // deleted text
33 Change(Type t = UNCHANGED, int a = 0, lyx::time_type ct = 0)
34 : type(t), author(a), changetime(ct) {}
36 Type type;
38 int author;
40 lyx::time_type changetime;
43 bool operator==(Change const & l, Change const & r);
44 bool operator!=(Change const & l, Change const & r);
46 class Changes {
47 public:
49 Changes(Change::Type type);
51 ~Changes();
53 Changes(Changes const &);
55 /// reset "default" change type (for empty pars)
56 void reset(Change::Type type) {
57 empty_type_ = type;
60 /// set the position to the given change
61 void set(Change 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, lyx::pos_type start, lyx::pos_type end);
72 /// mark the given change and adjust
73 void record(Change, lyx::pos_type pos);
75 /// return the change type at the given position
76 Change::Type lookup(lyx::pos_type pos) const;
78 /// return the change at the given position
79 Change const lookupFull(lyx::pos_type pos) const;
81 /// return true if there is a change in the given range
82 bool isChange(lyx::pos_type start, lyx::pos_type end) const;
84 /// return true if there is a deleted or unchanged range contained
85 bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
87 /// remove the given entry
88 void erase(lyx::pos_type pos);
90 /// output latex to mark a transition between two changetypes
91 /// returns length of text outputted
92 static int latexMarkChange(std::ostream & os, Change::Type old,
93 Change::Type change, bool const & output);
95 /// output .lyx file format for transitions between changes
96 static void lyxMarkChange(std::ostream & os, int & column,
97 lyx::time_type curtime, Change const & old, Change const & change);
99 private:
100 class Range {
101 public:
102 Range(lyx::pos_type s, lyx::pos_type e)
103 : start(s), end(e) {}
105 // does this range contain r ?
106 bool contains(Range const & r) const;
108 // does this range contain pos ?
109 bool contains(lyx::pos_type pos) const;
111 // does this range contain pos, or can it be appended ?
112 bool loose_contains(lyx::pos_type pos) const;
114 // is this range contained within r ?
115 bool contained(Range const & r) const;
117 // do the ranges intersect ?
118 bool intersects(Range const & r) const;
120 lyx::pos_type start;
121 lyx::pos_type end;
124 friend bool operator==(Range const & r1, Range const & r2);
125 friend bool operator!=(Range const & r1, Range const & r2);
127 class ChangeRange {
128 public:
129 ChangeRange(lyx::pos_type s, lyx::pos_type e, Change c)
130 : range(Range(s, e)), change(c) {}
131 Range range;
132 Change change;
135 typedef std::vector<ChangeRange> ChangeTable;
137 /// our table of changes
138 ChangeTable table_;
140 /// change type for an empty paragraph
141 Change::Type empty_type_;
143 /// handle a delete
144 void del(Change change, ChangeTable::size_type pos);
146 /// handle an add
147 void add(Change change, ChangeTable::size_type pos);
149 /// merge neighbouring ranges
150 void merge();
152 /// consistency check
153 void check() const;
157 #endif // CHANGES_H