shuffle (la)texstream around a bit

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19460 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-08-12 14:54:54 +00:00
parent 2515a3bded
commit 31d782b820
5 changed files with 51 additions and 39 deletions

View File

@ -47,6 +47,7 @@
#include "ParIterator.h"
#include "sgml.h"
#include "TexRow.h"
#include "TexStream.h"
#include "TocBackend.h"
#include "Undo.h"
#include "version.h"
@ -920,6 +921,8 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
if (!openFileWrite(ofs, fname))
return false;
//TexStream ts(ofs.rdbuf(), &texrow());
bool failed_export = false;
try {
writeLaTeXSource(ofs, original_path,

View File

@ -25,6 +25,8 @@ LYX_POST_LIBS = frontends/controllers/liblyxcontrollers.la \
OTHERLIBS = $(BOOST_LIBS) $(INTLLIBS) $(AIKSAURUS_LIBS) @LIBS@ $(SOCKET_LIBS)
AM_CPPFLAGS += $(PCH_FLAGS) -I$(srcdir)/.. $(BOOST_INCLUDES)
pkglib_LTLIBRARIES = liblyxcore.la
noinst_PROGRAMS = $(FRONTENDS_PROGS)
EXTRA_PROGRAMS = lyx-qt4
@ -224,6 +226,8 @@ liblyxcore_la_SOURCES = \
SpellBase.h \
TexRow.cpp \
TexRow.h \
TexStream.cpp \
TexStream.h \
Text.h \
Text.cpp \
Text2.cpp \
@ -457,8 +461,6 @@ EXTRA_DIST += \
insets/InsetTheorem.cpp \
insets/InsetTheorem.h
AM_CPPFLAGS += $(PCH_FLAGS) -I$(srcdir)/.. $(BOOST_INCLUDES)
liblyxinsets_la_SOURCES = \
insets/MailInset.cpp \
insets/MailInset.h \

View File

@ -20,7 +20,9 @@
namespace lyx {
/// Represents the correspondence between paragraphs and the generated LaTeX file
/// Represents the correspondence between paragraphs and the generated
//LaTeX file
class TexRow {
public:
///
@ -60,24 +62,13 @@ public:
{}
/// paragraph id
int id() const {
return id_;
}
int id() const { return id_; }
/// set paragraph position
void pos(int p) {
pos_ = p;
}
void pos(int p) { pos_ = p; }
/// paragraph position
int pos() const {
return pos_;
}
int pos() const { return pos_; }
/// row number
int rownumber() const {
return rownumber_;
}
int rownumber() const { return rownumber_; }
private:
RowItem();
int id_;

View File

@ -1,4 +1,5 @@
#include "LaTeXStream.h"
#include "TexStream.h"
#include "TexRow.h"
#include <iostream>
#include <streambuf>
@ -7,43 +8,50 @@ namespace lyx {
////////////////////////////////////////////////////////////////
//
// LaTeXStreamBuffer
// TexStreamBuffer
//
////////////////////////////////////////////////////////////////
class LaTeXStreamBuffer : public std::streambuf
class TexStreamBuffer : public TexStreamBase
{
public:
explicit LaTeXStreamBuffer(std::streambuf * sbuf);
TexStreamBuffer(TexStreamBase * sbuf, TexRow * texrow);
int line() const { return line_; }
int column() const { return column_; }
protected:
int overflow(int);
int sync();
private:
std::streambuf * sbuf_;
TexStreamBase * sbuf_;
TexRow * texrow_;
int column_;
int line_;
};
LaTeXStreamBuffer::LaTeXStreamBuffer(std::streambuf *sb)
: sbuf_(sb), line_(0)
TexStreamBuffer::TexStreamBuffer(TexStreamBase *sb, TexRow * texrow)
: sbuf_(sb), texrow_(texrow), line_(0)
{
setp(0, 0);
setg(0, 0, 0);
}
int LaTeXStreamBuffer::overflow(int c)
int TexStreamBuffer::overflow(int c)
{
if (c == '\n')
if (c == '\n') {
++line_;
column_ = 0;
} else {
++column_;
}
return c;
}
int LaTeXStreamBuffer::sync()
int TexStreamBuffer::sync()
{
sbuf_->pubsync();
return 0;
@ -52,22 +60,22 @@ int LaTeXStreamBuffer::sync()
////////////////////////////////////////////////////////////////
//
// LaTeXStream
// TexStream
//
////////////////////////////////////////////////////////////////
LaTeXStream::LaTeXStream(std::streambuf * sbuf)
: std::ostream(sbuf_ = new LaTeXStreamBuffer(sbuf))
TexStream::TexStream(TexStreamBase * sbuf, TexRow * texrow)
: std::basic_ostream<char_type>(sbuf_ = new TexStreamBuffer(sbuf, texrow))
{}
LaTeXStream::~LaTeXStream()
TexStream::~TexStream()
{
delete sbuf_;
}
int LaTeXStream::line() const
int TexStream::line() const
{
return sbuf_->line();
}
@ -83,7 +91,7 @@ int LaTeXStream::line() const
int main(int argc, char *argv[])
{
LaTeXStream out(std::cout.rdbuf());
TexStream out(std::cout.rdbuf());
char c;
while (std::cin) {
if (std::cin.get(c))

View File

@ -1,21 +1,29 @@
#ifndef LATEXSTREAM_H
#define LATEXSTREAM_H
#include "support/docstring.h"
#include "TexRow.h"
#include <iostream>
#include <streambuf>
namespace lyx {
class LaTeXStreamBuffer;
class TexStreamBuffer;
class TexRow;
class LaTeXStream : public std::ostream
typedef std::basic_streambuf<char_type> TexStreamBase;
class TexStream : public std::basic_ostream<char_type>
{
public:
LaTeXStream(std::streambuf * sbuf);
~LaTeXStream();
TexStream(TexStreamBase * sbuf, TexRow * texrow);
~TexStream();
int line() const;
private:
LaTeXStreamBuffer * sbuf_;
TexStreamBuffer * sbuf_;
};
} // namespace lyx