Use a set<string> instead of a vecctor<string> for list of features. This

allows to simplify the code to some extent.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22734 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2008-02-01 15:12:04 +00:00
parent 18ee04ae44
commit 11bea5a763
11 changed files with 53 additions and 70 deletions

View File

@ -810,13 +810,7 @@ void BufferParams::writeFile(ostream & os) const
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");

View File

@ -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 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;
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';

View File

@ -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_;
/// The features that are needed by the document
typedef std::set<std::string> Features;
///
Features features_;
/// Static preamble bits from the external material insets
typedef std::list<std::string> FeaturesList;
typedef std::list<std::string> SnippetList;
///
FeaturesList features_;
///
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)

View File

@ -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<string> const req =
getVectorFromString(lexrc.getString());
requires_.insert(req.begin(), req.end());
break;
}

View File

@ -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

View File

@ -991,13 +991,6 @@ void Paragraph::Private::validate(LaTeXFeatures & features,
// 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);

View File

@ -395,13 +395,9 @@ bool TextClass::read(FileName const & filename, ReadType rt)
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 & lexrc, docstring const & name)
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 & lexrc, docstring const & name)
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:

View File

@ -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_;
///

View File

@ -144,12 +144,7 @@ void InsetFlex::validate(LaTeXFeatures & features) const
{
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

View File

@ -66,7 +66,7 @@ private:
///
std::string name_;
///
std::vector<std::string> packages_;
std::set<std::string> packages_;
///
std::string preamble_;
};

View File

@ -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;