X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flayout.C;h=8652f06d8eb0c02dc846a2925dc48c638c547c8b;hb=f676dacf9c69d8c906653f54d00342c01de6facf;hp=1cbb0501c209d766cc4f640f48ed986ce4b9f12f;hpb=45a03f4f67bb00f8142e465c615f348f0622eb32;p=lyx.git diff --git a/src/layout.C b/src/layout.C index 1cbb0501c2..8652f06d8e 100644 --- a/src/layout.C +++ b/src/layout.C @@ -24,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; @@ -185,7 +188,7 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass) while (!finished && lexrc.IsOK() && !error) { int le = lexrc.lex(); // See comment in lyxrc.C. - switch(le) { + switch (le) { case LyXLex::LEX_FEOF: continue; @@ -195,7 +198,7 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass) continue; default: break; } - switch(static_cast(le)) { + switch (static_cast(le)) { case LT_END: // end of structure finished = true; break; @@ -426,7 +429,7 @@ void LyXLayout::readAlign(LyXLex & lexrc) return; default: break; }; - switch(static_cast(le)) { + switch (static_cast(le)) { case AT_BLOCK: align = LYX_ALIGN_BLOCK; break; @@ -607,7 +610,7 @@ void LyXLayout::readEndLabelType(LyXLex & lexrc) pushpophelper pph(lexrc, endlabelTypeTags, END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1); int le = lexrc.lex(); - switch(le) { + switch (le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown labeltype tag `$$Token'"); break; @@ -638,7 +641,7 @@ void LyXLayout::readMargin(LyXLex & lexrc) pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX); int le = lexrc.lex(); - switch(le) { + switch (le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown margin type tag `$$Token'"); return; @@ -707,13 +710,13 @@ void LyXLayout::readSpacing(LyXLex & lexrc) pushpophelper pph(lexrc, spacingTags, ST_OTHER); int le = lexrc.lex(); - switch(le) { + switch (le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown spacing token `$$Token'"); return; default: break; } - switch(static_cast(le)) { + switch (static_cast(le)) { case ST_SPACING_SINGLE: spacing.set(Spacing::Single); break; @@ -832,7 +835,7 @@ bool LyXTextClass::Read(string const & filename, bool merge) // parsing while (lexrc.IsOK() && !error) { int le = lexrc.lex(); - switch(le) { + switch (le) { case LyXLex::LEX_FEOF: continue; @@ -842,7 +845,7 @@ bool LyXTextClass::Read(string const & filename, bool merge) continue; default: break; } - switch(static_cast(le)) { + switch (static_cast(le)) { case TC_OUTPUTTYPE: // output type definition readOutputType(lexrc); break; @@ -870,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); } @@ -898,7 +901,7 @@ bool LyXTextClass::Read(string const & filename, bool merge) case TC_SIDES: if (lexrc.next()) { - switch(lexrc.GetInteger()) { + switch (lexrc.GetInteger()) { case 1: sides_ = OneSide; break; case 2: sides_ = TwoSides; break; default: @@ -1000,7 +1003,7 @@ void LyXTextClass::readOutputType(LyXLex & lexrc) pushpophelper pph(lexrc, outputTypeTags, LITERATE); int le = lexrc.lex(); - switch(le) { + switch (le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown output type `$$Token'"); return; @@ -1050,7 +1053,7 @@ void LyXTextClass::readMaxCounter(LyXLex & lexrc) pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV); int le = lexrc.lex(); - switch(le) { + switch (le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown MaxCounter tag `$$Token'"); return; @@ -1142,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; } @@ -1194,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 `" @@ -1213,13 +1210,12 @@ void LyXTextClass::load() 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)); } @@ -1241,7 +1237,7 @@ LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass, string const & name) const { classlist[textclass].load(); - for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) { + for (unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) { if (classlist[textclass][i].name() == name) return make_pair(true, i); }