]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.cpp
small code simplification
[lyx.git] / src / LaTeXFeatures.cpp
index f192813d73bfa41f8c6b34b11799038668cec89d..ecf02295f54f0ec5d1e3c1ee8e5e9bfc5289efd4 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "Color.h"
 #include "BufferParams.h"
-#include "support/debug.h"
 #include "Encoding.h"
 #include "Floating.h"
 #include "FloatList.h"
 #include "LyXRC.h"
 #include "TextClass.h"
 
+#include "support/debug.h"
 #include "support/docstream.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
+#include "support/lstrings.h"
 
 using namespace std;
 using namespace lyx::support;
@@ -302,7 +303,7 @@ static string const newlyxcommand_def =
 //
 /////////////////////////////////////////////////////////////////////
 
-LaTeXFeatures::PackagesList LaTeXFeatures::packages_;
+LaTeXFeatures::Packages LaTeXFeatures::packages_;
 
 
 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
@@ -322,10 +323,13 @@ bool LaTeXFeatures::useBabel() const
 
 void LaTeXFeatures::require(string const & name)
 {
-       if (isRequired(name))
-               return;
+       features_.insert(name);
+}
+
 
-       features_.push_back(name);
+void LaTeXFeatures::require(set<string> const & names)
+{
+       features_.insert(names.begin(), names.end());
 }
 
 
@@ -353,11 +357,7 @@ void LaTeXFeatures::getAvailable()
                        finished = true;
                        break;
                default:
-                       string const name = lex.getString();
-                       PackagesList::const_iterator begin = packages_.begin();
-                       PackagesList::const_iterator end   = packages_.end();
-                       if (find(begin, end, name) == end)
-                               packages_.push_back(name);
+                       packages_.insert(lex.getString());
                }
        }
 }
@@ -378,17 +378,16 @@ void LaTeXFeatures::useLayout(docstring const & layoutname)
        TextClass const & tclass = params_.getTextClass();
        if (tclass.hasLayout(layoutname)) {
                // Is this layout already in usedLayouts?
-               list<docstring>::const_iterator cit = usedLayouts_.begin();
-               list<docstring>::const_iterator end = usedLayouts_.end();
-               for (; cit != end; ++cit) {
-                       if (layoutname == *cit)
-                               return;
-               }
+               if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname) 
+                   != usedLayouts_.end())
+                       return;
+
+               Layout const & layout = *tclass[layoutname];
+               require(layout.requires());
 
-               LayoutPtr const & lyt = tclass[layoutname];
-               if (!lyt->depends_on().empty()) {
+               if (!layout.depends_on().empty()) {
                        ++level;
-                       useLayout(lyt->depends_on());
+                       useLayout(layout.depends_on());
                        --level;
                }
                usedLayouts_.push_back(layoutname);
@@ -404,7 +403,7 @@ void LaTeXFeatures::useLayout(docstring const & layoutname)
 
 bool LaTeXFeatures::isRequired(string const & name) const
 {
-       return find(features_.begin(), features_.end(), name) != features_.end();
+       return features_.find(name) != features_.end();
 }
 
 
@@ -416,20 +415,19 @@ bool LaTeXFeatures::mustProvide(string const & name) const
 
 bool LaTeXFeatures::isAvailable(string const & name)
 {
-       string n = name;
        if (packages_.empty())
                getAvailable();
-       size_t loc = n.rfind(".sty");
-       if (loc == n.length() - 4) 
-               n = n.erase(name.length() - 4);
-       return find(packages_.begin(), packages_.end(), n) != packages_.end();
+       string n = name;
+       if (suffixIs(n, ".sty"))
+               n.erase(name.length() - 4);
+       return packages_.find(n) != packages_.end();
 }
 
 
 void LaTeXFeatures::addPreambleSnippet(string const & preamble)
 {
-       FeaturesList::const_iterator begin = preamble_snippets_.begin();
-       FeaturesList::const_iterator end   = preamble_snippets_.end();
+       SnippetList::const_iterator begin = preamble_snippets_.begin();
+       SnippetList::const_iterator end   = preamble_snippets_.end();
        if (find(begin, end, preamble) == end)
                preamble_snippets_.push_back(preamble);
 }
@@ -713,8 +711,8 @@ string const LaTeXFeatures::getMacros() const
 
        if (!preamble_snippets_.empty())
                macros << '\n';
-       FeaturesList::const_iterator pit  = preamble_snippets_.begin();
-       FeaturesList::const_iterator pend = preamble_snippets_.end();
+       SnippetList::const_iterator pit  = preamble_snippets_.begin();
+       SnippetList::const_iterator pend = preamble_snippets_.end();
        for (; pit != pend; ++pit)
                macros << *pit << '\n';