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