4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Enrico Forestieri
9 * Full author contact details are available in file CREDITS.
12 #ifndef LYX_TEXSTREAM_H
13 #define LYX_TEXSTREAM_H
15 #include "support/docstream.h"
16 #include "support/unique_ptr.h"
24 class otexstringstream;
26 /** Wrapper class for odocstream.
27 This class is used to automatically count the lines of the exported latex
34 explicit otexrowstream(odocstream & os);
38 odocstream & os() { return os_; }
40 TexRow & texrow() { return *texrow_; }
42 unique_ptr<TexRow> releaseTexRow();
44 void put(char_type const & c);
46 void append(docstring const & str, TexRow texrow);
51 unique_ptr<TexRow> texrow_;
55 otexrowstream & operator<<(otexrowstream &, odocstream_manip);
57 otexrowstream & operator<<(otexrowstream &, docstring const &);
59 otexrowstream & operator<<(otexrowstream &, std::string const &);
61 otexrowstream & operator<<(otexrowstream &, char const *);
63 otexrowstream & operator<<(otexrowstream &, char);
65 template <typename Type>
66 otexrowstream & operator<<(otexrowstream & ots, Type value);
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.
79 class otexstream : public otexrowstream {
82 explicit otexstream(odocstream & os)
83 : otexrowstream(os), canbreakline_(false),
84 protectspace_(false), parbreak_(true), lastchar_(0) {}
86 void put(char_type const & c);
88 void canBreakLine(bool breakline) { canbreakline_ = breakline; }
90 bool canBreakLine() const { return canbreakline_; }
92 void protectSpace(bool protectspace) { protectspace_ = protectspace; }
94 bool protectSpace() const { return protectspace_; }
96 void lastChar(char_type const & c)
98 parbreak_ = (!canbreakline_ && c == '\n');
99 canbreakline_ = (c != '\n');
103 char_type lastChar() const { return lastchar_; }
105 bool afterParbreak() const { return parbreak_; }
117 /// Helper structs for breaking a line
122 struct SafeBreakLine {
126 extern BreakLine breakln;
127 extern SafeBreakLine safebreakln;
130 otexstream & operator<<(otexstream &, BreakLine);
132 otexstream & operator<<(otexstream &, SafeBreakLine);
134 otexstream & operator<<(otexstream &, odocstream_manip);
136 otexstream & operator<<(otexstream &, docstring const &);
138 otexstream & operator<<(otexstream &, std::string const &);
140 otexstream & operator<<(otexstream &, char const *);
142 otexstream & operator<<(otexstream &, char);
144 template <typename Type>
145 otexstream & operator<<(otexstream & ots, Type value);