>>>>> "Jean-Marc" == Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes:
Jean-Marc> The idea is to replace it with a std::set<string> and Jean-Marc> change LyXTextClass::provides() accordingly. The rest is Jean-Marc> purely mechanical (replace enum by string). It could be Jean-Marc> possible to simplify further the code, but it is not needed Jean-Marc> now (and may be more dangerous) This is how the basic (untested patch would look like). layout2layout support is still missing of course (so that this patch is useless as is). This trivial patch only works for the features that could already be provided earlier. Adding a "Provides graphics" will have no effect, for example. It is tempting to redefine isRequired() to return false when provides returns true, but we have to be a bit more careful than that. One solution would be to define a isNeeded() for this use case, and still use isRequired in the few cases where this makes sense. JMarc
Index: src/LaTeXFeatures.C =================================================================== --- src/LaTeXFeatures.C (révision 17488) +++ src/LaTeXFeatures.C (copie de travail) @@ -278,7 +278,7 @@ string const LaTeXFeatures::getPackages( // if (isRequired("amsmath") - && !tclass.provides(LyXTextClass::amsmath) + && !tclass.provides("amsmath") && params_.use_amsmath != BufferParams::package_off) { packages << "\\usepackage{amsmath}\n"; } @@ -306,7 +306,7 @@ string const LaTeXFeatures::getPackages( // makeidx.sty if (isRequired("makeidx")) { - if (!tclass.provides(LyXTextClass::makeidx)) + if (!tclass.provides("makeidx")) packages << "\\usepackage{makeidx}\n"; packages << "\\makeindex\n"; } @@ -370,13 +370,13 @@ string const LaTeXFeatures::getPackages( packages << "\\usepackage{esint}\n"; // url.sty - if (isRequired("url") && ! tclass.provides(LyXTextClass::url)) + if (isRequired("url") && ! tclass.provides("url")) packages << "\\IfFileExists{url.sty}{\\usepackage{url}}\n" " {\\newcommand{\\url}{\\texttt}}\n"; // float.sty // natbib.sty - if (isRequired("natbib") && ! tclass.provides(LyXTextClass::natbib)) { + if (isRequired("natbib") && ! tclass.provides("natbib")) { packages << "\\usepackage["; if (params_.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL) { packages << "numbers"; Index: src/buffer.C =================================================================== --- src/buffer.C (révision 17488) +++ src/buffer.C (copie de travail) @@ -1195,7 +1195,7 @@ void Buffer::validate(LaTeXFeatures & fe // AMS Style is at document level if (params().use_amsmath == BufferParams::package_on - || tclass.provides(LyXTextClass::amsmath)) + || tclass.provides("amsmath")) features.require("amsmath"); if (params().use_esint == BufferParams::package_on) features.require("esint"); Index: src/lyxtextclass.C =================================================================== --- src/lyxtextclass.C (révision 17488) +++ src/lyxtextclass.C (copie de travail) @@ -113,7 +113,6 @@ LyXTextClass::LyXTextClass(string const defaultfont_ = LyXFont(LyXFont::ALL_SANE); opt_fontsize_ = "10|11|12"; opt_pagestyle_ = "empty|plain|headings|fancy"; - provides_ = nothing; titletype_ = TITLE_COMMAND_AFTER; titlename_ = "maketitle"; loaded_ = false; @@ -158,10 +157,7 @@ enum TextClassTags { TC_TOCDEPTH, TC_CLASSOPTIONS, TC_PREAMBLE, - TC_PROVIDESAMSMATH, - TC_PROVIDESNATBIB, - TC_PROVIDESMAKEIDX, - TC_PROVIDESURL, + TC_PROVIDES, TC_LEFTMARGIN, TC_RIGHTMARGIN, TC_FLOAT, @@ -199,10 +195,7 @@ bool LyXTextClass::read(FileName const & { "outputtype", TC_OUTPUTTYPE }, { "pagestyle", TC_PAGESTYLE }, { "preamble", TC_PREAMBLE }, - { "providesamsmath", TC_PROVIDESAMSMATH }, - { "providesmakeidx", TC_PROVIDESMAKEIDX }, - { "providesnatbib", TC_PROVIDESNATBIB }, - { "providesurl", TC_PROVIDESURL }, + { "provides", TC_PROVIDES }, { "rightmargin", TC_RIGHTMARGIN }, { "secnumdepth", TC_SECNUMDEPTH }, { "sides", TC_SIDES }, @@ -383,24 +376,9 @@ bool LyXTextClass::read(FileName const & preamble_ = from_utf8(lexrc.getLongString("EndPreamble")); break; - case TC_PROVIDESAMSMATH: - if (lexrc.next() && lexrc.getInteger()) - provides_ |= amsmath; - break; - - case TC_PROVIDESNATBIB: - if (lexrc.next() && lexrc.getInteger()) - provides_ |= natbib; - break; - - case TC_PROVIDESMAKEIDX: - if (lexrc.next() && lexrc.getInteger()) - provides_ |= makeidx; - break; - - case TC_PROVIDESURL: - if (lexrc.next() && lexrc.getInteger()) - provides_ |= url; + case TC_PROVIDES: + if (lexrc.next()) + provides_.insert(lexrc.getString()); break; case TC_LEFTMARGIN: // left margin type @@ -1067,9 +1045,9 @@ OutputType LyXTextClass::outputType() co } -bool LyXTextClass::provides(LyXTextClass::Provides p) const +bool LyXTextClass::provides(string const & p) const { - return provides_ & p; + return provides_.find(p) != provides_.end(); } Index: src/lyxtextclass.h =================================================================== --- src/lyxtextclass.h (révision 17488) +++ src/lyxtextclass.h (copie de travail) @@ -16,7 +16,7 @@ #include <boost/shared_ptr.hpp> #include <vector> - +#include <set> namespace lyx { @@ -126,21 +126,8 @@ public: /// docstring const & preamble() const; - /// Packages that are already loaded by the class - enum Provides { - /// - nothing = 0, - /// - amsmath = 1, - /// - makeidx = 2, - /// - url = 4, - /// - natbib = 8 - }; - /// - bool provides(Provides p) const; + /// is this feature already provided by the class? + bool provides(std::string const & p) const; /// unsigned int columns() const; @@ -209,7 +196,7 @@ private: /// preamble text to support layout styles docstring preamble_; /// latex packages loaded by document class. - Provides provides_; + std::set<std::string> provides_; /// unsigned int columns_; /// @@ -261,14 +248,6 @@ private: }; -/// Merge two different provides flags into one bit field record -inline -void operator|=(LyXTextClass::Provides & p1, LyXTextClass::Provides p2) -{ - p1 = static_cast<LyXTextClass::Provides>(p1 | p2); -} - - /// convert page sides option to text 1 or 2 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p);