Jürgen Spitzmüller <[EMAIL PROTECTED]> writes: > Jean-Marc Lasgouttes wrote: >> I do not think it matter much in terms of speed, so code should be simple. > > OK, I remove that. > >> Because map require two types, doesn't it? This is why I wrote that >> there has to be a simpler type... > > OK, but the vector does not strike my naive mind overly complicated.
Here is what it looks like when using a std::set for features. Simpler, isn't it? BTW, there is a semantics problem: in a layout file, when I do Require foo Require bar does it mean that I want foo and bar, or only bar? InsetLayout used to implement the later solution and I changed it to the former. I only tested that the code compiles, I do not have proper test files (but I am fairly sure it is correct). UserGuide and EmbeddedObject crash with pegase: src/lyx Assertion triggered in bool lyx::EmbeddedFile::extract() const by failing check "enabled()" in file ../../lyx-devel/src/EmbeddedFiles.cpp:134 Aborted I do not think it is related to the patch, but who knows? Customization refuses to typeset because of a missing \inputencoding macro (I guess listings support should require an encoding). I do not think again it is my fault, do you see it? JMarc
svndiff src Index: src/TextClass.cpp =================================================================== --- src/TextClass.cpp (revision 22643) +++ src/TextClass.cpp (working copy) @@ -395,13 +395,9 @@ bool TextClass::read(FileName const & fi case TC_REQUIRES: { lexrc.eatLine(); - string const packages = lexrc.getString(); - vector<string> req = getVectorFromString(packages); - for (vector<string>::const_iterator it = req.begin(); - it != req.end(); ++it) { - if (find(requires_.begin(), requires_.end(), *it) == requires_.end()) - requires_.push_back(*it); - } + vector<string> const req + = getVectorFromString(lexrc.getString()); + requires_.insert(req.begin(), req.end()); break; } @@ -663,7 +659,7 @@ void TextClass::readInsetLayout(Lexer & FontInfo labelfont = inherit_font; ColorCode bgcolor(Color_background); string preamble; - vector<string> requires; + set<string> requires; bool multipar = false; bool passthru = false; bool needprotect = false; @@ -748,8 +744,9 @@ void TextClass::readInsetLayout(Lexer & break; case IL_REQUIRES: { lexrc.eatLine(); - string const packages = lexrc.getString(); - requires = getVectorFromString(packages); + vector<string> const req + = getVectorFromString(lexrc.getString()); + requires.insert(req.begin(), req.end()); break; } case IL_END: Index: src/Layout.h =================================================================== --- src/Layout.h (revision 22643) +++ src/Layout.h (working copy) @@ -19,7 +19,7 @@ #include "Spacing.h" #include "support/docstring.h" -#include <vector> +#include <set> #include <string> namespace lyx { @@ -84,7 +84,7 @@ public: /// docstring const & preamble() const { return preamble_; } /// - std::vector<std::string> const & requires() const { return requires_; } + std::set<std::string> 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<std::string> requires_; + std::set<std::string> requires_; }; } // namespace lyx Index: src/insets/InsetFlex.cpp =================================================================== --- src/insets/InsetFlex.cpp (revision 22643) +++ src/insets/InsetFlex.cpp (working copy) @@ -144,12 +144,7 @@ void InsetFlex::validate(LaTeXFeatures & { if (!preamble_.empty()) features.addPreambleSnippet(preamble_); - if (packages_.empty()) - return; - for (vector<string>::const_iterator it = packages_.begin(); - it != packages_.end(); ++it) { - features.require(*it); - } + features.require(packages_); } } // namespace lyx Index: src/insets/InsetLayout.h =================================================================== --- src/insets/InsetLayout.h (revision 22643) +++ src/insets/InsetLayout.h (working copy) @@ -15,7 +15,7 @@ #include "support/docstring.h" -#include <vector> +#include <set> #include <string> namespace lyx { @@ -34,7 +34,7 @@ public: FontInfo labelfont; ColorCode bgcolor; std::string preamble; - std::vector<std::string> requires; + std::set<std::string> requires; bool multipar; bool passthru; bool needprotect; Index: src/insets/InsetFlex.h =================================================================== --- src/insets/InsetFlex.h (revision 22643) +++ src/insets/InsetFlex.h (working copy) @@ -66,7 +66,7 @@ private: /// std::string name_; /// - std::vector<std::string> packages_; + std::set<std::string> packages_; /// std::string preamble_; }; Index: src/TextClass.h =================================================================== --- src/TextClass.h (revision 22643) +++ src/TextClass.h (working copy) @@ -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<std::string> requires() const { return requires_; } + std::set<std::string> const & requires() const { return requires_; } /// unsigned int columns() const; @@ -205,7 +205,7 @@ private: /// latex packages loaded by document class. std::set<std::string> provides_; /// latex packages requested by document class. - std::vector<std::string> requires_; + std::set<std::string> requires_; /// unsigned int columns_; /// Index: src/LaTeXFeatures.h =================================================================== --- src/LaTeXFeatures.h (revision 22643) +++ src/LaTeXFeatures.h (working copy) @@ -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<std::string> 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<docstring> usedLayouts_; - /// Static preamble bits from the external material insets - typedef std::list<std::string> FeaturesList; + /// The features that are needed by the document + typedef std::set<std::string> Features; /// - FeaturesList features_; + Features features_; + /// Static preamble bits from the external material insets + typedef std::list<std::string> SnippetList; /// - FeaturesList preamble_snippets_; + SnippetList preamble_snippets_; /// The available (required) packages - typedef std::list<std::string> PackagesList; + typedef std::set<std::string> Packages; /// - static PackagesList packages_; + static Packages packages_; /// typedef std::set<Language const *> LanguageList; /// used languages (only those that are supported by babel) Index: src/Paragraph.cpp =================================================================== --- src/Paragraph.cpp (revision 22643) +++ src/Paragraph.cpp (working copy) @@ -991,13 +991,6 @@ void Paragraph::Private::validate(LaTeXF // then the layouts features.useLayout(layout.name()); - if (!layout.requires().empty()) { - vector<string> req = layout.requires(); - for (vector<string>::const_iterator it = req.begin(); - it != req.end(); ++it) { - features.require(*it); - } - } // then the fonts fontlist_.validate(features); Index: src/LaTeXFeatures.cpp =================================================================== --- src/LaTeXFeatures.cpp (revision 22644) +++ src/LaTeXFeatures.cpp (working copy) @@ -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<string> 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 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 +402,7 @@ void LaTeXFeatures::useLayout(docstring 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 c 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() 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'; Index: src/Layout.cpp =================================================================== --- src/Layout.cpp (revision 22643) +++ src/Layout.cpp (working copy) @@ -488,8 +488,10 @@ bool Layout::read(Lexer & lexrc, TextCla break; case LT_REQUIRES: - if (lexrc.eatLine()) - requires_ = getVectorFromString(lexrc.getString()); + lexrc.eatLine(); + vector<string> const req = + getVectorFromString(lexrc.getString()); + requires_.insert(req.begin(), req.end()); break; } Index: src/BufferParams.cpp =================================================================== --- src/BufferParams.cpp (revision 22644) +++ src/BufferParams.cpp (working copy) @@ -810,13 +810,7 @@ void BufferParams::writeFile(ostream & o void BufferParams::validate(LaTeXFeatures & features) const { - if (!getTextClass().requires().empty()) { - vector<string> req = getTextClass().requires(); - for (vector<string>::const_iterator it = req.begin(); - it != req.end(); ++it) { - features.require(*it); - } - } + features.require(getTextClass().requires()); if (outputChanges) { bool dvipost = LaTeXFeatures::isAvailable("dvipost");