]> git.lyx.org Git - features.git/blob - src/TexRow.h
Add a unique id to math insets
[features.git] / src / TexRow.h
1 // -*- C++ -*-
2 /**
3  * \file TexRow.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Matthias Ettrich
8  * \author Lars Gullik Bjønnes
9  * \author John Levon
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef TEXROW_H
15 #define TEXROW_H
16
17 #include "support/debug.h"
18
19 #include <vector>
20
21 namespace lyx {
22
23 class LyXErr;
24 class DocIterator;
25
26 typedef void const * uid_type;
27
28 /// Represents the correspondence between paragraphs and the generated
29 /// LaTeX file
30
31 class TexRow {
32 public:
33         ///
34         TexRow(bool enable = true)
35                 : lastid(-1), lastpos(-1), started(false), enabled_(enable) {}
36
37         /// Clears structure
38         /// TexRow is often computed to be immediately discarded. Set enable to
39         /// false if texrow is not needed
40         void reset(bool enable = true);
41
42         /// Define what paragraph and position the next row will represent
43         void start(int id, int pos);
44
45         /// Insert node when line is completed
46         void newline();
47
48         /// Insert multiple nodes when zero or more lines are completed
49         void newlines(int num_lines);
50
51         /// Call when code generation is complete
52         void finalize();
53
54         /**
55          * getIdFromRow - find pid and position for a given row
56          * @param row row number to find
57          * @param id set to id if found
58          * @param pos set to paragraph position if found
59          * @return true if found, false otherwise
60          *
61          * If the row could not be found, pos is set to zero and
62          * id is set to -1
63          */
64         bool getIdFromRow(int row, int & id, int & pos) const;
65
66         /// Finds the best pair of rows for dit
67         /// returns (-1,-1) if not found.
68         std::pair<int,int> rowFromDocIterator(DocIterator const & dit) const;
69         
70         /// Returns the number of rows contained
71         int rows() const { return rowlist.size(); }
72
73         /// an individual id/pos <=> row mapping
74         class RowItem {
75         public:
76                 RowItem(int id, int pos)
77                         : id_(id), pos_(pos)
78                 {}
79
80                 /// paragraph id
81                 int id() const { return id_; }
82                 /// set paragraph position
83                 void pos(int p) { pos_ = p; }
84                 /// paragraph position
85                 int pos() const { return pos_; }
86         private:
87                 RowItem();
88                 int id_;
89                 int pos_;
90         };
91         ///
92         typedef std::vector<RowItem> RowList;
93 private:
94         /// container of id/pos <=> row mapping
95         RowList rowlist;
96         /// Last paragraph
97         int lastid;
98         /// Last position
99         int lastpos;
100         /// Is id/pos already registered for current row?
101         bool started;
102         /// 
103         bool enabled_;
104 };
105
106 LyXErr & operator<<(LyXErr &, TexRow &);
107
108
109 } // namespace lyx
110
111 #endif // TEXROW_H