]> git.lyx.org Git - lyx.git/blob - src/texstream.h
Add Qt's Svg module to the list of used modules. This is required to allow the use...
[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 and also to ensure that no blank lines may be inadvertently output.
23     To this end, use the special variables "breakln" and "safebreakln" as if
24     they were iomanip's to ensure that the next output will start at the
25     beginning of a line. Using "breakln", a '\n' char will be output if needed,
26     while using "safebreakln", "%\n" will be output if needed.
27     The class also records the last output character and can tell whether
28     a paragraph break was just output.
29   */
30
31 class otexstream {
32 public:
33         ///
34         otexstream(odocstream & os, TexRow & texrow)
35                 : os_(os), texrow_(texrow), canbreakline_(false),
36                   protectspace_(false), parbreak_(true), lastchar_(0) {}
37         ///
38         odocstream & os() { return os_; }
39         ///
40         TexRow & texrow() { return texrow_; }
41         ///
42         void put(char_type const & c);
43         ///
44         void canBreakLine(bool breakline) { canbreakline_ = breakline; }
45         ///
46         bool canBreakLine() const { return canbreakline_; }
47         ///
48         void protectSpace(bool protectspace) { protectspace_ = protectspace; }
49         ///
50         bool protectSpace() const { return protectspace_; }
51         ///
52         void lastChar(char_type const & c)
53         {
54                 parbreak_ = (!canbreakline_ && c == '\n');
55                 canbreakline_ = (c != '\n');
56                 lastchar_ = c;
57         }
58         ///
59         char_type lastChar() const { return lastchar_; }
60         ///
61         bool afterParbreak() const { return parbreak_; }
62 private:
63         ///
64         odocstream & os_;
65         ///
66         TexRow & texrow_;
67         ///
68         bool canbreakline_;
69         ///
70         bool protectspace_;
71         ///
72         bool parbreak_;
73         ///
74         char_type lastchar_;
75 };
76
77 /// Helper structs for breaking a line
78 struct BreakLine {
79         char n;
80 };
81
82 struct SafeBreakLine {
83         char n;
84 };
85
86 extern BreakLine breakln;
87 extern SafeBreakLine safebreakln;
88
89 ///
90 otexstream & operator<<(otexstream &, BreakLine);
91 ///
92 otexstream & operator<<(otexstream &, SafeBreakLine);
93 ///
94 otexstream & operator<<(otexstream &, odocstream_manip);
95 ///
96 otexstream & operator<<(otexstream &, docstring const &);
97 ///
98 otexstream & operator<<(otexstream &, std::string const &);
99 ///
100 otexstream & operator<<(otexstream &, char const *);
101 ///
102 otexstream & operator<<(otexstream &, char);
103 ///
104 template <typename Type>
105 otexstream & operator<<(otexstream & ots, Type value);
106
107 }
108
109 #endif