diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 147fe8e10f..5563056cb2 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -810,13 +810,7 @@ void BufferParams::writeFile(ostream & os) const void BufferParams::validate(LaTeXFeatures & features) const { - if (!getTextClass().requires().empty()) { - vector req = getTextClass().requires(); - for (vector::const_iterator it = req.begin(); - it != req.end(); ++it) { - features.require(*it); - } - } + features.require(getTextClass().requires()); if (outputChanges) { bool dvipost = LaTeXFeatures::isAvailable("dvipost"); diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index f192813d73..15547477c6 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -302,7 +302,7 @@ static string const newlyxcommand_def = // ///////////////////////////////////////////////////////////////////// -LaTeXFeatures::PackagesList LaTeXFeatures::packages_; +LaTeXFeatures::Packages LaTeXFeatures::packages_; LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p, @@ -322,10 +322,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 const & names) +{ + features_.insert(names.begin(), names.end()); } @@ -353,11 +356,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 +377,16 @@ void LaTeXFeatures::useLayout(docstring const & layoutname) TextClass const & tclass = params_.getTextClass(); if (tclass.hasLayout(layoutname)) { // Is this layout already in usedLayouts? - list::const_iterator cit = usedLayouts_.begin(); - list::const_iterator end = usedLayouts_.end(); - for (; cit != end; ++cit) { - if (layoutname == *cit) - return; - } + if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname) + != usedLayouts_.end()) + return; - LayoutPtr const & lyt = tclass[layoutname]; - if (!lyt->depends_on().empty()) { + Layout const & layout = *tclass[layoutname]; + require(layout.requires()); + + if (!layout.depends_on().empty()) { ++level; - useLayout(lyt->depends_on()); + useLayout(layout.depends_on()); --level; } usedLayouts_.push_back(layoutname); @@ -404,7 +402,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(); } @@ -428,8 +426,8 @@ bool LaTeXFeatures::isAvailable(string const & name) 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'; diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index fa64d8f7fb..268f6b05b0 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -66,8 +66,10 @@ public: void showStruct() const; /// void addPreambleSnippet(std::string const &); - /// Provide a string name-space to the requirements + /// Add a feature name requirements void require(std::string const & name); + /// Add a set of feature names requirements + void require(std::set const & names); /// Which of the required packages are installed? static void getAvailable(); /// Is the (required) package available? @@ -105,16 +107,18 @@ public: private: std::list usedLayouts_; + /// The features that are needed by the document + typedef std::set Features; + /// + Features features_; /// Static preamble bits from the external material insets - typedef std::list FeaturesList; + typedef std::list SnippetList; /// - FeaturesList features_; - /// - FeaturesList preamble_snippets_; + SnippetList preamble_snippets_; /// The available (required) packages - typedef std::list PackagesList; + typedef std::set Packages; /// - static PackagesList packages_; + static Packages packages_; /// typedef std::set LanguageList; /// used languages (only those that are supported by babel) diff --git a/src/Layout.cpp b/src/Layout.cpp index 80c8550923..ebf301abdd 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -488,8 +488,10 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass) break; case LT_REQUIRES: - if (lexrc.eatLine()) - requires_ = getVectorFromString(lexrc.getString()); + lexrc.eatLine(); + vector const req = + getVectorFromString(lexrc.getString()); + requires_.insert(req.begin(), req.end()); break; } diff --git a/src/Layout.h b/src/Layout.h index 56e031fd59..fa4bdc2da2 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -19,7 +19,7 @@ #include "Spacing.h" #include "support/docstring.h" -#include +#include #include namespace lyx { @@ -84,7 +84,7 @@ public: /// docstring const & preamble() const { return preamble_; } /// - std::vector const & requires() const { return requires_; } + std::set const & requires() const { return requires_; } /// std::string const & latexparam() const { return latexparam_; } /// @@ -256,7 +256,7 @@ private: /// Macro definitions needed for this layout docstring preamble_; /// Packages needed for this layout - std::vector requires_; + std::set requires_; }; } // namespace lyx diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index c7e33b1db2..19a99cfe09 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -991,13 +991,6 @@ void Paragraph::Private::validate(LaTeXFeatures & features, // then the layouts features.useLayout(layout.name()); - if (!layout.requires().empty()) { - vector req = layout.requires(); - for (vector::const_iterator it = req.begin(); - it != req.end(); ++it) { - features.require(*it); - } - } // then the fonts fontlist_.validate(features); diff --git a/src/TextClass.cpp b/src/TextClass.cpp index 51084095a5..ab92d33eb5 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -395,13 +395,9 @@ bool TextClass::read(FileName const & filename, ReadType rt) case TC_REQUIRES: { lexrc.eatLine(); - string const packages = lexrc.getString(); - vector req = getVectorFromString(packages); - for (vector::const_iterator it = req.begin(); - it != req.end(); ++it) { - if (find(requires_.begin(), requires_.end(), *it) == requires_.end()) - requires_.push_back(*it); - } + vector const req + = getVectorFromString(lexrc.getString()); + requires_.insert(req.begin(), req.end()); break; } @@ -663,7 +659,7 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name) FontInfo labelfont = inherit_font; ColorCode bgcolor(Color_background); string preamble; - vector requires; + set requires; bool multipar = false; bool passthru = false; bool needprotect = false; @@ -748,8 +744,9 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name) break; case IL_REQUIRES: { lexrc.eatLine(); - string const packages = lexrc.getString(); - requires = getVectorFromString(packages); + vector const req + = getVectorFromString(lexrc.getString()); + requires.insert(req.begin(), req.end()); break; } case IL_END: diff --git a/src/TextClass.h b/src/TextClass.h index 670bc5694b..a64aff6463 100644 --- a/src/TextClass.h +++ b/src/TextClass.h @@ -138,7 +138,7 @@ public: /// is this feature already provided by the class? bool provides(std::string const & p) const; /// features required by the class? - std::vector requires() const { return requires_; } + std::set const & requires() const { return requires_; } /// unsigned int columns() const; @@ -205,7 +205,7 @@ private: /// latex packages loaded by document class. std::set provides_; /// latex packages requested by document class. - std::vector requires_; + std::set requires_; /// unsigned int columns_; /// diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp index e2a6cacbe5..50c16a50cd 100644 --- a/src/insets/InsetFlex.cpp +++ b/src/insets/InsetFlex.cpp @@ -144,12 +144,7 @@ void InsetFlex::validate(LaTeXFeatures & features) const { if (!preamble_.empty()) features.addPreambleSnippet(preamble_); - if (packages_.empty()) - return; - for (vector::const_iterator it = packages_.begin(); - it != packages_.end(); ++it) { - features.require(*it); - } + features.require(packages_); } } // namespace lyx diff --git a/src/insets/InsetFlex.h b/src/insets/InsetFlex.h index 4ac50dcd05..141beb1b80 100644 --- a/src/insets/InsetFlex.h +++ b/src/insets/InsetFlex.h @@ -66,7 +66,7 @@ private: /// std::string name_; /// - std::vector packages_; + std::set packages_; /// std::string preamble_; }; diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index f4921ff295..37ccb9d28f 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -15,7 +15,7 @@ #include "support/docstring.h" -#include +#include #include namespace lyx { @@ -34,7 +34,7 @@ public: FontInfo labelfont; ColorCode bgcolor; std::string preamble; - std::vector requires; + std::set requires; bool multipar; bool passthru; bool needprotect;