]> git.lyx.org Git - lyx.git/blob - src/TexStream.cpp
Kill LFUN_PARAGRAPH_SPACING in favour of LFUN_PARAGRAPH_PARAMS.
[lyx.git] / src / TexStream.cpp
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.
5  *
6  * Full author contact details are available in file CREDITS.
7  *
8  * Inspired by Dietmar Kuehl's prefix iostreams found on
9  * http://www.inf.uni-konstanz.de/~kuehl/
10  */
11
12 #include <config.h>
13
14 #include "TexStream.h"
15 #include "TexRow.h"
16
17 #include <iostream>
18 #include <streambuf>
19
20 namespace lyx {
21
22 ////////////////////////////////////////////////////////////////
23 //
24 // TexStreamBuffer
25 //
26 ////////////////////////////////////////////////////////////////
27
28
29 class TexStreamBuffer : public TexStreamBase
30 {
31 public:
32         TexStreamBuffer(TexStreamBase * sbuf, TexRow * texrow);
33         int line() const { return line_; }
34         int column() const { return column_; }
35
36 protected:
37         int overflow(int);
38         int sync();
39
40 private:
41         TexStreamBase * sbuf_; 
42         TexRow * texrow_;
43         int column_;
44         int line_;
45 };
46
47
48 TexStreamBuffer::TexStreamBuffer(TexStreamBase *sb, TexRow * texrow)
49   : sbuf_(sb), texrow_(texrow), line_(0)
50 {
51         setp(0, 0);
52         setg(0, 0, 0);
53 }
54
55 int TexStreamBuffer::overflow(int c)
56 {
57         if (c == '\n') {
58                 ++line_;
59                 column_ = 0;
60         } else {
61                 ++column_;
62         }
63         return c;
64 }
65
66
67 int TexStreamBuffer::sync()
68 {
69         sbuf_->pubsync();
70         return 0;
71 }
72
73   
74 ////////////////////////////////////////////////////////////////
75 //
76 // TexStream
77 //
78 ////////////////////////////////////////////////////////////////
79
80 TexStream::TexStream(TexStreamBase * sbuf, TexRow * texrow)
81                 : std::basic_ostream<char_type>(sbuf_ = new TexStreamBuffer(sbuf, texrow))
82 {}
83
84
85 TexStream::~TexStream()
86 {
87         delete sbuf_;
88 }
89
90
91 int TexStream::line() const
92 {
93         return sbuf_->line();
94 }
95
96
97 ////////////////////////////////////////////////////////////////
98 //
99 // Test
100 //
101 ////////////////////////////////////////////////////////////////
102
103 #if 0
104
105 int main(int argc, char *argv[])
106 {
107         TexStream out(cout.rdbuf());
108         char c;
109         while (cin) {
110                 if (cin.get(c))
111                         out.put(c);
112         }
113         cout << "line count: " << out.line() << endl;
114
115         return 0;
116 }
117
118 #endif
119
120 }
121