]> git.lyx.org Git - lyx.git/blobdiff - src/layout.C
update all .po files ot latestes pot
[lyx.git] / src / layout.C
index 1cbb0501c209d766cc4f640f48ed986ce4b9f12f..bad3b274118812ec634e630be50b5cb6c8520857 100644 (file)
 #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;
@@ -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);
                                }
@@ -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<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,
-                                        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));
 }