]> git.lyx.org Git - lyx.git/blobdiff - src/layout.C
implement getLabelList
[lyx.git] / src / layout.C
index 06e011331804ebf1024ed28293c12d36d7f676ed..58fd7f1bb93ec9b31cc1b7a8965196533bbf3521 100644 (file)
@@ -6,7 +6,8 @@
  *          Copyright 1995 Matthias Ettrich
  *          Copyright 1995-2000 The LyX Team.
  *
- * ====================================================== */
+ * ======================================================
+ */
 
 #include <config.h>
 
@@ -15,8 +16,6 @@
 #endif
 
 #include <algorithm>
-using std::make_pair;
-using std::sort;
 
 #include "layout.h"
 #include "lyxlex.h"
@@ -25,7 +24,14 @@ using std::sort;
 #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;
@@ -75,6 +81,7 @@ enum LayoutTags {
        LT_LABELSTRING, 
        LT_LABELSTRING_APPENDIX, 
        LT_LABELTYPE,
+       LT_ENDLABELSTRING,
        LT_ENDLABELTYPE,
        LT_LATEXNAME, 
        LT_LATEXPARAM, 
@@ -95,50 +102,6 @@ enum LayoutTags {
 };
 
 
-#if 0
-// This table is sorted alphabetically [asierra 30March96]
-static keyword_item layoutTags[] = {
-       { "align",                      LT_ALIGN },
-       { "alignpossible",              LT_ALIGNPOSSIBLE },
-       { "bottomsep",                  LT_BOTTOMSEP },
-       { "copystyle",                  LT_COPYSTYLE },
-       { "end",                        LT_END },
-       { "endlabeltype",               LT_ENDLABELTYPE },
-       { "fill_bottom",                LT_FILL_BOTTOM },
-       { "fill_top",                   LT_FILL_TOP },
-       { "font",                       LT_FONT },
-       { "freespacing",                LT_FREE_SPACING },
-       { "intitle",                    LT_INTITLE },
-       { "itemsep",                    LT_ITEMSEP },
-       { "keepempty",                  LT_KEEPEMPTY },
-       { "labelbottomsep",             LT_LABEL_BOTTOMSEP },
-       { "labelfont",                  LT_LABELFONT },
-       { "labelindent",                LT_LABELINDENT },
-       { "labelsep",                   LT_LABELSEP },
-       { "labelstring",                LT_LABELSTRING },
-       { "labelstringappendix",        LT_LABELSTRING_APPENDIX },
-       { "labeltype",                  LT_LABELTYPE },
-       { "latexname",                  LT_LATEXNAME },
-       { "latexparam",                 LT_LATEXPARAM },
-       { "latextype",                  LT_LATEXTYPE },
-       { "leftmargin",                 LT_LEFTMARGIN },
-       { "margin",                     LT_MARGIN },
-       { "needprotect",                LT_NEED_PROTECT },
-       { "newline",                    LT_NEWLINE },
-       { "nextnoindent",               LT_NEXTNOINDENT },
-       { "obsoletedby",                LT_OBSOLETEDBY },
-       { "parindent",                  LT_PARINDENT },
-       { "parsep",                     LT_PARSEP },
-       { "parskip",                    LT_PARSKIP },
-       { "preamble",                   LT_PREAMBLE },
-       { "rightmargin",                LT_RIGHTMARGIN },
-       { "spacing",                    LT_SPACING },
-       { "textfont",                   LT_TEXTFONT },
-       { "topsep",                     LT_TOPSEP }
-};
-#endif
-
-
 /////////////////////
 
 // Constructor for layout
@@ -176,7 +139,6 @@ LyXLayout::LyXLayout ()
 // Reads a layout definition from file
 bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
 {
-#if 1
        // This table is sorted alphabetically [asierra 30March96]
        keyword_item layoutTags[] = {
                { "align",                      LT_ALIGN },
@@ -184,6 +146,7 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
                { "bottomsep",                  LT_BOTTOMSEP },
                { "copystyle",                  LT_COPYSTYLE },
                { "end",                        LT_END },
+               { "endlabelstring",             LT_ENDLABELSTRING },
                { "endlabeltype",               LT_ENDLABELTYPE },
                { "fill_bottom",                LT_FILL_BOTTOM },
                { "fill_top",                   LT_FILL_TOP },
@@ -217,7 +180,7 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
                { "textfont",                   LT_TEXTFONT },
                { "topsep",                     LT_TOPSEP }
        };
-#endif
+
        bool error = false;
        bool finished = false;
        lexrc.pushTable(layoutTags, LT_INTITLE);
@@ -225,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; 
 
@@ -235,7 +198,7 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
                        continue; 
                default: break;
                }
-               switch(static_cast<LayoutTags>(le)) {
+               switch (static_cast<LayoutTags>(le)) {
                case LT_END:            // end of structure
                        finished = true;
                        break;
@@ -414,6 +377,11 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
                                labelstring_ = lexrc.GetString();
                        break;
 
+               case LT_ENDLABELSTRING: // endlabel string definition
+                       if (lexrc.next())
+                               endlabelstring_ = lexrc.GetString();
+                       break;
+
                case LT_LABELSTRING_APPENDIX: // label string appendix definition
                        if (lexrc.next())
                                labelstring_appendix_ = lexrc.GetString();
@@ -443,19 +411,8 @@ enum AlignTags {
 };
 
 
-#if 0
-static keyword_item alignTags[] = {
-       { "block",  AT_BLOCK },
-       { "center", AT_CENTER },
-       { "layout", AT_LAYOUT },
-       { "left",   AT_LEFT },
-       { "right",  AT_RIGHT }
-};
-#endif
-
 void LyXLayout::readAlign(LyXLex & lexrc)
 {
-#if 1
        keyword_item alignTags[] = {
                { "block",  AT_BLOCK },
                { "center", AT_CENTER },
@@ -463,7 +420,7 @@ void LyXLayout::readAlign(LyXLex & lexrc)
                { "left",   AT_LEFT },
                { "right",  AT_RIGHT }
        };
-#endif
+
        pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
        int le = lexrc.lex();
        switch (le) {
@@ -472,7 +429,7 @@ void LyXLayout::readAlign(LyXLex & lexrc)
                return; 
        default: break;
        };
-       switch(static_cast<AlignTags>(le)) {
+       switch (static_cast<AlignTags>(le)) {
        case AT_BLOCK:
                align = LYX_ALIGN_BLOCK;
                break;
@@ -494,7 +451,6 @@ void LyXLayout::readAlign(LyXLex & lexrc)
 
 void LyXLayout::readAlignPossible(LyXLex & lexrc)
 {
-#if 1
        keyword_item alignTags[] = {
                { "block",  AT_BLOCK },
                { "center", AT_CENTER },
@@ -502,7 +458,7 @@ void LyXLayout::readAlignPossible(LyXLex & lexrc)
                { "left",   AT_LEFT },
                { "right",  AT_RIGHT }
        };
-#endif
+
        lexrc.pushTable(alignTags, AT_LAYOUT);
        alignpossible = LYX_ALIGN_NONE;
        int lineno = lexrc.GetLineNo();
@@ -557,32 +513,8 @@ enum LabelTypeTags {
 };
 
 
-#if 0
-static keyword_item labelTypeTags[] = {
-       { "bibliography",             LA_BIBLIO },
-       { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
-       { "counter_chapter",          LA_COUNTER_CHAPTER },
-       { "counter_enumi",            LA_COUNTER_ENUMI },
-       { "counter_enumii",           LA_COUNTER_ENUMII },
-       { "counter_enumiii",          LA_COUNTER_ENUMIII },
-       { "counter_enumiv",           LA_COUNTER_ENUMIV },
-       { "counter_paragraph",        LA_COUNTER_PARAGRAPH },
-       { "counter_section",          LA_COUNTER_SECTION },
-       { "counter_subparagraph",     LA_COUNTER_SUBPARAGRAPH },
-       { "counter_subsection",       LA_COUNTER_SUBSECTION },
-       { "counter_subsubsection",    LA_COUNTER_SUBSUBSECTION },
-       { "manual",                   LA_MANUAL },
-       { "no_label",                 LA_NO_LABEL },
-       { "sensitive",                LA_SENSITIVE },
-       { "static",                   LA_STATIC },
-       { "top_environment",          LA_TOP_ENVIRONMENT }
-};
-#endif
-
-
 void LyXLayout::readLabelType(LyXLex & lexrc)
 {
-#if 1
        keyword_item labelTypeTags[] = {
        { "bibliography",             LA_BIBLIO },
        { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
@@ -602,7 +534,7 @@ void LyXLayout::readLabelType(LyXLex & lexrc)
        { "static",                   LA_STATIC },
        { "top_environment",          LA_TOP_ENVIRONMENT }
 };
-#endif
+
        pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
        int le = lexrc.lex();
        switch (le) {
@@ -666,21 +598,29 @@ void LyXLayout::readLabelType(LyXLex & lexrc)
        }
 }
 
-static keyword_item endlabelTypeTags[] = {
+
+namespace {
+
+keyword_item endlabelTypeTags[] = {
        { "box",        END_LABEL_BOX },
        { "filled_box", END_LABEL_FILLED_BOX },
-       { "no_label",   END_LABEL_NO_LABEL }
+       { "no_label",   END_LABEL_NO_LABEL },
+       { "static",     END_LABEL_STATIC }
 };
 
+} // namespace anon
+
+
 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;
+       case END_LABEL_STATIC:
        case END_LABEL_BOX:
        case END_LABEL_FILLED_BOX:
        case END_LABEL_NO_LABEL:
@@ -693,19 +633,9 @@ void LyXLayout::readEndLabelType(LyXLex & lexrc)
        }
 }
 
-#if 0
-static keyword_item marginTags[] = {
-       { "dynamic",           MARGIN_DYNAMIC },
-       { "first_dynamic",     MARGIN_FIRST_DYNAMIC },
-       { "manual",            MARGIN_MANUAL },
-       { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
-       { "static",            MARGIN_STATIC }
-};
-#endif
 
 void LyXLayout::readMargin(LyXLex & lexrc)
 {
-#if 1
        keyword_item marginTags[] = {
                { "dynamic",           MARGIN_DYNAMIC },
                { "first_dynamic",     MARGIN_FIRST_DYNAMIC },
@@ -713,11 +643,11 @@ void LyXLayout::readMargin(LyXLex & lexrc)
                { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
                { "static",            MARGIN_STATIC }
        };
-#endif
+
        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;
@@ -736,28 +666,16 @@ void LyXLayout::readMargin(LyXLex & lexrc)
 }
 
 
-#if 0
-static keyword_item latexTypeTags[] = {
-       { "command",          LATEX_COMMAND },
-       { "environment",      LATEX_ENVIRONMENT },
-       { "item_environment", LATEX_ITEM_ENVIRONMENT },
-       { "list_environment", LATEX_LIST_ENVIRONMENT },
-       { "paragraph",        LATEX_PARAGRAPH }
-};
-#endif
-
-
 void LyXLayout::readLatexType(LyXLex & lexrc)
 {
-#if 1
        keyword_item latexTypeTags[] = {
                { "command",          LATEX_COMMAND },
                { "environment",      LATEX_ENVIRONMENT },
                { "item_environment", LATEX_ITEM_ENVIRONMENT },
                { "list_environment", LATEX_LIST_ENVIRONMENT },
                { "paragraph",        LATEX_PARAGRAPH }
-};
-#endif
+       };
+
        pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
        int le = lexrc.lex();
        switch (le) {
@@ -787,35 +705,24 @@ enum SpacingTags {
 };
 
 
-#if 0
-static keyword_item spacingTags[] = {
-       {"double",  ST_SPACING_DOUBLE },
-       {"onehalf", ST_SPACING_ONEHALF },
-       {"other",   ST_OTHER },
-       {"single",  ST_SPACING_SINGLE }
-};
-#endif
-
-
 void LyXLayout::readSpacing(LyXLex & lexrc)
 {
-#if 1
        keyword_item spacingTags[] = {
                {"double",  ST_SPACING_DOUBLE },
                {"onehalf", ST_SPACING_ONEHALF },
                {"other",   ST_OTHER },
                {"single",  ST_SPACING_SINGLE }
        };
-#endif
+
        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<SpacingTags>(le)) {
+       switch (static_cast<SpacingTags>(le)) {
        case ST_SPACING_SINGLE:
                spacing.set(Spacing::Single);
                break;
@@ -892,34 +799,9 @@ enum TextClassTags {
 };
 
 
-#if 0
-static keyword_item textClassTags[] = {
-       { "classoptions",    TC_CLASSOPTIONS },
-       { "columns",         TC_COLUMNS },
-       { "defaultfont",     TC_DEFAULTFONT },
-       { "input",           TC_INPUT },
-       { "leftmargin",      TC_LEFTMARGIN },
-       { "maxcounter",      TC_MAXCOUNTER },
-       { "nostyle",         TC_NOSTYLE },
-       { "outputtype",      TC_OUTPUTTYPE },
-       { "pagestyle",       TC_PAGESTYLE },
-       { "preamble",        TC_PREAMBLE },
-       { "providesamsmath", TC_PROVIDESAMSMATH },
-       { "providesmakeidx", TC_PROVIDESMAKEIDX },
-       { "providesurl",     TC_PROVIDESURL },
-       { "rightmargin",     TC_RIGHTMARGIN },
-       { "secnumdepth",     TC_SECNUMDEPTH },
-       { "sides",           TC_SIDES },
-       { "style",           TC_STYLE },
-       { "tocdepth",        TC_TOCDEPTH }
-};
-#endif
-
-
 // Reads a textclass structure from file.
 bool LyXTextClass::Read(string const & filename, bool merge)
 {
-#if 1
        keyword_item textClassTags[] = {
                { "classoptions",    TC_CLASSOPTIONS },
                { "columns",         TC_COLUMNS },
@@ -939,8 +821,8 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                { "sides",           TC_SIDES },
                { "style",           TC_STYLE },
                { "tocdepth",        TC_TOCDEPTH }
-};
-#endif
+       };
+
        if (!merge)
                lyxerr[Debug::TCLASS] << "Reading textclass "
                                      << MakeDisplayPath(filename)
@@ -959,7 +841,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; 
 
@@ -969,7 +851,7 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                        continue; 
                default: break;
                }
-               switch(static_cast<TextClassTags>(le)) {
+               switch (static_cast<TextClassTags>(le)) {
                case TC_OUTPUTTYPE:   // output type definition
                        readOutputType(lexrc);
                        break;
@@ -997,7 +879,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);
                                }
@@ -1025,7 +907,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:
@@ -1048,7 +930,7 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                        if (!defaultfont_.resolved()) {
                                lexrc.printError("Warning: defaultfont should "
                                                 "be fully instantiated!");
-                               defaultfont_.realize(LyXFont::ALL_SANE);
+                               defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
                        }
                        break;
 
@@ -1115,29 +997,19 @@ bool LyXTextClass::Read(string const & filename, bool merge)
 }
 
 
-#if 0
-static keyword_item outputTypeTags[] = {
-       { "docbook", DOCBOOK },
-       { "latex", LATEX },
-       { "linuxdoc", LINUXDOC },
-       { "literate", LITERATE }
-};
-#endif
-
 void LyXTextClass::readOutputType(LyXLex & lexrc)
 {
-#if 1
        keyword_item outputTypeTags[] = {
                { "docbook", DOCBOOK },
                { "latex", LATEX },
                { "linuxdoc", LINUXDOC },
                { "literate", LITERATE }
-};
-#endif
+       };
+
        pushpophelper pph(lexrc, outputTypeTags, LITERATE);
 
        int le = lexrc.lex();
-       switch(le) {
+       switch (le) {
        case LyXLex::LEX_UNDEF:
                lexrc.printError("Unknown output type `$$Token'");
                return;
@@ -1170,25 +1042,8 @@ enum MaxCounterTags {
 };
 
 
-#if 0
-static keyword_item maxCounterTags[] = {
-       {"counter_chapter", MC_COUNTER_CHAPTER },
-       {"counter_enumi", MC_COUNTER_ENUMI },
-       {"counter_enumii", MC_COUNTER_ENUMII },
-       {"counter_enumiii", MC_COUNTER_ENUMIII },
-       {"counter_enumiv", MC_COUNTER_ENUMIV },
-       {"counter_paragraph", MC_COUNTER_PARAGRAPH },
-       {"counter_section", MC_COUNTER_SECTION },
-       {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
-       {"counter_subsection", MC_COUNTER_SUBSECTION },
-       {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
-};
-#endif
-
-
 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
 {
-#if 1
        keyword_item maxCounterTags[] = {
                {"counter_chapter", MC_COUNTER_CHAPTER },
                {"counter_enumi", MC_COUNTER_ENUMI },
@@ -1201,10 +1056,10 @@ void LyXTextClass::readMaxCounter(LyXLex & lexrc)
                {"counter_subsection", MC_COUNTER_SUBSECTION },
                {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
        };
-#endif
+
        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; 
@@ -1253,26 +1108,15 @@ enum ClassOptionsTags {
 };
 
 
-#if 0
-static keyword_item classOptionsTags[] = {
-       {"end", CO_END },
-       {"fontsize", CO_FONTSIZE },
-       {"other", CO_OTHER },
-       {"pagestyle", CO_PAGESTYLE }
-};
-#endif
-
-
 void LyXTextClass::readClassOptions(LyXLex & lexrc)
 {
-#if 1
        keyword_item classOptionsTags[] = {
                {"end", CO_END },
                {"fontsize", CO_FONTSIZE },
                {"other", CO_OTHER },
                {"pagestyle", CO_PAGESTYLE }
        };
-#endif
+
        lexrc.pushTable(classOptionsTags, CO_END);
        bool getout = false;
        while (!getout && lexrc.IsOK()) {
@@ -1307,49 +1151,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;
 }
 
 
@@ -1359,7 +1197,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 `"
@@ -1375,15 +1213,15 @@ void LyXTextClass::load()
 //////////////////////////////////////////
 
 // Gets textclass number from name
-pair<bool, LyXTextClassList::size_type>
+pair<bool, LyXTextClassList::size_type> 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, 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));
 }
 
 
@@ -1400,18 +1238,18 @@ LyXTextClassList::Style(LyXTextClassList::size_type textclass,
 
 
 // Gets layout number from name and textclass number
-pair<bool, LyXTextClass::size_type>
+pair<bool, LyXTextClass::size_type> const
 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);
        }
        if (name == "dummy")
-               return make_pair(true, LYX_DUMMY_LAYOUT);
-       return make_pair(false, LyXTextClass::LayoutList::size_type(0)); // not found
+               return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT));
+       return make_pair(false, LyXTextClass::size_type(0)); // not found
 }
 
 
@@ -1600,3 +1438,18 @@ LyXTextClassList::Load (LyXTextClassList::size_type number) const
        }
        return result;
 }
+
+
+std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
+{
+       switch (p) {
+       case LyXTextClass::OneSide:
+               os << "1";
+               break;
+       case LyXTextClass::TwoSides:
+               os << "2";
+               break;
+       }
+       return os;
+}
+