]> git.lyx.org Git - features.git/blobdiff - src/mathed/math_rowst.h
mathed57.diff
[features.git] / src / mathed / math_rowst.h
index 222a8eb5e06f384c137528c4d0a28c7ad9f68161..0eeb0810814272f5f774a9a81ae9d75e5b90248e 100644 (file)
@@ -17,10 +17,8 @@ public:
        typedef std::vector<int> Widths;
        
        ///
-       explicit
-       MathedRowStruct(int n)
-               : asc_(0), desc_(0), y_(0), widths_(n + 1, 0),
-                 numbered_(true)
+       MathedRowStruct()
+               : asc_(0), desc_(0), y_(0), numbered_(true)
                {}
        ///
        string const & getLabel() const;
@@ -64,25 +62,6 @@ protected:
 };
 
 
-class MathedRowContainer;
-
-class MathedRowSt : public MathedRowStruct {
-public:
-       ///
-       explicit MathedRowSt(int n)
-                       : MathedRowStruct(n), next_(0)
-               {}
-       explicit MathedRowSt(MathedRowStruct const & t)
-                       : MathedRowStruct(t), next_(0)
-               {}
-//private:
-       ///
-       MathedRowSt * next_;
-       ///
-       friend class MathedRowContainer;
-};
-
-
 // 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. 
@@ -91,104 +70,51 @@ struct MathedRowContainer {
        ///
        struct iterator {
                ///
-               iterator() : st_(0) {}
-               ///
-               explicit iterator(MathedRowSt * st) : st_(st) {}
+               iterator() : st_(0), pos_(0) {}
                ///
-               explicit iterator(MathedRowContainer * m) : st_(m->data_) {}
-               /// "better" conversion to bool
-               operator void *() const { return st_; }
+               explicit iterator(MathedRowContainer * m) : st_(m), pos_(0) {}
+               /// "better" conversion to bool, static_cast doens't help?
+               operator void *() const
+                       { return (void *)(st_ && pos_ < st_->data_.size()); }
                ///
-               MathedRowStruct & operator*() { Assert(st_); return *st_; }
+               MathedRowStruct & operator*() { Assert(st_); return st_->data_[pos_]; }
                ///
-               MathedRowStruct * operator->() { return st_; }
+               MathedRowStruct * operator->() { return &st_->data_[pos_]; }
                ///
-               MathedRowStruct const * operator->() const { return st_; }
+               MathedRowStruct const * operator->() const { return &st_->data_[pos_]; }
                ///
-               void operator++() { Assert(st_); st_ = st_->next_; }
+               void operator++() { Assert(st_); ++pos_; }
                ///
-               bool is_last() const { Assert(st_); return st_->next_ == 0; }
+               bool is_last() const { Assert(st_); return pos_ == st_->data_.size() - 1; }
                ///
-               bool operator==(const iterator & it) const { return st_ == it.st_; }
+               bool operator==(const iterator & it) const
+                       { return st_ == it.st_ && pos_ == it.pos_; }
 
        //private:
                ///
-               MathedRowSt * st_;
+               MathedRowContainer * st_;
+               ///
+               unsigned int pos_;
        };
 
-       ///
-       MathedRowContainer() : data_(0) {}
-
-       ///
-       MathedRowContainer(MathedRowContainer const & c) : data_(0) {
-               if (!c.empty()) {
-                       MathedRowSt * ro = 0;
-                       MathedRowSt * mrow = c.data_;
-
-                       while (mrow) {
-                               MathedRowSt * r = new MathedRowSt(*mrow);
-                               if (!ro) 
-                                       data_ = r;
-                               else
-                                       ro->next_ = r;
-                               mrow = mrow->next_;
-                               ro = r;
-                       }
-               }
-       }
-
-               
-       ~MathedRowContainer() {
-               MathedRowSt * r = data_;
-               while (r) {
-                       MathedRowSt * q = r->next_;
-                       delete r;
-                       r = q;
-               }
-       }
-
        ///
        iterator begin() { return iterator(this); }
        ///
-       bool empty() const { return data_ == 0; }
+       bool empty() const { return data_.size() == 0; }
 
        /// insert 'item' before 'iterator'
-       void insert(iterator const & it, MathedRowStruct const & item) {
-               MathedRowSt * r = new MathedRowSt(item);
-               if (data_ == it.st_)
-                       data_ = r;
-               else {
-                       MathedRowSt * pos = data_;
-                       if (pos->next_ == it.st_)
-                               pos->next_ = r;
-               }
-               r->next_  = it.st_;
+       void insert(iterator const & it) {
+               Assert(it.st_ == this);
+               data_.insert(data_.begin() + it.pos_, MathedRowStruct());
        }
                        
-       /// insert 'item' after 'iterator'
-       void insert_after(iterator & it, MathedRowStruct const & item) {
-               MathedRowSt * r = new MathedRowSt(item);
-               if (it) {
-                       r->next_ = it.st_->next_;
-                       it.st_->next_ = r;
-               } else {
-                       it.st_ = r;
-                       r->next_ = 0;
-               }
-       }
-
        void erase(iterator & it) {
-               Assert(it.st_);
-               MathedRowSt * r = it.st_->next_;
-    if (r) {
-      it.st_->next_ = r->next_;
-      delete r;
-    }
+               Assert(it.st_ == this);
+               data_.erase(data_.begin() + it.pos_);
        }
 
-
        ///
-       MathedRowSt * data_;
+       std::vector<MathedRowStruct> data_;
 
 private:
        // currently unimplemented just to make sure it's not used