Update lyx examples to latest file format (for 1.5.0 release)
[lyx.git] / src / Changes.h
blob5305f55004ca6f52a075291aa9152203b8946f0d
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
8 * \author Michael Gerz
10 * Full author contact details are available in file CREDITS.
12 * Record changes in a paragraph.
15 #ifndef CHANGES_H
16 #define CHANGES_H
18 #include "support/docstream.h"
19 #include "support/lyxtime.h"
21 #include <vector>
24 namespace lyx {
26 class AuthorList;
28 class Change {
29 public:
30 /// the type of change
31 enum Type {
32 UNCHANGED, // no change
33 INSERTED, // new text
34 DELETED // deleted text
37 explicit Change(Type t, int a = 0, time_type ct = current_time())
38 : type(t), author(a), changetime(ct) {}
40 /// is the change similar to the given change such that both can be merged?
41 bool isSimilarTo(Change const & change);
43 Type type;
45 int author;
47 time_type changetime;
50 bool operator==(Change const & l, Change const & r);
51 bool operator!=(Change const & l, Change const & r);
53 class BufferParams;
55 class Changes {
56 public:
57 /// set the pos to the given change
58 void set(Change const & change, pos_type pos);
59 /// set the range (excluding end) to the given change
60 void set(Change const & change, pos_type start, pos_type end);
62 /// erase the entry at pos and adjust all range bounds past it
63 /// (assumes that a character was deleted at pos)
64 void erase(lyx::pos_type pos);
66 /// insert a new entry at pos and adjust all range bounds past it
67 /// (assumes that a character was inserted at pos)
68 void insert(Change const & change, lyx::pos_type pos);
70 ///
72 /// return the change at the given pos
73 Change const & lookup(pos_type pos) const;
75 /// return true if there is a change in the given range (excluding end)
76 bool isChanged(pos_type start, pos_type end) const;
78 ///
80 /// output latex to mark a transition between two change types
81 /// returns length of text outputted
82 static int latexMarkChange(odocstream & os, BufferParams const & bparams,
83 Change const & oldChange, Change const & change);
85 /// output .lyx file format for transitions between changes
86 static void lyxMarkChange(std::ostream & os, int & column,
87 Change const & old, Change const & change);
89 ///
90 void checkAuthors(AuthorList const & authorList);
92 private:
93 class Range {
94 public:
95 Range(pos_type s, pos_type e)
96 : start(s), end(e) {}
98 // does this range contain r ? (inlined as the result of profiling)
99 bool contains(Range const & r) const {
100 return r.start >= start && r.end <= end;
103 // does this range contain pos ? (inlined as the result of profiling)
104 bool contains(pos_type pos) const {
105 return pos >= start && pos < end;
108 // do the ranges intersect ?
109 bool intersects(Range const & r) const;
111 pos_type start;
112 pos_type end; // Caution: end is not in the range!
115 friend bool operator==(Range const & r1, Range const & r2);
116 friend bool operator!=(Range const & r1, Range const & r2);
118 class ChangeRange {
119 public:
120 ChangeRange(Change const & c, Range const & r)
121 : change(c), range(r) {}
123 Change change;
124 Range range;
127 /// merge equal changes with adjoining ranges
128 void merge();
130 typedef std::vector<ChangeRange> ChangeTable;
132 /// table of changes, every row a change and range descriptor
133 ChangeTable table_;
137 } // namespace lyx
139 #endif // CHANGES_H