]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_rowst.h
mathed47.diff
[lyx.git] / src / mathed / math_rowst.h
index 891f7656b95cd2e3abc42a1c219436d516d93f19..602198d3095a07b660b9e9af2e520a4c3767844f 100644 (file)
@@ -3,54 +3,57 @@
 #define MATH_ROWST_H
 
 #include <vector>
+#include "support/LAssert.h"
 
 /** The physical structure of a row and aditional information is stored here.
     It allows to manage the extra info independently of the paragraph data.  
     Only used for multiline paragraphs.
  */
-struct MathedRowSt
+
+class MathedRowStruct
 {
+public:
        ///
        typedef std::vector<int> Widths;
        
        ///
        explicit
-       MathedRowSt(int n)
+       MathedRowStruct(int n)
                : asc_(0), desc_(0), y_(0), widths_(n + 1, 0),
-                 numbered_(true), next_(0)
+                 numbered_(true)
                {}
-       /// Should be const but...
-       MathedRowSt * getNext() const  { return next_; }
-       /// ...we couldn't use this.
-       void setNext(MathedRowSt * n) { next_ = n; }
        ///
-       string const & getLabel() const { return label_; }
+       string const & getLabel() const;
        ///
-       bool isNumbered() const { return numbered_; }
+       bool isNumbered() const;
        ///
-       int  getBaseline() const { return y_; }
+       int  getBaseline() const;
        ///
-       void setBaseline(int b) { y_ = b; }
+       void setBaseline(int b);
        ///
-       int ascent() const { return asc_; }
+       int ascent() const;
        ///
-       int descent() const { return desc_; }
+       int descent() const;
        ///
-       void ascent(int a) { asc_ = a; }
+       void ascent(int a);
        ///
-       void descent(int d) { desc_ = d; }
+       void descent(int d);
        ///
-       int  getTab(int i) const { return widths_[i]; }
+       int  getTab(int i) const;
        /// 
-       void setLabel(string const & l) { label_ = l; }
+       void setLabel(string const & l);
        ///
-       void setNumbered(bool nf) { numbered_ = nf; }
+       void setNumbered(bool nf);
        ///
-       void setTab(int i, int t) { widths_[i] = t; }
-private:
+       void setTab(int i, int t);
+       ///
+       friend class MathedRowSt;
+protected:
        /// Vericals 
        int asc_;
+       ///
        int desc_;
+       ///
        int y_;
        /// widths 
        Widths widths_;
@@ -58,7 +61,167 @@ private:
        string label_;
        ///
        bool numbered_;
+};
+
+class MathedRowSt : public MathedRowStruct {
+public:
+       ///
+       explicit MathedRowSt(int n)
+                       : MathedRowStruct(n), next_(0)
+               {}
+       /// Should be const but...
+       MathedRowSt * getNext() const;
+       /// ...we couldn't use this.
+       void setNext(MathedRowSt * n);
+//private:
        ///
        MathedRowSt * next_;
 };
+
+
+// The idea is to change this  MathedRowContainer  to mimic the behaviour
+// of std::list<MathedRowStruct> in several small steps.  In the end it
+// could be replaced by such a list and MathedRowSt can go as well. 
+struct MathedRowContainer {
+       ///
+       struct iterator {
+               ///
+               iterator() : st_(0) {}
+               ///
+               explicit iterator(MathedRowSt * st) : st_(st) {}
+               /// "better" conversion to bool
+               explicit iterator(MathedRowContainer * m) : st_(m->data_) {}
+               /// "better" conversion to bool
+               operator void *() const { return st_; }
+               ///
+               MathedRowStruct & operator*() { Assert(st_); return *st_; }
+               ///
+               MathedRowStruct * operator->() { return st_; }
+               ///
+               MathedRowStruct const * operator->() const { return st_; }
+               ///
+               void operator++() { Assert(st_); st_ = st_->next_; }
+               ///
+               bool is_last() const { Assert(st_); return st_->next_ == 0; }
+               ///
+               bool operator==(const iterator & it) const { return st_ == it.st_; }
+
+       //private:
+               ///
+               MathedRowSt * st_;
+       };
+
+       ///
+       MathedRowContainer() : data_(0) {}
+       ///
+       MathedRowContainer(MathedRowSt * data) : data_(data) {}
+
+       ///
+       iterator begin() { return iterator(this); }
+       ///
+       bool empty() const { return data_ == 0; }
+
+       ///
+       MathedRowSt * data_;
+};
+
+
+
+inline
+MathedRowSt * MathedRowSt::getNext() const
+{
+       return next_;
+}
+
+
+inline
+void MathedRowSt::setNext(MathedRowSt * n)
+{
+       next_ = n;
+}
+
+
+inline
+string const & MathedRowStruct::getLabel() const
+{
+       return label_;
+}
+
+
+inline
+bool MathedRowStruct::isNumbered() const
+{
+       return numbered_;
+}
+
+
+inline
+int MathedRowStruct::getBaseline() const
+{
+       return y_;
+}
+
+
+inline
+void MathedRowStruct::setBaseline(int b)
+{
+       y_ = b;
+}
+
+
+inline
+int MathedRowStruct::ascent() const
+{
+       return asc_;
+}
+
+
+inline
+int MathedRowStruct::descent() const
+{
+       return desc_;
+}
+
+
+inline
+void MathedRowStruct::ascent(int a)
+{
+       asc_ = a;
+}
+
+
+inline
+void MathedRowStruct::descent(int d)
+{
+       desc_ = d;
+}
+
+
+inline
+int MathedRowStruct::getTab(int i) const
+{
+       return widths_[i];
+}
+
+
+inline
+void MathedRowStruct::setLabel(string const & l)
+{
+       label_ = l;
+}
+
+
+inline
+void MathedRowStruct::setNumbered(bool nf)
+{
+       numbered_ = nf;
+}
+
+
+inline
+void MathedRowStruct::setTab(int i, int t)
+{
+       widths_[i] = t;
+}
 #endif