lyx_mirror/src/TexStream.cpp
André Pönitz 1a0f0fa186 some renamimg
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19458 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-12 14:03:48 +00:00

100 lines
1.5 KiB
C++

#include "LaTeXStream.h"
#include <iostream>
#include <streambuf>
namespace lyx {
////////////////////////////////////////////////////////////////
//
// LaTeXStreamBuffer
//
////////////////////////////////////////////////////////////////
class LaTeXStreamBuffer : public std::streambuf
{
public:
explicit LaTeXStreamBuffer(std::streambuf * sbuf);
int line() const { return line_; }
protected:
int overflow(int);
int sync();
private:
std::streambuf * sbuf_;
int line_;
};
LaTeXStreamBuffer::LaTeXStreamBuffer(std::streambuf *sb)
: sbuf_(sb), line_(0)
{
setp(0, 0);
setg(0, 0, 0);
}
int LaTeXStreamBuffer::overflow(int c)
{
if (c == '\n')
++line_;
return c;
}
int LaTeXStreamBuffer::sync()
{
sbuf_->pubsync();
return 0;
}
////////////////////////////////////////////////////////////////
//
// LaTeXStream
//
////////////////////////////////////////////////////////////////
LaTeXStream::LaTeXStream(std::streambuf * sbuf)
: std::ostream(sbuf_ = new LaTeXStreamBuffer(sbuf))
{}
LaTeXStream::~LaTeXStream()
{
delete sbuf_;
}
int LaTeXStream::line() const
{
return sbuf_->line();
}
////////////////////////////////////////////////////////////////
//
// Test
//
////////////////////////////////////////////////////////////////
#if 0
int main(int argc, char *argv[])
{
LaTeXStream out(std::cout.rdbuf());
char c;
while (std::cin) {
if (std::cin.get(c))
out.put(c);
}
std::cout << "line count: " << out.line() << std::endl;
return 0;
}
#endif
}