From 13c24dd556a8b1998a29f9a88f2ceda5c5365590 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sat, 6 Nov 2004 15:23:12 +0000 Subject: [PATCH] * lyxfunctional.h: delete back_inserter_fun functions and helper classes. * lyx_gui.C (start): use for_each instead of explicit for loop * cursor.C (insert): use for_each instead of explicit for loop * bufferlist.C (getFileNames): use std::transform and std::back_inserter instead of std::copy and lyx::back_inserter_fun. * buffer_funcs.C (bufferErrors): use for_each instead of explicit for loop * buffer.C (changeLanguage): use for_each instead of explicit for loop (hasParWithID): implement using getParFromID * LaTeXFeatures.C: ws change only * CutAndPaste.C (replaceSelectionWithString): Use a temporary var to cleanup a bit. * BufferView_pimpl.C (trackChanges): use for_each instead of expilicit for loop git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9182 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 16 +++--- src/ChangeLog | 32 +++++++++-- src/CutAndPaste.C | 7 +-- src/LaTeXFeatures.C | 1 - src/buffer.C | 22 ++------ src/buffer_funcs.C | 8 ++- src/bufferlist.C | 10 +++- src/cursor.C | 11 ++-- src/frontends/qt2/ChangeLog | 4 ++ src/frontends/qt2/lyx_gui.C | 6 +-- src/frontends/xforms/ChangeLog | 4 ++ src/frontends/xforms/lyx_gui.C | 6 +-- src/support/ChangeLog | 7 ++- src/support/lyxfunctional.h | 98 ---------------------------------- 14 files changed, 81 insertions(+), 151 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 6bb29ef2de..2f8ebd9764 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -72,6 +72,8 @@ #include +#include + using lyx::pos_type; using lyx::support::AddPath; @@ -90,6 +92,7 @@ using std::istringstream; using std::make_pair; using std::min; using std::string; +using std::mem_fun_ref; extern BufferList bufferlist; @@ -823,9 +826,9 @@ void BufferView::Pimpl::trackChanges() bool const tracking = buf->params().tracking_changes; if (!tracking) { - ParIterator const end = buf->par_iterator_end(); - for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) - it->trackChanges(); + for_each(buf->par_iterator_begin(), + buf->par_iterator_end(), + bind(&Paragraph::trackChanges, _1, Change::UNCHANGED)); buf->params().tracking_changes = true; // we cannot allow undos beyond the freeze point @@ -842,9 +845,10 @@ void BufferView::Pimpl::trackChanges() return; } - ParIterator const end = buf->par_iterator_end(); - for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) - it->untrackChanges(); + for_each(buf->par_iterator_begin(), + buf->par_iterator_end(), + mem_fun_ref(&Paragraph::untrackChanges)); + buf->params().tracking_changes = false; } diff --git a/src/ChangeLog b/src/ChangeLog index 57f9a08840..1bfb78a556 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,25 @@ +2004-11-06 Lars Gullik Bjonnes + + * cursor.C (insert): use for_each instead of explicit for loop + + * bufferlist.C (getFileNames): use std::transform and + std::back_inserter instead of std::copy and lyx::back_inserter_fun. + + * buffer_funcs.C (bufferErrors): use for_each instead of explicit + for loop + + * buffer.C (changeLanguage): use for_each instead of explicit for + loop + (hasParWithID): implement using getParFromID + + * LaTeXFeatures.C: ws change only + + * CutAndPaste.C (replaceSelectionWithString): Use a temporary var + to cleanup a bit. + + * BufferView_pimpl.C (trackChanges): use for_each instead of + expilicit for loop + 2004-11-04 Jean-Marc Lasgouttes * lyxlength.C (asLatexString): rewrite so that it does not use @@ -11,7 +33,7 @@ 2004-11-02 José Matos * output_docbook.C (docbook): - * paragraph.C (getID): + * paragraph.C (getID): * sgml.[Ch] (openTag, cleanID): escape characters inside ids to garantee that the output is always legal. @@ -46,10 +68,10 @@ 2004-10-30 José Matos * paragraph.C (getFirstWord): the content should always be escaped - there. + there. (simpleDocBookOnePar): * output_docbook.C (makeEnvironment): replace reference to CDATA - to style pass_thru. + to style pass_thru. 2004-10-30 José Matos @@ -81,7 +103,7 @@ 2004-10-28 José Matos * output_docbook.C (makeEnvironment): move id to broadest possible - scope. + scope. * sgml.C (openTag): apply substitution of <> for all attributes. @@ -114,7 +136,7 @@ 2004-10-25 José Matos * output_docbook.C (makeCommand): merge two if's that tested the - same condition. + same condition. 2004-10-25 Jean-Marc Lasgouttes diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 4f422ae268..acdc5e7638 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -601,14 +601,15 @@ void replaceSelectionWithString(LCursor & cur, string const & str) // Get font setting before we cut pos_type pos = cur.selEnd().pos(); - LyXFont const font = text->getPar(cur.selBegin().par()). - getFontSettings(cur.buffer().params(), cur.selBegin().pos()); + Paragraph & par = text->getPar(cur.selEnd().par()); + LyXFont const font = + par.getFontSettings(cur.buffer().params(), cur.selBegin().pos()); // Insert the new string string::const_iterator cit = str.begin(); string::const_iterator end = str.end(); for (; cit != end; ++cit, ++pos) - text->getPar(cur.selEnd().par()).insertChar(pos, (*cit), font); + par.insertChar(pos, (*cit), font); // Cut the selection cutSelection(cur, true, false); diff --git a/src/LaTeXFeatures.C b/src/LaTeXFeatures.C index 67fcb20535..9545af96f4 100644 --- a/src/LaTeXFeatures.C +++ b/src/LaTeXFeatures.C @@ -160,7 +160,6 @@ string LaTeXFeatures::getLanguages() const cit != UsedLanguages_.end(); ++cit) languages << (*cit)->babel() << ','; - return languages.str(); } diff --git a/src/buffer.C b/src/buffer.C index 2fdf62c6d1..154f365ffd 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1323,9 +1323,9 @@ void Buffer::changeLanguage(Language const * from, Language const * to) // Take care of l10n/i18n updateDocLang(to); - ParIterator end = par_iterator_end(); - for (ParIterator it = par_iterator_begin(); it != end; ++it) - it->changeLanguage(params(), from, to); + for_each(par_iterator_begin(), + par_iterator_end(), + bind(&Paragraph::changeLanguage, _1, params(), from, to)); } @@ -1367,20 +1367,8 @@ ParIterator Buffer::getParFromID(int id) const bool Buffer::hasParWithID(int id) const { - ParConstIterator it = par_iterator_begin(); - ParConstIterator end = par_iterator_end(); - - if (id < 0) { - // John says this is called with id == -1 from undo - lyxerr << "hasParWithID(), id: " << id << endl; - return 0; - } - - for (; it != end; ++it) - if (it->id() == id) - return true; - - return false; + ParConstIterator it = getParFromID(id); + return it != par_iterator_end(); } diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index b1d5068081..2f41213184 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -31,6 +31,8 @@ #include "support/filetools.h" #include "support/lyxlib.h" +#include + using lyx::support::bformat; using lyx::support::FileInfo; using lyx::support::IsFileWriteable; @@ -211,11 +213,7 @@ void bufferErrors(Buffer const & buf, TeXErrors const & terr) void bufferErrors(Buffer const & buf, ErrorList const & el) { - ErrorList::const_iterator it = el.begin(); - ErrorList::const_iterator end = el.end(); - - for (; it != end; ++it) - buf.error(*it); + for_each(el.begin(), el.end(), bind(ref(buf.error), _1)); } diff --git a/src/bufferlist.C b/src/bufferlist.C index b43b07a9e0..b5d1bc9cc8 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -31,6 +31,9 @@ #include +#include +#include + using lyx::support::AddName; using lyx::support::bformat; using lyx::support::GetEnvPath; @@ -49,6 +52,8 @@ using std::find_if; using std::for_each; using std::string; using std::vector; +using std::back_inserter; +using std::transform; BufferList::BufferList() @@ -195,8 +200,9 @@ bool BufferList::close(Buffer * buf, bool ask) vector const BufferList::getFileNames() const { vector nvec; - std::copy(bstore.begin(), bstore.end(), - lyx::back_inserter_fun(nvec, &Buffer::fileName)); + transform(bstore.begin(), bstore.end(), + back_inserter(nvec), + boost::bind(&Buffer::fileName, _1)); return nvec; } diff --git a/src/cursor.C b/src/cursor.C index 28b1bffd0c..e84d6c27ec 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -44,6 +44,7 @@ #include "frontends/LyXView.h" #include +#include #include #include @@ -61,8 +62,8 @@ using std::swap; namespace { - bool positionable - (DocIterator const & cursor, DocIterator const & anchor) + bool + positionable(DocIterator const & cursor, DocIterator const & anchor) { // avoid deeper nested insets when selecting if (cursor.size() > anchor.size()) @@ -624,9 +625,9 @@ void LCursor::plainInsert(MathAtom const & t) void LCursor::insert(string const & str) { - //lyxerr << "LCursor::insert str '" << str << "'" << endl; - for (string::const_iterator it = str.begin(); it != str.end(); ++it) - insert(*it); + for_each(str.begin(), str.end(), + boost::bind(static_cast + (&LCursor::insert), this, _1)); } diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 99635acecb..d1561a6234 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,7 @@ +2004-11-06 Lars Gullik Bjonnes + + * lyx_gui.C (start): use for_each instead of explict for loop + 2004-10-26 Angus Leeming * Makefile.dialogs: diff --git a/src/frontends/qt2/lyx_gui.C b/src/frontends/qt2/lyx_gui.C index d98e4d9fc2..0495ae770f 100644 --- a/src/frontends/qt2/lyx_gui.C +++ b/src/frontends/qt2/lyx_gui.C @@ -231,10 +231,8 @@ void start(string const & batch, vector const & files) lyxsocket = new LyXServerSocket(&view.getLyXFunc(), os::slashify_path(os::getTmpDir() + "/lyxsocket")); - vector::const_iterator cit = files.begin(); - vector::const_iterator end = files.end(); - for (; cit != end; ++cit) - view.view()->loadLyXFile(*cit, true); + for_each(files.begin(), files.end(), + bind(&BufferView::loadLyXFile, view.view(), _1, true)); // handle the batch commands the user asked for if (!batch.empty()) { diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 7b562be069..ad209f669a 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,7 @@ +2004-11-06 Lars Gullik Bjonnes + + * lyx_gui.C (start): use for_each instead of explicit for loop + 2004-11-05 Allan Rae * forms/Makefile.am: s/SUFFIX/SUFFIXES/ rule. diff --git a/src/frontends/xforms/lyx_gui.C b/src/frontends/xforms/lyx_gui.C index 44d2e3c3c5..de220cdc58 100644 --- a/src/frontends/xforms/lyx_gui.C +++ b/src/frontends/xforms/lyx_gui.C @@ -304,10 +304,8 @@ void start(string const & batch, vector const & files) lyxsocket = new LyXServerSocket(&view->getLyXFunc(), os::slashify_path(os::getTmpDir() + "/lyxsocket")); - vector::const_iterator cit = files.begin(); - vector::const_iterator end = files.end(); - for (; cit != end; ++cit) - view->view()->loadLyXFile(*cit, true); + for_each(files.begin(), files.end(), + bind(&BufferView::loadLyXFile, view->view(), _1, true)); // handle the batch commands the user asked for if (!batch.empty()) diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 316aeed88c..453b7ea462 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,7 +1,12 @@ +2004-11-06 Lars Gullik Bjonnes + + * lyxfunctional.h: delete back_inserter_fun functions and helper + classes. + 2004-11-04 Jean-Marc Lasgouttes * snprintf.[ch]: removed - + * Makefile.am (libsupport_la_SOURCES): remove snprintf 2004-10-29 Georg Baum diff --git a/src/support/lyxfunctional.h b/src/support/lyxfunctional.h index c52375b237..4c4b318fbf 100644 --- a/src/support/lyxfunctional.h +++ b/src/support/lyxfunctional.h @@ -22,104 +22,6 @@ namespace lyx { -template -class back_insert_fun_iterator { -protected: - Cont * container; - MemRet(Type::*pmf)(); -public: - typedef Cont container_type; - typedef std::output_iterator_tag iterator_category; - typedef void value_type; - typedef void difference_type; - typedef void pointer; - typedef void reference; - - back_insert_fun_iterator(Cont & x, MemRet(Type::*p)()) - : container(&x), pmf(p) {} - - back_insert_fun_iterator & - operator=(Type * val) { - container->push_back((val->*pmf)()); - return *this; - } - - back_insert_fun_iterator & - operator=(Type & val) { - container->push_back((val.*pmf)()); - return *this; - } - - back_insert_fun_iterator & operator*() { - return *this; - } - back_insert_fun_iterator & operator++() { // prefix ++ - return *this; - } - back_insert_fun_iterator & operator++(int) { // postfix ++ - return *this; - } -}; - - -template -class const_back_insert_fun_iterator { -protected: - Cont * container; - MemRet(Type::*pmf)() const; -public: - typedef Cont container_type; - typedef std::output_iterator_tag iterator_category; - typedef void value_type; - typedef void difference_type; - typedef void pointer; - typedef void reference; - - const_back_insert_fun_iterator(Cont & x, MemRet(Type::*p)() const) - : container(&x), pmf(p) {} - - ~const_back_insert_fun_iterator() {} - - const_back_insert_fun_iterator & - operator=(Type const * val) { - container->push_back((val->*pmf)()); - return *this; - } - - const_back_insert_fun_iterator & - operator=(Type const & val) { - container->push_back((val.*pmf)()); - return *this; - } - - const_back_insert_fun_iterator & operator*() { - return *this; - } - const_back_insert_fun_iterator & operator++() { // prefix ++ - return *this; - } - const_back_insert_fun_iterator & operator++(int) { // postfix ++ - return *this; - } -}; - - -template -back_insert_fun_iterator -back_inserter_fun(Cont & cont, MemRet(Type::*p)()) -{ - return back_insert_fun_iterator(cont, p); -} - - -template -const_back_insert_fun_iterator -back_inserter_fun(Cont & cont, MemRet(Type::*p)() const) -{ - return const_back_insert_fun_iterator(cont, p); -} - - template class compare_memfun_t { public: -- 2.39.2