From db95a4d876c75b0c373c97216fc1fa4bec7189f4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Wed, 14 Feb 2001 17:50:58 +0000 Subject: [PATCH] mathed17.diff + some iterator methods git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1512 a592a061-630c-0410-9148-cb99ea01b6c8 --- po/POTFILES.in | 34 +++++++++---------- src/mathed/ChangeLog | 11 +++++- src/mathed/array.C | 75 ++++++++++++++++++++++++----------------- src/mathed/array.h | 28 +++++++++------ src/mathed/math_xiter.C | 8 +++-- 5 files changed, 96 insertions(+), 60 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index cf8fdaa1f2..7739bbbcca 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -66,44 +66,44 @@ src/frontends/kde/tocdlg.C src/frontends/kde/urldlg.C src/frontends/qt2/FormCopyright.C src/frontends/xforms/FormBase.h -src/frontends/xforms/FormBibitem.C src/frontends/xforms/form_bibitem.C -src/frontends/xforms/FormBibtex.C +src/frontends/xforms/FormBibitem.C src/frontends/xforms/form_bibtex.C +src/frontends/xforms/FormBibtex.C src/frontends/xforms/form_browser.C -src/frontends/xforms/FormCitation.C src/frontends/xforms/form_citation.C -src/frontends/xforms/FormCopyright.C +src/frontends/xforms/FormCitation.C src/frontends/xforms/form_copyright.C -src/frontends/xforms/FormDocument.C +src/frontends/xforms/FormCopyright.C src/frontends/xforms/form_document.C -src/frontends/xforms/FormError.C +src/frontends/xforms/FormDocument.C src/frontends/xforms/form_error.C -src/frontends/xforms/FormGraphics.C +src/frontends/xforms/FormError.C src/frontends/xforms/form_graphics.C -src/frontends/xforms/FormInclude.C +src/frontends/xforms/FormGraphics.C src/frontends/xforms/form_include.C -src/frontends/xforms/FormIndex.C +src/frontends/xforms/FormInclude.C src/frontends/xforms/form_index.C +src/frontends/xforms/FormIndex.C src/frontends/xforms/FormInset.h src/frontends/xforms/FormLog.C -src/frontends/xforms/FormParagraph.C src/frontends/xforms/form_paragraph.C -src/frontends/xforms/FormPreferences.C +src/frontends/xforms/FormParagraph.C src/frontends/xforms/form_preferences.C -src/frontends/xforms/FormPrint.C +src/frontends/xforms/FormPreferences.C src/frontends/xforms/form_print.C -src/frontends/xforms/FormRef.C +src/frontends/xforms/FormPrint.C src/frontends/xforms/form_ref.C +src/frontends/xforms/FormRef.C src/frontends/xforms/FormSplash.C -src/frontends/xforms/FormTabular.C src/frontends/xforms/form_tabular.C -src/frontends/xforms/FormTabularCreate.C +src/frontends/xforms/FormTabular.C src/frontends/xforms/form_tabular_create.C -src/frontends/xforms/FormToc.C +src/frontends/xforms/FormTabularCreate.C src/frontends/xforms/form_toc.C -src/frontends/xforms/FormUrl.C +src/frontends/xforms/FormToc.C src/frontends/xforms/form_url.C +src/frontends/xforms/FormUrl.C src/frontends/xforms/FormVCLog.C src/frontends/xforms/input_validators.C src/frontends/xforms/Menubar_pimpl.C diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 090344a9f8..2314eadfba 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,12 @@ +2001-02-14 Lars Gullik Bjønnes + + * array.C (begin): new method + (end): ditto + +2001-02-14 André Pönitz + + * math_iter.[Ch]: remove 'insert', 'maxsize' and 'ARRAY_SIZE' + 2001-02-14 Jean-Marc Lasgouttes * math_spaceinset.C: @@ -13,7 +22,7 @@ * math_accentinset.C: * math_sqrtinset.C: include LOstream.h and add using directive. -2001-02-12 André Pönitz +2001-02-14 André Pönitz * math_iter.C: reformatting diff --git a/src/mathed/array.C b/src/mathed/array.C index 060effb046..245b801a2f 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -18,6 +18,38 @@ void * my_memcpy(void * ps_in, void const * pt_in, size_t n) } +MathedArray::MathedArray(int size) + : last_(0) +{ + int const newsize = (size < ARRAY_MIN_SIZE) ? ARRAY_MIN_SIZE : size; + bf_.resize(newsize); +} + + +MathedArray::iterator MathedArray::begin() +{ + return bf_.begin(); +} + + +MathedArray::iterator MathedArray::end() +{ + return bf_.end(); +} + + +MathedArray::const_iterator MathedArray::begin() const +{ + return bf_.begin(); +} + + +MathedArray::const_iterator MathedArray::end() const +{ + return bf_.end(); +} + + int MathedArray::empty() const { return (last_ == 0); @@ -36,15 +68,9 @@ void MathedArray::last(int l) } -int MathedArray::maxsize() const -{ - return static_cast(bf_.size()); -} - - void MathedArray::need_size(int needed) { - if (needed >= maxsize()) + if (needed >= static_cast(bf_.size())) resize(needed); } @@ -55,19 +81,12 @@ void MathedArray::resize(int newsize) newsize = ARRAY_MIN_SIZE; newsize += ARRAY_STEP - (newsize % ARRAY_STEP); bf_.resize(newsize); - if (last_ >= newsize) last_ = newsize - 1; + if (last_ >= newsize) + last_ = newsize - 1; bf_[last_] = 0; } -MathedArray::MathedArray(int size) -{ - int newsize = (size < ARRAY_MIN_SIZE) ? ARRAY_MIN_SIZE : size; - bf_.resize(newsize); - last_ = 0; -} - - void MathedArray::move(int p, int shift) { if (p <= last_) { @@ -79,10 +98,20 @@ void MathedArray::move(int p, int shift) } +#if 0 +void MathedArray::insert(MathedArray::iterator pos, + MathedArray::const_iterator beg, + MathedArray::const_iterator end) +{ + bf_.insert(pos, beg, end); + last_ = bf_.size() - 1; +} +#else void MathedArray::mergeF(MathedArray * a, int p, int dx) { my_memcpy(&bf_[p], &a->bf_[0], dx); } +#endif void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const @@ -114,17 +143,3 @@ byte & MathedArray::operator[](int i) { return bf_[i]; } - - -void MathedArray::insert(int pos, byte c) -{ - if (pos < 0) pos = last_; - - // I think this should be replaced by need_size(pos). Note that the - // current code looks troublesome if pos > maxsize() + ARRAY_STEP. - if (pos >= maxsize()) - resize(maxsize() + ARRAY_STEP); - bf_[pos] = c; - if (pos >= last_) - last_ = pos + 1; -} diff --git a/src/mathed/array.h b/src/mathed/array.h index 7801fcd7dd..c9d042587a 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -42,10 +42,11 @@ public: typedef std::vector buffer_type; typedef byte value_type; typedef buffer_type::size_type size_type; + typedef buffer_type::iterator iterator; + typedef buffer_type::const_iterator const_iterator; + /// enum { - /// - ARRAY_SIZE = 256, /// ARRAY_STEP = 16, /// @@ -56,6 +57,15 @@ public: explicit MathedArray(int size = ARRAY_STEP); + /// + iterator begin(); + /// + iterator end(); + /// + const_iterator begin() const; + /// + const_iterator end() const; + /// int empty() const; @@ -63,14 +73,15 @@ public: int last() const; /// void last(int l); - + +#if 0 + /// + void insert(iterator pos, const_iterator beg, const_iterator end); +#else /// Merge \a dx elements from array \a a at \apos. /// This doesn't changes the size (dangerous) void mergeF(MathedArray * a, int pos, int dx); - - /// Insert a character at position \a pos - void insert(int pos, byte); - +#endif /// void raw_pointer_copy(MathedInset ** p, int pos) const; /// @@ -86,12 +97,9 @@ public: void move(int p, int shift); /// void resize(int newsize); - /// - int maxsize() const; /// Make sure we can access at least \a needed elements void need_size(int needed); private: - /// Buffer buffer_type bf_; /// Last position inserted. diff --git a/src/mathed/math_xiter.C b/src/mathed/math_xiter.C index 046257659f..40ca0eba33 100644 --- a/src/mathed/math_xiter.C +++ b/src/mathed/math_xiter.C @@ -137,11 +137,15 @@ void MathedXIter::Merge(MathedArray * a0) // All insets must be clonned MathedIter it(a0); MathedArray * a = it.Copy(); - + +#if 0 + array->insert(array->begin() + pos, + a->begin(), a->end()); +#else // make room for the data split(a->last()); array->mergeF(a, pos, a->last()); - +#endif int pos1 = pos; int pos2 = pos + a->last(); -- 2.39.2