]> git.lyx.org Git - lyx.git/blob - src/texstream.h
Sort the language nesting mess with polyglossia
[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 "support/docstream.h"
16 #include "support/unique_ptr.h"
17
18 namespace lyx {
19
20 class TexRow;
21
22
23 // declared below
24 class otexstringstream;
25
26 /** Wrapper class for odocstream.
27     This class is used to automatically count the lines of the exported latex
28     code.
29   */
30
31 class otexrowstream {
32 public:
33         ///
34         explicit otexrowstream(odocstream & os);
35         /// defaulted
36         ~otexrowstream();
37         ///
38         odocstream & os() { return os_; }
39         ///
40         TexRow & texrow() { return *texrow_; }
41         ///
42         unique_ptr<TexRow> releaseTexRow();
43         ///
44         void put(char_type const & c);
45         ///
46         void append(docstring const & str, TexRow texrow);
47 private:
48         ///
49         odocstream & os_;
50         ///
51         unique_ptr<TexRow> texrow_;
52 };
53
54 ///
55 otexrowstream & operator<<(otexrowstream &, odocstream_manip);
56 ///
57 otexrowstream & operator<<(otexrowstream &, docstring const &);
58 ///
59 otexrowstream & operator<<(otexrowstream &, std::string const &);
60 ///
61 otexrowstream & operator<<(otexrowstream &, char const *);
62 ///
63 otexrowstream & operator<<(otexrowstream &, char);
64 ///
65 template <typename Type>
66 otexrowstream & operator<<(otexrowstream & ots, Type value);
67
68
69 /** Subclass for otexrowstream.
70     This class is used to ensure that no blank lines may be inadvertently output.
71     To this end, use the special variables "breakln" and "safebreakln" as if
72     they were iomanip's to ensure that the next output will start at the
73     beginning of a line. Using "breakln", a '\n' char will be output if needed,
74     while using "safebreakln", "%\n" will be output if needed.
75     The class also records the last output character and can tell whether
76     a paragraph break was just output.
77   */
78
79 class otexstream : public otexrowstream {
80 public:
81         ///
82         explicit otexstream(odocstream & os)
83                 : otexrowstream(os), canbreakline_(false),
84                   protectspace_(false), parbreak_(true), lastchar_(0) {}
85         ///
86         void put(char_type const & c);
87         ///
88         void canBreakLine(bool breakline) { canbreakline_ = breakline; }
89         ///
90         bool canBreakLine() const { return canbreakline_; }
91         ///
92         void protectSpace(bool protectspace) { protectspace_ = protectspace; }
93         ///
94         bool protectSpace() const { return protectspace_; }
95         ///
96         void lastChar(char_type const & c)
97         {
98                 parbreak_ = (!canbreakline_ && c == '\n');
99                 canbreakline_ = (c != '\n');
100                 lastchar_ = c;
101         }
102         ///
103         char_type lastChar() const { return lastchar_; }
104         ///
105         bool afterParbreak() const { return parbreak_; }
106 private:
107         ///
108         bool canbreakline_;
109         ///
110         bool protectspace_;
111         ///
112         bool parbreak_;
113         ///
114         char_type lastchar_;
115 };
116
117 /// Helper structs for breaking a line
118 struct BreakLine {
119         char n;
120 };
121
122 struct SafeBreakLine {
123         char n;
124 };
125
126 extern BreakLine breakln;
127 extern SafeBreakLine safebreakln;
128
129 ///
130 otexstream & operator<<(otexstream &, BreakLine);
131 ///
132 otexstream & operator<<(otexstream &, SafeBreakLine);
133 ///
134 otexstream & operator<<(otexstream &, odocstream_manip);
135 ///
136 otexstream & operator<<(otexstream &, docstring const &);
137 ///
138 otexstream & operator<<(otexstream &, std::string const &);
139 ///
140 otexstream & operator<<(otexstream &, char const *);
141 ///
142 otexstream & operator<<(otexstream &, char);
143 ///
144 template <typename Type>
145 otexstream & operator<<(otexstream & ots, Type value);
146
147
148 }
149
150 #endif