]> git.lyx.org Git - lyx.git/blobdiff - src/texstream.h
Make sure a pointer is valid before using it
[lyx.git] / src / texstream.h
index 282d210163189bb5e0a93bf816e2ca2b652bebf3..2c8299f0afc074bbe4e5347a92c1b07840d75d3a 100644 (file)
 #ifndef LYX_TEXSTREAM_H
 #define LYX_TEXSTREAM_H
 
-#include "TexRow.h"
 #include "support/docstream.h"
+#include "support/unique_ptr.h"
 
 namespace lyx {
 
+class TexRow;
+
+
+// declared below
+class otexstringstream;
+
 /** Wrapper class for odocstream.
     This class is used to automatically count the lines of the exported latex
-    code and also to ensure that no blank lines may be inadvertently output.
+    code.
+  */
+
+class otexrowstream {
+public:
+       ///
+       explicit otexrowstream(odocstream & os, bool enable = true);
+       /// defaulted
+       ~otexrowstream();
+       ///
+       odocstream & os() { return os_; }
+       ///
+       TexRow & texrow() { return *texrow_; }
+       ///
+       unique_ptr<TexRow> releaseTexRow();
+       ///
+       void put(char_type const & c);
+       ///
+       void append(docstring const & str, TexRow texrow);
+private:
+       ///
+       odocstream & os_;
+       ///
+       unique_ptr<TexRow> texrow_;
+};
+
+///
+otexrowstream & operator<<(otexrowstream &, odocstream_manip);
+///
+otexrowstream & operator<<(otexrowstream &, docstring const &);
+///
+otexrowstream & operator<<(otexrowstream &, std::string const &);
+///
+otexrowstream & operator<<(otexrowstream &, char const *);
+///
+otexrowstream & operator<<(otexrowstream &, char);
+///
+template <typename Type>
+otexrowstream & operator<<(otexrowstream & ots, Type value);
+
+
+/** Subclass for otexrowstream.
+    This class is used to ensure that no blank lines may be inadvertently output.
     To this end, use the special variables "breakln" and "safebreakln" as if
     they were iomanip's to ensure that the next output will start at the
     beginning of a line. Using "breakln", a '\n' char will be output if needed,
@@ -28,17 +76,13 @@ namespace lyx {
     a paragraph break was just output.
   */
 
-class otexstream {
+class otexstream : public otexrowstream {
 public:
        ///
-       otexstream(odocstream & os, TexRow & texrow)
-               : os_(os), texrow_(texrow), canbreakline_(false),
+       explicit otexstream(odocstream & os, bool enable = true)
+               : otexrowstream(os, enable), canbreakline_(false),
                  protectspace_(false), parbreak_(true), lastchar_(0) {}
        ///
-       odocstream & os() { return os_; }
-       ///
-       TexRow & texrow() { return texrow_; }
-       ///
        void put(char_type const & c);
        ///
        void canBreakLine(bool breakline) { canbreakline_ = breakline; }
@@ -60,10 +104,6 @@ public:
        ///
        bool afterParbreak() const { return parbreak_; }
 private:
-       ///
-       odocstream & os_;
-       ///
-       TexRow & texrow_;
        ///
        bool canbreakline_;
        ///
@@ -104,6 +144,7 @@ otexstream & operator<<(otexstream &, char);
 template <typename Type>
 otexstream & operator<<(otexstream & ots, Type value);
 
+
 }
 
 #endif