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 /** Wrapper class for odocstream.
25 This class is used to automatically count the lines of the exported latex
32 explicit otexrowstream(odocstream & os);
36 odocstream & os() { return os_; }
38 TexRow & texrow() { return *texrow_; }
40 unique_ptr<TexRow> releaseTexRow();
42 void put(char_type const & c);
44 void append(TexString ts);
49 unique_ptr<TexRow> texrow_;
53 otexrowstream & operator<<(otexrowstream &, odocstream_manip);
55 otexrowstream & operator<<(otexrowstream &, TexString);
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), terminate_command_(false),
85 parbreak_(true), blankline_(true), lastchar_(0) {}
87 void put(char_type const & c);
89 void append(TexString ts);
91 void canBreakLine(bool breakline) { canbreakline_ = breakline; }
93 bool canBreakLine() const { return canbreakline_; }
95 void protectSpace(bool protectspace) { protectspace_ = protectspace; }
97 bool protectSpace() const { return protectspace_; }
99 void terminateCommand(bool terminate) { terminate_command_ = terminate; }
101 bool terminateCommand() const { return terminate_command_; }
103 void lastChar(char_type const & c)
105 parbreak_ = (!canbreakline_ && c == '\n');
106 blankline_ = ((!canbreakline_ && c == ' ') || c == '\n');
107 canbreakline_ = (c != '\n');
111 char_type lastChar() const { return lastchar_; }
113 bool afterParbreak() const { return parbreak_; }
115 bool blankLine() const { return blankline_; }
122 bool terminate_command_;
132 /// because we need to pass ods_ to the base class
133 struct otexstringstream_helper { odocstringstream ods_; };
135 /// otexstringstream : a odocstringstream with tex/row correspondence
136 class otexstringstream : otexstringstream_helper, public otexstream {
138 otexstringstream() : otexstringstream_helper(), otexstream(ods_) {}
140 docstring str() const { return ods_.str(); }
144 bool empty() { return 0 == length(); }
145 /// move-returns the contents and reset the texstream
150 /// Helper structs for breaking a line
155 struct SafeBreakLine {
159 /// Helper structs for terminating a command
160 struct TerminateCommand {
164 extern BreakLine breakln;
165 extern SafeBreakLine safebreakln;
166 extern TerminateCommand termcmd;
169 otexstream & operator<<(otexstream &, BreakLine);
171 otexstream & operator<<(otexstream &, SafeBreakLine);
173 otexstream & operator<<(otexstream &, TerminateCommand);
175 otexstream & operator<<(otexstream &, odocstream_manip);
177 otexstream & operator<<(otexstream &, TexString);
179 otexstream & operator<<(otexstream &, docstring const &);
181 otexstream & operator<<(otexstream &, std::string const &);
183 otexstream & operator<<(otexstream &, char const *);
185 otexstream & operator<<(otexstream &, char);
187 template <typename Type>
188 otexstream & operator<<(otexstream & ots, Type value);