Another minor change, but this should almost get us to the point that we
[lyx.git] / src / TexStream.cpp
blob3ac285ee13b15d4f3c7c53ec0311cd7b99e49a17
1 /**
2 * \file TexStream.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * Full author contact details are available in file CREDITS.
8 * Inspired by Dietmar Kuehl's prefix iostreams found on
9 * http://www.inf.uni-konstanz.de/~kuehl/
12 #include <config.h>
14 #include "TexStream.h"
15 #include "TexRow.h"
17 #include <iostream>
18 #include <streambuf>
20 namespace lyx {
22 ////////////////////////////////////////////////////////////////
24 // TexStreamBuffer
26 ////////////////////////////////////////////////////////////////
29 class TexStreamBuffer : public TexStreamBase
31 public:
32 TexStreamBuffer(TexStreamBase * sbuf, TexRow * texrow);
33 int line() const { return line_; }
34 int column() const { return column_; }
36 protected:
37 int overflow(int);
38 int sync();
40 private:
41 TexStreamBase * sbuf_;
42 TexRow * texrow_;
43 int column_;
44 int line_;
48 TexStreamBuffer::TexStreamBuffer(TexStreamBase *sb, TexRow * texrow)
49 : sbuf_(sb), texrow_(texrow), line_(0)
51 setp(0, 0);
52 setg(0, 0, 0);
55 int TexStreamBuffer::overflow(int c)
57 if (c == '\n') {
58 ++line_;
59 column_ = 0;
60 } else {
61 ++column_;
63 return c;
67 int TexStreamBuffer::sync()
69 sbuf_->pubsync();
70 return 0;
74 ////////////////////////////////////////////////////////////////
76 // TexStream
78 ////////////////////////////////////////////////////////////////
80 TexStream::TexStream(TexStreamBase * sbuf, TexRow * texrow)
81 : std::basic_ostream<char_type>(sbuf_ = new TexStreamBuffer(sbuf, texrow))
85 TexStream::~TexStream()
87 delete sbuf_;
91 int TexStream::line() const
93 return sbuf_->line();
97 ////////////////////////////////////////////////////////////////
99 // Test
101 ////////////////////////////////////////////////////////////////
103 #if 0
105 int main(int argc, char *argv[])
107 TexStream out(cout.rdbuf());
108 char c;
109 while (cin) {
110 if (cin.get(c))
111 out.put(c);
113 cout << "line count: " << out.line() << endl;
115 return 0;
118 #endif