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
16 #include "support/docstream.h"
20 /** Wrapper class for odocstream.
21 This class is used to automatically count the lines of the exported latex
28 otexrowstream(odocstream & os, TexRow & texrow)
29 : os_(os), texrow_(texrow) {}
31 odocstream & os() { return os_; }
33 TexRow & texrow() { return texrow_; }
35 void put(char_type const & c);
44 otexrowstream & operator<<(otexrowstream &, odocstream_manip);
46 otexrowstream & operator<<(otexrowstream &, docstring const &);
48 otexrowstream & operator<<(otexrowstream &, std::string const &);
50 otexrowstream & operator<<(otexrowstream &, char const *);
52 otexrowstream & operator<<(otexrowstream &, char);
54 template <typename Type>
55 otexrowstream & operator<<(otexrowstream & ots, Type value);
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.
68 class otexstream : public otexrowstream {
71 otexstream(odocstream & os, TexRow & texrow)
72 : otexrowstream(os, texrow), canbreakline_(false),
73 protectspace_(false), parbreak_(true), lastchar_(0) {}
75 void put(char_type const & c);
77 void canBreakLine(bool breakline) { canbreakline_ = breakline; }
79 bool canBreakLine() const { return canbreakline_; }
81 void protectSpace(bool protectspace) { protectspace_ = protectspace; }
83 bool protectSpace() const { return protectspace_; }
85 void lastChar(char_type const & c)
87 parbreak_ = (!canbreakline_ && c == '\n');
88 canbreakline_ = (c != '\n');
92 char_type lastChar() const { return lastchar_; }
94 bool afterParbreak() const { return parbreak_; }
106 /// Helper structs for breaking a line
111 struct SafeBreakLine {
115 extern BreakLine breakln;
116 extern SafeBreakLine safebreakln;
119 otexstream & operator<<(otexstream &, BreakLine);
121 otexstream & operator<<(otexstream &, SafeBreakLine);
123 otexstream & operator<<(otexstream &, odocstream_manip);
125 otexstream & operator<<(otexstream &, docstring const &);
127 otexstream & operator<<(otexstream &, std::string const &);
129 otexstream & operator<<(otexstream &, char const *);
131 otexstream & operator<<(otexstream &, char);
133 template <typename Type>
134 otexstream & operator<<(otexstream & ots, Type value);