mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
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:
parent
18ee04ae44
commit
11bea5a763
@ -810,13 +810,7 @@ void BufferParams::writeFile(ostream & os) const
|
|||||||
|
|
||||||
void BufferParams::validate(LaTeXFeatures & features) const
|
void BufferParams::validate(LaTeXFeatures & features) const
|
||||||
{
|
{
|
||||||
if (!getTextClass().requires().empty()) {
|
features.require(getTextClass().requires());
|
||||||
vector<string> req = getTextClass().requires();
|
|
||||||
for (vector<string>::const_iterator it = req.begin();
|
|
||||||
it != req.end(); ++it) {
|
|
||||||
features.require(*it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outputChanges) {
|
if (outputChanges) {
|
||||||
bool dvipost = LaTeXFeatures::isAvailable("dvipost");
|
bool dvipost = LaTeXFeatures::isAvailable("dvipost");
|
||||||
|
@ -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,
|
LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
|
||||||
@ -322,10 +322,13 @@ bool LaTeXFeatures::useBabel() const
|
|||||||
|
|
||||||
void LaTeXFeatures::require(string const & name)
|
void LaTeXFeatures::require(string const & name)
|
||||||
{
|
{
|
||||||
if (isRequired(name))
|
features_.insert(name);
|
||||||
return;
|
}
|
||||||
|
|
||||||
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;
|
finished = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
string const name = lex.getString();
|
packages_.insert(lex.getString());
|
||||||
PackagesList::const_iterator begin = packages_.begin();
|
|
||||||
PackagesList::const_iterator end = packages_.end();
|
|
||||||
if (find(begin, end, name) == end)
|
|
||||||
packages_.push_back(name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -378,17 +377,16 @@ void LaTeXFeatures::useLayout(docstring const & layoutname)
|
|||||||
TextClass const & tclass = params_.getTextClass();
|
TextClass const & tclass = params_.getTextClass();
|
||||||
if (tclass.hasLayout(layoutname)) {
|
if (tclass.hasLayout(layoutname)) {
|
||||||
// Is this layout already in usedLayouts?
|
// Is this layout already in usedLayouts?
|
||||||
list<docstring>::const_iterator cit = usedLayouts_.begin();
|
if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname)
|
||||||
list<docstring>::const_iterator end = usedLayouts_.end();
|
!= usedLayouts_.end())
|
||||||
for (; cit != end; ++cit) {
|
|
||||||
if (layoutname == *cit)
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
LayoutPtr const & lyt = tclass[layoutname];
|
Layout const & layout = *tclass[layoutname];
|
||||||
if (!lyt->depends_on().empty()) {
|
require(layout.requires());
|
||||||
|
|
||||||
|
if (!layout.depends_on().empty()) {
|
||||||
++level;
|
++level;
|
||||||
useLayout(lyt->depends_on());
|
useLayout(layout.depends_on());
|
||||||
--level;
|
--level;
|
||||||
}
|
}
|
||||||
usedLayouts_.push_back(layoutname);
|
usedLayouts_.push_back(layoutname);
|
||||||
@ -404,7 +402,7 @@ void LaTeXFeatures::useLayout(docstring const & layoutname)
|
|||||||
|
|
||||||
bool LaTeXFeatures::isRequired(string const & name) const
|
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)
|
void LaTeXFeatures::addPreambleSnippet(string const & preamble)
|
||||||
{
|
{
|
||||||
FeaturesList::const_iterator begin = preamble_snippets_.begin();
|
SnippetList::const_iterator begin = preamble_snippets_.begin();
|
||||||
FeaturesList::const_iterator end = preamble_snippets_.end();
|
SnippetList::const_iterator end = preamble_snippets_.end();
|
||||||
if (find(begin, end, preamble) == end)
|
if (find(begin, end, preamble) == end)
|
||||||
preamble_snippets_.push_back(preamble);
|
preamble_snippets_.push_back(preamble);
|
||||||
}
|
}
|
||||||
@ -713,8 +711,8 @@ string const LaTeXFeatures::getMacros() const
|
|||||||
|
|
||||||
if (!preamble_snippets_.empty())
|
if (!preamble_snippets_.empty())
|
||||||
macros << '\n';
|
macros << '\n';
|
||||||
FeaturesList::const_iterator pit = preamble_snippets_.begin();
|
SnippetList::const_iterator pit = preamble_snippets_.begin();
|
||||||
FeaturesList::const_iterator pend = preamble_snippets_.end();
|
SnippetList::const_iterator pend = preamble_snippets_.end();
|
||||||
for (; pit != pend; ++pit)
|
for (; pit != pend; ++pit)
|
||||||
macros << *pit << '\n';
|
macros << *pit << '\n';
|
||||||
|
|
||||||
|
@ -66,8 +66,10 @@ public:
|
|||||||
void showStruct() const;
|
void showStruct() const;
|
||||||
///
|
///
|
||||||
void addPreambleSnippet(std::string 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);
|
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?
|
/// Which of the required packages are installed?
|
||||||
static void getAvailable();
|
static void getAvailable();
|
||||||
/// Is the (required) package available?
|
/// Is the (required) package available?
|
||||||
@ -105,16 +107,18 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::list<docstring> usedLayouts_;
|
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
|
/// Static preamble bits from the external material insets
|
||||||
typedef std::list<std::string> FeaturesList;
|
typedef std::list<std::string> SnippetList;
|
||||||
///
|
///
|
||||||
FeaturesList features_;
|
SnippetList preamble_snippets_;
|
||||||
///
|
|
||||||
FeaturesList preamble_snippets_;
|
|
||||||
/// The available (required) packages
|
/// 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;
|
typedef std::set<Language const *> LanguageList;
|
||||||
/// used languages (only those that are supported by babel)
|
/// used languages (only those that are supported by babel)
|
||||||
|
@ -488,8 +488,10 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LT_REQUIRES:
|
case LT_REQUIRES:
|
||||||
if (lexrc.eatLine())
|
lexrc.eatLine();
|
||||||
requires_ = getVectorFromString(lexrc.getString());
|
vector<string> const req =
|
||||||
|
getVectorFromString(lexrc.getString());
|
||||||
|
requires_.insert(req.begin(), req.end());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#include "Spacing.h"
|
#include "Spacing.h"
|
||||||
#include "support/docstring.h"
|
#include "support/docstring.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
@ -84,7 +84,7 @@ public:
|
|||||||
///
|
///
|
||||||
docstring const & preamble() const { return preamble_; }
|
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_; }
|
std::string const & latexparam() const { return latexparam_; }
|
||||||
///
|
///
|
||||||
@ -256,7 +256,7 @@ private:
|
|||||||
/// Macro definitions needed for this layout
|
/// Macro definitions needed for this layout
|
||||||
docstring preamble_;
|
docstring preamble_;
|
||||||
/// Packages needed for this layout
|
/// Packages needed for this layout
|
||||||
std::vector<std::string> requires_;
|
std::set<std::string> requires_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -991,13 +991,6 @@ void Paragraph::Private::validate(LaTeXFeatures & features,
|
|||||||
|
|
||||||
// then the layouts
|
// then the layouts
|
||||||
features.useLayout(layout.name());
|
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
|
// then the fonts
|
||||||
fontlist_.validate(features);
|
fontlist_.validate(features);
|
||||||
|
@ -395,13 +395,9 @@ bool TextClass::read(FileName const & filename, ReadType rt)
|
|||||||
|
|
||||||
case TC_REQUIRES: {
|
case TC_REQUIRES: {
|
||||||
lexrc.eatLine();
|
lexrc.eatLine();
|
||||||
string const packages = lexrc.getString();
|
vector<string> const req
|
||||||
vector<string> req = getVectorFromString(packages);
|
= getVectorFromString(lexrc.getString());
|
||||||
for (vector<string>::const_iterator it = req.begin();
|
requires_.insert(req.begin(), req.end());
|
||||||
it != req.end(); ++it) {
|
|
||||||
if (find(requires_.begin(), requires_.end(), *it) == requires_.end())
|
|
||||||
requires_.push_back(*it);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,7 +659,7 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
|
|||||||
FontInfo labelfont = inherit_font;
|
FontInfo labelfont = inherit_font;
|
||||||
ColorCode bgcolor(Color_background);
|
ColorCode bgcolor(Color_background);
|
||||||
string preamble;
|
string preamble;
|
||||||
vector<string> requires;
|
set<string> requires;
|
||||||
bool multipar = false;
|
bool multipar = false;
|
||||||
bool passthru = false;
|
bool passthru = false;
|
||||||
bool needprotect = false;
|
bool needprotect = false;
|
||||||
@ -748,8 +744,9 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
|
|||||||
break;
|
break;
|
||||||
case IL_REQUIRES: {
|
case IL_REQUIRES: {
|
||||||
lexrc.eatLine();
|
lexrc.eatLine();
|
||||||
string const packages = lexrc.getString();
|
vector<string> const req
|
||||||
requires = getVectorFromString(packages);
|
= getVectorFromString(lexrc.getString());
|
||||||
|
requires.insert(req.begin(), req.end());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IL_END:
|
case IL_END:
|
||||||
|
@ -138,7 +138,7 @@ public:
|
|||||||
/// is this feature already provided by the class?
|
/// is this feature already provided by the class?
|
||||||
bool provides(std::string const & p) const;
|
bool provides(std::string const & p) const;
|
||||||
/// features required by the class?
|
/// 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;
|
unsigned int columns() const;
|
||||||
@ -205,7 +205,7 @@ private:
|
|||||||
/// latex packages loaded by document class.
|
/// latex packages loaded by document class.
|
||||||
std::set<std::string> provides_;
|
std::set<std::string> provides_;
|
||||||
/// latex packages requested by document class.
|
/// latex packages requested by document class.
|
||||||
std::vector<std::string> requires_;
|
std::set<std::string> requires_;
|
||||||
///
|
///
|
||||||
unsigned int columns_;
|
unsigned int columns_;
|
||||||
///
|
///
|
||||||
|
@ -144,12 +144,7 @@ void InsetFlex::validate(LaTeXFeatures & features) const
|
|||||||
{
|
{
|
||||||
if (!preamble_.empty())
|
if (!preamble_.empty())
|
||||||
features.addPreambleSnippet(preamble_);
|
features.addPreambleSnippet(preamble_);
|
||||||
if (packages_.empty())
|
features.require(packages_);
|
||||||
return;
|
|
||||||
for (vector<string>::const_iterator it = packages_.begin();
|
|
||||||
it != packages_.end(); ++it) {
|
|
||||||
features.require(*it);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -66,7 +66,7 @@ private:
|
|||||||
///
|
///
|
||||||
std::string name_;
|
std::string name_;
|
||||||
///
|
///
|
||||||
std::vector<std::string> packages_;
|
std::set<std::string> packages_;
|
||||||
///
|
///
|
||||||
std::string preamble_;
|
std::string preamble_;
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#include "support/docstring.h"
|
#include "support/docstring.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
@ -34,7 +34,7 @@ public:
|
|||||||
FontInfo labelfont;
|
FontInfo labelfont;
|
||||||
ColorCode bgcolor;
|
ColorCode bgcolor;
|
||||||
std::string preamble;
|
std::string preamble;
|
||||||
std::vector<std::string> requires;
|
std::set<std::string> requires;
|
||||||
bool multipar;
|
bool multipar;
|
||||||
bool passthru;
|
bool passthru;
|
||||||
bool needprotect;
|
bool needprotect;
|
||||||
|
Loading…
Reference in New Issue
Block a user