]> git.lyx.org Git - lyx.git/blobdiff - src/TexStream.cpp
Natbib authoryear uses (Ref1; Ref2) by default.
[lyx.git] / src / TexStream.cpp
index b3d9f50362b28bda4ffdc185973fcdfa83c5c103..dc1c43c2a9846c318147e0d24ce9d4092ebc288c 100644 (file)
@@ -1,4 +1,18 @@
-#include "LaTeXStream.h"
+/**
+ * \file TexStream.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * Full author contact details are available in file CREDITS.
+ *
+ * Inspired by Dietmar Kuehl's prefix iostreams found on
+ * http://www.inf.uni-konstanz.de/~kuehl/
+ */
+
+#include <config.h>
+
+#include "TexStream.h"
+#include "TexRow.h"
 
 #include <iostream>
 #include <streambuf>
@@ -7,67 +21,74 @@ 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();
+       int_type overflow(int_type);
+       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);
+       setp(0, 0);
+       setg(0, 0, 0);
 }
 
-int LaTeXStreamBuffer::overflow(int c)
+TexStreamBuffer::int_type TexStreamBuffer::overflow(TexStreamBuffer::int_type c)
 {
-       if (c == '\n')
+       if (c == '\n') {
                ++line_;
+               column_ = 0;
+       } else {
+               ++column_;
+       }
        return c;
 }
 
 
-int LaTeXStreamBuffer::sync()
+int TexStreamBuffer::sync()
 {
-  sbuf_->pubsync();
-  return 0;
+       sbuf_->pubsync();
+       return 0;
 }
 
   
 ////////////////////////////////////////////////////////////////
 //
-// 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,17 +104,18 @@ int LaTeXStream::line() const
 
 int main(int argc, char *argv[])
 {
-       LaTeXStream out(std::cout.rdbuf());
+       TexStream out(cout.rdbuf());
        char c;
-       while (std::cin) {
-               if (std::cin.get(c))
+       while (cin) {
+               if (cin.get(c))
                        out.put(c);
        }
-       std::cout << "line count: " << out.line() << std::endl;
+       cout << "line count: " << out.line() << endl;
 
-  return 0;
+       return 0;
 }
 
 #endif
 
 }
+