2015-01-09 20:07:59 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file texstream.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Enrico Forestieri
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LYX_TEXSTREAM_H
|
|
|
|
#define LYX_TEXSTREAM_H
|
|
|
|
|
|
|
|
#include "support/docstream.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "support/unique_ptr.h"
|
2015-01-09 20:07:59 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2016-06-19 02:39:38 +00:00
|
|
|
class TexRow;
|
2016-10-17 22:54:37 +00:00
|
|
|
struct TexString;
|
2016-06-19 02:39:38 +00:00
|
|
|
|
|
|
|
|
2015-01-09 20:07:59 +00:00
|
|
|
/** Wrapper class for odocstream.
|
|
|
|
This class is used to automatically count the lines of the exported latex
|
2015-10-07 03:02:40 +00:00
|
|
|
code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class otexrowstream {
|
|
|
|
public:
|
|
|
|
///
|
2016-09-04 02:02:47 +00:00
|
|
|
explicit otexrowstream(odocstream & os);
|
2016-06-19 02:39:38 +00:00
|
|
|
/// defaulted
|
|
|
|
~otexrowstream();
|
2015-10-07 03:02:40 +00:00
|
|
|
///
|
|
|
|
odocstream & os() { return os_; }
|
|
|
|
///
|
2016-06-19 02:39:38 +00:00
|
|
|
TexRow & texrow() { return *texrow_; }
|
|
|
|
///
|
2016-07-04 02:43:22 +00:00
|
|
|
unique_ptr<TexRow> releaseTexRow();
|
2015-10-07 03:02:40 +00:00
|
|
|
///
|
|
|
|
void put(char_type const & c);
|
2015-10-13 22:51:50 +00:00
|
|
|
///
|
2016-09-04 02:21:19 +00:00
|
|
|
void append(TexString ts);
|
2015-10-07 03:02:40 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
odocstream & os_;
|
|
|
|
///
|
2016-06-19 02:39:38 +00:00
|
|
|
unique_ptr<TexRow> texrow_;
|
2015-10-07 03:02:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///
|
|
|
|
otexrowstream & operator<<(otexrowstream &, odocstream_manip);
|
|
|
|
///
|
2016-09-04 02:21:19 +00:00
|
|
|
otexrowstream & operator<<(otexrowstream &, TexString);
|
|
|
|
///
|
2015-10-07 03:02:40 +00:00
|
|
|
otexrowstream & operator<<(otexrowstream &, docstring const &);
|
|
|
|
///
|
|
|
|
otexrowstream & operator<<(otexrowstream &, std::string const &);
|
|
|
|
///
|
|
|
|
otexrowstream & operator<<(otexrowstream &, char const *);
|
|
|
|
///
|
|
|
|
otexrowstream & operator<<(otexrowstream &, char);
|
|
|
|
///
|
|
|
|
template <typename Type>
|
|
|
|
otexrowstream & operator<<(otexrowstream & ots, Type value);
|
|
|
|
|
|
|
|
|
|
|
|
/** Subclass for otexrowstream.
|
|
|
|
This class is used to ensure that no blank lines may be inadvertently output.
|
2015-01-09 20:07:59 +00:00
|
|
|
To this end, use the special variables "breakln" and "safebreakln" as if
|
|
|
|
they were iomanip's to ensure that the next output will start at the
|
|
|
|
beginning of a line. Using "breakln", a '\n' char will be output if needed,
|
|
|
|
while using "safebreakln", "%\n" will be output if needed.
|
|
|
|
The class also records the last output character and can tell whether
|
|
|
|
a paragraph break was just output.
|
|
|
|
*/
|
|
|
|
|
2015-10-07 03:02:40 +00:00
|
|
|
class otexstream : public otexrowstream {
|
2015-01-09 20:07:59 +00:00
|
|
|
public:
|
|
|
|
///
|
2016-09-04 02:02:47 +00:00
|
|
|
explicit otexstream(odocstream & os)
|
|
|
|
: otexrowstream(os), canbreakline_(false),
|
2016-12-12 14:55:28 +00:00
|
|
|
protectspace_(false), terminate_command_(false),
|
2018-12-06 09:30:58 +00:00
|
|
|
parbreak_(true), blankline_(true), lastchar_(0) {}
|
2015-01-09 20:07:59 +00:00
|
|
|
///
|
|
|
|
void put(char_type const & c);
|
|
|
|
///
|
2016-09-04 02:21:19 +00:00
|
|
|
void append(TexString ts);
|
|
|
|
///
|
2015-01-09 20:07:59 +00:00
|
|
|
void canBreakLine(bool breakline) { canbreakline_ = breakline; }
|
|
|
|
///
|
|
|
|
bool canBreakLine() const { return canbreakline_; }
|
|
|
|
///
|
|
|
|
void protectSpace(bool protectspace) { protectspace_ = protectspace; }
|
|
|
|
///
|
|
|
|
bool protectSpace() const { return protectspace_; }
|
|
|
|
///
|
2016-12-12 14:55:28 +00:00
|
|
|
void terminateCommand(bool terminate) { terminate_command_ = terminate; }
|
|
|
|
///
|
|
|
|
bool terminateCommand() const { return terminate_command_; }
|
|
|
|
///
|
2015-01-09 20:07:59 +00:00
|
|
|
void lastChar(char_type const & c)
|
|
|
|
{
|
|
|
|
parbreak_ = (!canbreakline_ && c == '\n');
|
2018-12-06 09:30:58 +00:00
|
|
|
blankline_ = ((!canbreakline_ && c == ' ') || c == '\n');
|
2015-01-09 20:07:59 +00:00
|
|
|
canbreakline_ = (c != '\n');
|
|
|
|
lastchar_ = c;
|
|
|
|
}
|
|
|
|
///
|
|
|
|
char_type lastChar() const { return lastchar_; }
|
|
|
|
///
|
|
|
|
bool afterParbreak() const { return parbreak_; }
|
2018-12-06 09:30:58 +00:00
|
|
|
///
|
|
|
|
bool blankLine() const { return blankline_; }
|
2015-01-09 20:07:59 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
bool canbreakline_;
|
|
|
|
///
|
|
|
|
bool protectspace_;
|
|
|
|
///
|
2016-12-12 14:55:28 +00:00
|
|
|
bool terminate_command_;
|
|
|
|
///
|
2015-01-09 20:07:59 +00:00
|
|
|
bool parbreak_;
|
|
|
|
///
|
2018-12-06 09:30:58 +00:00
|
|
|
bool blankline_;
|
|
|
|
///
|
2015-01-09 20:07:59 +00:00
|
|
|
char_type lastchar_;
|
|
|
|
};
|
|
|
|
|
2016-09-04 02:21:19 +00:00
|
|
|
|
|
|
|
/// because we need to pass ods_ to the base class
|
|
|
|
struct otexstringstream_helper { odocstringstream ods_; };
|
|
|
|
|
|
|
|
/// otexstringstream : a odocstringstream with tex/row correspondence
|
|
|
|
class otexstringstream : otexstringstream_helper, public otexstream {
|
|
|
|
public:
|
|
|
|
otexstringstream() : otexstringstream_helper(), otexstream(ods_) {}
|
|
|
|
///
|
|
|
|
docstring str() const { return ods_.str(); }
|
|
|
|
///
|
|
|
|
size_t length();
|
|
|
|
///
|
|
|
|
bool empty() { return 0 == length(); }
|
|
|
|
/// move-returns the contents and reset the texstream
|
|
|
|
TexString release();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-09 20:07:59 +00:00
|
|
|
/// Helper structs for breaking a line
|
|
|
|
struct BreakLine {
|
|
|
|
char n;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SafeBreakLine {
|
|
|
|
char n;
|
|
|
|
};
|
|
|
|
|
2016-12-12 14:55:28 +00:00
|
|
|
/// Helper structs for terminating a command
|
|
|
|
struct TerminateCommand {
|
|
|
|
char n;
|
|
|
|
};
|
|
|
|
|
2015-01-09 20:07:59 +00:00
|
|
|
extern BreakLine breakln;
|
|
|
|
extern SafeBreakLine safebreakln;
|
2016-12-12 14:55:28 +00:00
|
|
|
extern TerminateCommand termcmd;
|
2015-01-09 20:07:59 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
otexstream & operator<<(otexstream &, BreakLine);
|
|
|
|
///
|
|
|
|
otexstream & operator<<(otexstream &, SafeBreakLine);
|
|
|
|
///
|
2016-12-12 14:55:28 +00:00
|
|
|
otexstream & operator<<(otexstream &, TerminateCommand);
|
|
|
|
///
|
2015-01-09 20:07:59 +00:00
|
|
|
otexstream & operator<<(otexstream &, odocstream_manip);
|
|
|
|
///
|
2016-09-04 02:21:19 +00:00
|
|
|
otexstream & operator<<(otexstream &, TexString);
|
|
|
|
///
|
2015-01-09 20:07:59 +00:00
|
|
|
otexstream & operator<<(otexstream &, docstring const &);
|
|
|
|
///
|
|
|
|
otexstream & operator<<(otexstream &, std::string const &);
|
|
|
|
///
|
|
|
|
otexstream & operator<<(otexstream &, char const *);
|
|
|
|
///
|
|
|
|
otexstream & operator<<(otexstream &, char);
|
|
|
|
///
|
|
|
|
template <typename Type>
|
|
|
|
otexstream & operator<<(otexstream & ots, Type value);
|
|
|
|
|
2016-06-19 02:39:38 +00:00
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace lyx
|
2015-01-09 20:07:59 +00:00
|
|
|
|
|
|
|
#endif
|