]> git.lyx.org Git - lyx.git/blob - src/Changes.h
Fixed some lines that were too long. It compiled afterwards.
[lyx.git] / src / Changes.h
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.
6  *
7  * \author John Levon
8  * \author Michael Gerz
9  *
10  * Full author contact details are available in file CREDITS.
11  *
12  * Record changes in a paragraph.
13  */
14
15 #ifndef CHANGES_H
16 #define CHANGES_H
17
18 #include "support/docstream.h"
19 #include "support/lyxtime.h"
20
21 #include <vector>
22
23
24 namespace lyx {
25
26 class AuthorList;
27
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
35         };
36
37         explicit Change(Type t, int a = 0, time_type ct = current_time())
38                 : type(t), author(a), changetime(ct) {}
39
40         /// is the change similar to the given change such that both can be merged?
41         bool isSimilarTo(Change const & change);
42
43         Type type;
44
45         int author;
46
47         time_type changetime;
48 };
49
50 bool operator==(Change const & l, Change const & r);
51 bool operator!=(Change const & l, Change const & r);
52
53 class BufferParams;
54
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);
61
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);
65
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);
69
70         ///
71
72         /// return the change at the given pos
73         Change const & lookup(pos_type pos) const;
74
75         /// return true if there is a change in the given range (excluding end)
76         bool isChanged(pos_type start, pos_type end) const;
77
78         ///
79
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);
84
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);
88
89         ///
90         void checkAuthors(AuthorList const & authorList);
91
92 private:
93         class Range {
94         public:
95                 Range(pos_type s, pos_type e)
96                         : start(s), end(e) {}
97
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;
101                 }
102
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;
106                 }
107
108                 // do the ranges intersect ?
109                 bool intersects(Range const & r) const;
110
111                 pos_type start;
112                 pos_type end; // Caution: end is not in the range!
113         };
114
115         friend bool operator==(Range const & r1, Range const & r2);
116         friend bool operator!=(Range const & r1, Range const & r2);
117
118         class ChangeRange {
119         public:
120                 ChangeRange(Change const & c, Range const & r)
121                         : change(c), range(r) {}
122
123                 Change change;
124                 Range range;
125         };
126
127         /// merge equal changes with adjoining ranges
128         void merge();
129
130         typedef std::vector<ChangeRange> ChangeTable;
131
132         /// table of changes, every row a change and range descriptor
133         ChangeTable table_;
134 };
135
136
137 } // namespace lyx
138
139 #endif // CHANGES_H