]> git.lyx.org Git - lyx.git/blob - src/texstream.h
prepare Qt 5.6 builds
[lyx.git] / src / texstream.h
1 // -*- C++ -*-
2 /**
3  * \file texstream.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Enrico Forestieri
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef LYX_TEXSTREAM_H
13 #define LYX_TEXSTREAM_H
14
15 #include "TexRow.h"
16 #include "support/docstream.h"
17
18 namespace lyx {
19
20 /** Wrapper class for odocstream.
21     This class is used to automatically count the lines of the exported latex
22     code.
23   */
24
25 class otexrowstream {
26 public:
27         ///
28         otexrowstream(odocstream & os, TexRow & texrow)
29                 : os_(os), texrow_(texrow) {}
30         ///
31         odocstream & os() { return os_; }
32         ///
33         TexRow & texrow() { return texrow_; }
34         ///
35         void put(char_type const & c);
36         ///
37         void append(docstring const &, TexRow const &);
38 private:
39         ///
40         odocstream & os_;
41         ///
42         TexRow & texrow_;
43 };
44
45 ///
46 otexrowstream & operator<<(otexrowstream &, odocstream_manip);
47 ///
48 otexrowstream & operator<<(otexrowstream &, docstring const &);
49 ///
50 otexrowstream & operator<<(otexrowstream &, std::string const &);
51 ///
52 otexrowstream & operator<<(otexrowstream &, char const *);
53 ///
54 otexrowstream & operator<<(otexrowstream &, char);
55 ///
56 template <typename Type>
57 otexrowstream & operator<<(otexrowstream & ots, Type value);
58
59
60 /** Subclass for otexrowstream.
61     This class is used to ensure that no blank lines may be inadvertently output.
62     To this end, use the special variables "breakln" and "safebreakln" as if
63     they were iomanip's to ensure that the next output will start at the
64     beginning of a line. Using "breakln", a '\n' char will be output if needed,
65     while using "safebreakln", "%\n" will be output if needed.
66     The class also records the last output character and can tell whether
67     a paragraph break was just output.
68   */
69
70 class otexstream : public otexrowstream {
71 public:
72         ///
73         otexstream(odocstream & os, TexRow & texrow)
74                 : otexrowstream(os, texrow), canbreakline_(false),
75                   protectspace_(false), parbreak_(true), lastchar_(0) {}
76         ///
77         void put(char_type const & c);
78         ///
79         void canBreakLine(bool breakline) { canbreakline_ = breakline; }
80         ///
81         bool canBreakLine() const { return canbreakline_; }
82         ///
83         void protectSpace(bool protectspace) { protectspace_ = protectspace; }
84         ///
85         bool protectSpace() const { return protectspace_; }
86         ///
87         void lastChar(char_type const & c)
88         {
89                 parbreak_ = (!canbreakline_ && c == '\n');
90                 canbreakline_ = (c != '\n');
91                 lastchar_ = c;
92         }
93         ///
94         char_type lastChar() const { return lastchar_; }
95         ///
96         bool afterParbreak() const { return parbreak_; }
97 private:
98         ///
99         bool canbreakline_;
100         ///
101         bool protectspace_;
102         ///
103         bool parbreak_;
104         ///
105         char_type lastchar_;
106 };
107
108 /// Helper structs for breaking a line
109 struct BreakLine {
110         char n;
111 };
112
113 struct SafeBreakLine {
114         char n;
115 };
116
117 extern BreakLine breakln;
118 extern SafeBreakLine safebreakln;
119
120 ///
121 otexstream & operator<<(otexstream &, BreakLine);
122 ///
123 otexstream & operator<<(otexstream &, SafeBreakLine);
124 ///
125 otexstream & operator<<(otexstream &, odocstream_manip);
126 ///
127 otexstream & operator<<(otexstream &, docstring const &);
128 ///
129 otexstream & operator<<(otexstream &, std::string const &);
130 ///
131 otexstream & operator<<(otexstream &, char const *);
132 ///
133 otexstream & operator<<(otexstream &, char);
134 ///
135 template <typename Type>
136 otexstream & operator<<(otexstream & ots, Type value);
137
138 }
139
140 #endif