]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathStream.h
MathML stream allows for name spaces.
[lyx.git] / src / mathed / MathStream.h
index df9d61088f45b87d9d7ad018114babe6389569db..f6f6e7525d28665690814f60505288a53341740f 100644 (file)
@@ -293,6 +293,8 @@ private:
 //  MathML
 //
 
+
+/// Start tag.
 class MTag {
 public:
        ///
@@ -304,6 +306,8 @@ public:
        std::string attr_;
 };
 
+
+/// End tag.
 class ETag {
 public:
        ///
@@ -313,6 +317,19 @@ public:
 };
 
 
+/// Compound tag (no content, directly closed).
+class CTag {
+public:
+       ///
+       CTag(char const * const tag, std::string attr = "")
+            : tag_(tag), attr_(attr) {}
+       ///
+       char const * const tag_;
+    ///
+    std::string attr_;
+};
+
+
 /// Throw MathExportException to signal that the attempt to export
 /// some math in the current format did not succeed. E.g., we can't
 /// export xymatrix as MathML, so that will throw, and we'll fall back
@@ -322,8 +339,8 @@ class MathExportException : public std::exception {};
 
 class MathStream {
 public:
-       ///
-       explicit MathStream(odocstream & os);
+       /// Builds a stream proxy for os; the MathML namespace is given by xmlns (supposed to be already defined elsewhere in the document).
+       explicit MathStream(odocstream & os, std::string xmlns="");
        ///
        void cr();
        ///
@@ -342,6 +359,10 @@ public:
        docstring deferred() const;
        ///
        bool inText() const { return in_text_; }
+       ///
+       std::string xmlns() const { return xmlns_; }
+       /// Returns the tag name prefixed by the name space if needed.
+       std::string namespacedTag(std::string tag) const { return ((xmlns().empty()) ? "" : xmlns() + ":") + tag; }
 private:
        ///
        void setTextMode(bool t) { in_text_ = t; }
@@ -356,6 +377,8 @@ private:
        ///
        odocstringstream deferred_;
        ///
+       std::string xmlns_;
+       ///
        friend class SetMode;
 };
 
@@ -375,18 +398,20 @@ MathStream & operator<<(MathStream &, char_type);
 MathStream & operator<<(MathStream &, MTag const &);
 ///
 MathStream & operator<<(MathStream &, ETag const &);
+///
+MathStream & operator<<(MathStream &, CTag const &);
 
 
 /// A simpler version of ModeSpecifier, for MathML
 class SetMode {
 public:
        ///
-       explicit SetMode(MathStream & os, bool text);
+       explicit SetMode(MathStream & ms, bool text);
        ///
        ~SetMode();
 private:
        ///
-       MathStream & os_;
+       MathStream & ms_;
        ///
        bool was_text_;
 };