X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flayout.C;h=bad3b274118812ec634e630be50b5cb6c8520857;hb=d5b3b6807a719bdc3510444b307a1d22a94c6876;hp=0e8dfae7c0692278b8559213781584cbd0c38cfa;hpb=ee72ce87743857b4317da00e6e09cb6842095664;p=lyx.git diff --git a/src/layout.C b/src/layout.C index 0e8dfae7c0..bad3b27411 100644 --- a/src/layout.C +++ b/src/layout.C @@ -6,7 +6,8 @@ * Copyright 1995 Matthias Ettrich * Copyright 1995-2000 The LyX Team. * - * ====================================================== */ + * ====================================================== + */ #include @@ -23,11 +24,14 @@ #include "debug.h" #include "gettext.h" #include "support/LAssert.h" +#include "support/lyxfunctional.h" using std::pair; using std::make_pair; using std::sort; using std::endl; +using std::find_if; +using std::remove_if; // Global variable: textclass table. LyXTextClassList textclasslist; @@ -869,7 +873,7 @@ bool LyXTextClass::Read(string const & filename, bool merge) error = do_readStyle(lexrc, lay); } else { LyXLayout lay; - lay.name(name); + lay.setName(name); if (!(error = do_readStyle(lexrc, lay))) layoutlist.push_back(lay); } @@ -1141,49 +1145,43 @@ void LyXTextClass::readClassOptions(LyXLex & lexrc) bool LyXTextClass::hasLayout(string const & name) const { - for (LayoutList::const_iterator cit = layoutlist.begin(); - cit != layoutlist.end(); ++cit) { - if ((*cit).name() == name) - return true; - } - return false; + return find_if(layoutlist.begin(), layoutlist.end(), + compare_memfun(&LyXLayout::name, name)) + != layoutlist.end(); } LyXLayout const & LyXTextClass::GetLayout (string const & name) const { - for (LayoutList::const_iterator cit = layoutlist.begin(); - cit != layoutlist.end(); ++cit) { - if ((*cit).name() == name) - return (*cit); - } - Assert(false); // we actually require the name to exist. - return layoutlist.front(); + LayoutList::const_iterator cit = + find_if(layoutlist.begin(), + layoutlist.end(), + compare_memfun(&LyXLayout::name, name)); + Assert(cit != layoutlist.end()); // we require the name to exist + return (*cit); } LyXLayout & LyXTextClass::GetLayout(string const & name) { - for (LayoutList::iterator it = layoutlist.begin(); - it != layoutlist.end(); ++it) { - if ((*it).name() == name) - return (*it); - } - Assert(false); // we actually require the name to exist. - return layoutlist.front(); + LayoutList::iterator it = + find_if(layoutlist.begin(), + layoutlist.end(), + compare_memfun(&LyXLayout::name, name)); + Assert(it != layoutlist.end()); // we require the name to exist + return (*it); } -bool LyXTextClass::delete_layout (string const & name) +bool LyXTextClass::delete_layout(string const & name) { - for(LayoutList::iterator it = layoutlist.begin(); - it != layoutlist.end(); ++it) { - if ((*it).name() == name) { - layoutlist.erase(it); - return true; - } - } - return false; + LayoutList::iterator it = + remove_if(layoutlist.begin(), layoutlist.end(), + compare_memfun(&LyXLayout::name, name)); + LayoutList::iterator end = layoutlist.end(); + bool const ret = (it != end); + layoutlist.erase(it, end); + return ret; } @@ -1193,7 +1191,7 @@ void LyXTextClass::load() if (loaded) return; // Read style-file - string real_file = LibFileSearch("layouts", name_, "layout"); + string const real_file = LibFileSearch("layouts", name_, "layout"); if (Read(real_file)) { lyxerr << "Error reading `" @@ -1209,16 +1207,15 @@ void LyXTextClass::load() ////////////////////////////////////////// // Gets textclass number from name -pair +pair const LyXTextClassList::NumberOfClass(string const & textclass) const { - for (ClassList::const_iterator cit = classlist.begin(); - cit != classlist.end(); ++cit) { - if ((*cit).name() == textclass) - return make_pair(true, - size_type(cit - classlist.begin())); - } - return make_pair(false, size_type(0)); + ClassList::const_iterator cit = + find_if(classlist.begin(), classlist.end(), + compare_memfun(&LyXTextClass::name, textclass)); + return cit != classlist.end() ? + make_pair(true, size_type(cit - classlist.begin())) : + make_pair(false, size_type(0)); } @@ -1235,7 +1232,7 @@ LyXTextClassList::Style(LyXTextClassList::size_type textclass, // Gets layout number from name and textclass number -pair +pair const LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass, string const & name) const { @@ -1449,3 +1446,4 @@ std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p) } return os; } +