]> git.lyx.org Git - features.git/blob - src/texstream.h
4fff211146d57da631f1e6f7b79bf72bb8bd5efc
[features.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 private:
37         ///
38         odocstream & os_;
39         ///
40         TexRow & texrow_;
41 };
42
43 ///
44 otexrowstream & operator<<(otexrowstream &, odocstream_manip);
45 ///
46 otexrowstream & operator<<(otexrowstream &, docstring const &);
47 ///
48 otexrowstream & operator<<(otexrowstream &, std::string const &);
49 ///
50 otexrowstream & operator<<(otexrowstream &, char const *);
51 ///
52 otexrowstream & operator<<(otexrowstream &, char);
53 ///
54 template <typename Type>
55 otexrowstream & operator<<(otexrowstream & ots, Type value);
56
57
58 /** Subclass for otexrowstream.
59     This class is used to ensure that no blank lines may be inadvertently output.
60     To this end, use the special variables "breakln" and "safebreakln" as if
61     they were iomanip's to ensure that the next output will start at the
62     beginning of a line. Using "breakln", a '\n' char will be output if needed,
63     while using "safebreakln", "%\n" will be output if needed.
64     The class also records the last output character and can tell whether
65     a paragraph break was just output.
66   */
67
68 class otexstream : public otexrowstream {
69 public:
70         ///
71         otexstream(odocstream & os, TexRow & texrow)
72                 : otexrowstream(os, texrow), canbreakline_(false),
73                   protectspace_(false), parbreak_(true), lastchar_(0) {}
74         ///
75         void put(char_type const & c);
76         ///
77         void canBreakLine(bool breakline) { canbreakline_ = breakline; }
78         ///
79         bool canBreakLine() const { return canbreakline_; }
80         ///
81         void protectSpace(bool protectspace) { protectspace_ = protectspace; }
82         ///
83         bool protectSpace() const { return protectspace_; }
84         ///
85         void lastChar(char_type const & c)
86         {
87                 parbreak_ = (!canbreakline_ && c == '\n');
88                 canbreakline_ = (c != '\n');
89                 lastchar_ = c;
90         }
91         ///
92         char_type lastChar() const { return lastchar_; }
93         ///
94         bool afterParbreak() const { return parbreak_; }
95 private:
96         ///
97         bool canbreakline_;
98         ///
99         bool protectspace_;
100         ///
101         bool parbreak_;
102         ///
103         char_type lastchar_;
104 };
105
106 /// Helper structs for breaking a line
107 struct BreakLine {
108         char n;
109 };
110
111 struct SafeBreakLine {
112         char n;
113 };
114
115 extern BreakLine breakln;
116 extern SafeBreakLine safebreakln;
117
118 ///
119 otexstream & operator<<(otexstream &, BreakLine);
120 ///
121 otexstream & operator<<(otexstream &, SafeBreakLine);
122 ///
123 otexstream & operator<<(otexstream &, odocstream_manip);
124 ///
125 otexstream & operator<<(otexstream &, docstring const &);
126 ///
127 otexstream & operator<<(otexstream &, std::string const &);
128 ///
129 otexstream & operator<<(otexstream &, char const *);
130 ///
131 otexstream & operator<<(otexstream &, char);
132 ///
133 template <typename Type>
134 otexstream & operator<<(otexstream & ots, Type value);
135
136 }
137
138 #endif