]> git.lyx.org Git - lyx.git/blob - src/TexRow.h
Correct early return position for if use_pixmap_cache_ check
[lyx.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 /// Represents the correspondence between paragraphs and the generated
27 /// LaTeX file
28
29 class TexRow {
30 public:
31         ///
32         TexRow(bool enable = true)
33                 : lastid(-1), lastpos(-1), started(false), enabled_(enable) {}
34
35         /// Clears structure
36         /// TexRow is often computed to be immediately discarded. Set enable to
37         /// false if texrow is not needed
38         void reset(bool enable = true);
39
40         /// Define what paragraph and position the next row will represent
41         void start(int id, int pos);
42
43         /// Insert node when line is completed
44         void newline();
45
46         /// Insert multiple nodes when zero or more lines are completed
47         void newlines(int num_lines);
48
49         /// Call when code generation is complete
50         void finalize();
51
52         /**
53          * getIdFromRow - find pid and position for a given row
54          * @param row row number to find
55          * @param id set to id if found
56          * @param pos set to paragraph position if found
57          * @return true if found, false otherwise
58          *
59          * If the row could not be found, pos is set to zero and
60          * id is set to -1
61          */
62         bool getIdFromRow(int row, int & id, int & pos) const;
63
64         /// Finds the best pair of rows for dit
65         /// returns (-1,-1) if not found.
66         std::pair<int,int> rowFromDocIterator(DocIterator const & dit) const;
67         
68         /// Returns the number of rows contained
69         int rows() const { return rowlist.size(); }
70
71         /// an individual id/pos <=> row mapping
72         class RowItem {
73         public:
74                 RowItem(int id, int pos)
75                         : id_(id), pos_(pos)
76                 {}
77
78                 /// paragraph id
79                 int id() const { return id_; }
80                 /// set paragraph position
81                 void pos(int p) { pos_ = p; }
82                 /// paragraph position
83                 int pos() const { return pos_; }
84         private:
85                 RowItem();
86                 int id_;
87                 int pos_;
88         };
89         ///
90         typedef std::vector<RowItem> RowList;
91 private:
92         /// container of id/pos <=> row mapping
93         RowList rowlist;
94         /// Last paragraph
95         int lastid;
96         /// Last position
97         int lastpos;
98         /// Is id/pos already registered for current row?
99         bool started;
100         /// 
101         bool enabled_;
102 };
103
104 LyXErr & operator<<(LyXErr &, TexRow &);
105
106
107 } // namespace lyx
108
109 #endif // TEXROW_H