After a hiatus, I'm returning to the rewrite of InsetCommandParams, the purpose of all of this being to make things more flexible, with the ultimate goal being biblatex support and a kind of InsetCommandFlex that will allow user-definable such things. The next step, really, is to fix up CiteEngine so that we can have different sets of parameters for InsetCitation depending upon what engine is in use. (Something like this also needs doing with InsetInclude.)

This patch reworks the machinery that holds information about what parameters there are and what their values are. There's enough flexibility here that true keyval support ought to be fairly easy at this point. I'll have a peek at that shortly.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23168 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2008-02-23 22:01:02 +00:00
parent c207a8fe0b
commit 8e9410b3d0
27 changed files with 294 additions and 179 deletions

View File

@ -38,8 +38,6 @@ namespace lyx {
int InsetBibitem::key_counter = 0; int InsetBibitem::key_counter = 0;
docstring const key_prefix = from_ascii("key-"); docstring const key_prefix = from_ascii("key-");
@ -51,12 +49,14 @@ InsetBibitem::InsetBibitem(InsetCommandParams const & p)
} }
CommandInfo const * InsetBibitem::findInfo(string const & /* cmdName */) ParamInfo const & InsetBibitem::findInfo(string const & /* cmdName */)
{ {
static const char * const paramnames[] = {"label", "key", ""}; static ParamInfo param_info_;
static const bool isoptional[] = {true, false}; if (param_info_.empty()) {
static const CommandInfo info = {2, paramnames, isoptional}; param_info_.add("label", true);
return &info; param_info_.add("key", false);
}
return param_info_;
} }

View File

@ -46,7 +46,7 @@ public:
/// Update the counter of this inset /// Update the counter of this inset
virtual void updateLabels(Buffer const &, ParIterator const &); virtual void updateLabels(Buffer const &, ParIterator const &);
/// ///
static CommandInfo const * findInfo(std::string const &); static ParamInfo const & findInfo(std::string const &);
/// ///
static std::string defaultCommand() { return "bibitem"; }; static std::string defaultCommand() { return "bibitem"; };
/// ///
@ -56,8 +56,8 @@ protected:
/// ///
virtual void doDispatch(Cursor & cur, FuncRequest & cmd); virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
private: private:
///
virtual Inset * clone() const; virtual Inset * clone() const;
/// The label that is set by updateLabels /// The label that is set by updateLabels
docstring autolabel_; docstring autolabel_;
/// ///

View File

@ -53,13 +53,16 @@ InsetBibtex::InsetBibtex(InsetCommandParams const & p)
{} {}
CommandInfo const * InsetBibtex::findInfo(string const & /* cmdName */) ParamInfo const & InsetBibtex::findInfo(string const & /* cmdName */)
{ {
static const char * const paramnames[] = static ParamInfo param_info_;
{"options", "btprint", "bibfiles", "embed", ""}; if (param_info_.empty()) {
static const bool isoptional[] = {true, true, false, false}; param_info_.add("options", true);
static const CommandInfo info = {4, paramnames, isoptional}; param_info_.add("btprint", true);
return &info; param_info_.add("bibfiles", false);
param_info_.add("embed", false);
}
return param_info_;
} }

View File

@ -49,7 +49,7 @@ public:
/// ///
void validate(LaTeXFeatures &) const; void validate(LaTeXFeatures &) const;
/// ///
static CommandInfo const * findInfo(std::string const &); static ParamInfo const & findInfo(std::string const &);
/// ///
static std::string defaultCommand() { return "bibtex"; }; static std::string defaultCommand() { return "bibtex"; };
/// ///
@ -61,8 +61,10 @@ public:
void updateEmbeddedFile(Buffer const & buf, EmbeddedFile const & file); void updateEmbeddedFile(Buffer const & buf, EmbeddedFile const & file);
protected: protected:
///
virtual void doDispatch(Cursor & cur, FuncRequest & cmd); virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
private: private:
///
virtual Inset * clone() const; virtual Inset * clone() const;
}; };

View File

@ -375,22 +375,26 @@ docstring const getBasicLabel(docstring const & keyList, docstring const & after
} // anon namespace } // anon namespace
ParamInfo InsetCitation::param_info_;
InsetCitation::InsetCitation(InsetCommandParams const & p) InsetCitation::InsetCitation(InsetCommandParams const & p)
: InsetCommand(p, "citation") : InsetCommand(p, "citation")
{} {}
CommandInfo const * InsetCitation::findInfo(string const & /* cmdName */) ParamInfo const & InsetCitation::findInfo(string const & /* cmdName */)
{ {
// standard cite does only take one argument if jurabib is // standard cite does only take one argument if jurabib is
// not used, but jurabib extends this to two arguments, so // not used, but jurabib extends this to two arguments, so
// we have to allow both here. InsetCitation takes care that // we have to allow both here. InsetCitation takes care that
// LaTeX output is nevertheless correct. // LaTeX output is nevertheless correct.
static const char * const paramnames[] = if (param_info_.empty()) {
{"after", "before", "key", ""}; param_info_.add("after", true);
static const bool isoptional[] = {true, true, false}; param_info_.add("before", true);
static const CommandInfo info = {3, paramnames, isoptional}; param_info_.add("key", false);
return &info; }
return param_info_;
} }

View File

@ -49,7 +49,7 @@ public:
/// ///
void validate(LaTeXFeatures &) const; void validate(LaTeXFeatures &) const;
/// ///
static CommandInfo const * findInfo(std::string const &); static ParamInfo const & findInfo(std::string const &);
//FIXME This is the locus of the design problem we have. //FIXME This is the locus of the design problem we have.
//It really ought to do what default_cite_command() does, //It really ought to do what default_cite_command() does,
//but to do that it needs to know what CiteEngine we are //but to do that it needs to know what CiteEngine we are
@ -59,14 +59,16 @@ public:
/// ///
static bool isCompatibleCommand(std::string const & cmd); static bool isCompatibleCommand(std::string const & cmd);
private: private:
///
virtual Inset * clone() const virtual Inset * clone() const
{ { return new InsetCitation(params()); }
return new InsetCitation(params()); /// we'll eventually want to be able to get info on this from the
} /// various CiteEngines
static ParamInfo param_info_;
/// This function does the donkey work of creating the pretty label /// This function does the donkey work of creating the pretty label
docstring const generateLabel(Buffer const &) const; docstring const generateLabel(Buffer const &) const;
///
class Cache { class Cache {
public: public:
/// ///

View File

@ -80,7 +80,7 @@ public:
bool setMouseHover(bool mouse_hover); bool setMouseHover(bool mouse_hover);
/// Return parameter information for command cmdName. /// Return parameter information for command cmdName.
/// Not implemented here. Must be implemented in derived class. /// Not implemented here. Must be implemented in derived class.
static CommandInfo const * findInfo(std::string const & cmdName); static ParamInfo const & findInfo(std::string const & cmdName);
/// Return default command for this inset. /// Return default command for this inset.
/// Not implemented here. Must be implemented in derived class. /// Not implemented here. Must be implemented in derived class.
static std::string defaultCommand(); static std::string defaultCommand();

View File

@ -42,14 +42,63 @@ using namespace lyx::support;
namespace lyx { namespace lyx {
ParamInfo::ParamData::ParamData(std::string const & s, bool b) :
name_(s), optional_(b)
{}
bool ParamInfo::ParamData::operator==(ParamInfo::ParamData const & rhs) const
{
return name() == rhs.name() && isOptional() == rhs.isOptional();
}
bool ParamInfo::hasParam(std::string const & name) const
{
const_iterator it = begin();
for (; it != end(); ++it) {
if (it->name() == name)
return true;
}
return false;
}
void ParamInfo::add(std::string const & name, bool opt)
{
info_.push_back(ParamData(name, opt));
}
bool ParamInfo::operator==(ParamInfo const & rhs) const
{
// the idea here is to check each ParamData for equality
const_iterator itL = begin();
const_iterator itR = rhs.begin();
const_iterator endL = end();
const_iterator endR = rhs.end();
while (true) {
// if they both end together, return true
if (itL == endL && itR == endR)
return true;
// but if one ends before the other, return false
if (itL == endL || itR == endR)
return false;
//check this one for equality
if (*itL != *itR)
return false;
// equal, so check the next one
++itL;
++itR;
}
}
InsetCommandParams::InsetCommandParams(InsetCode code) InsetCommandParams::InsetCommandParams(InsetCode code)
: insetCode_(code), preview_(false) : insetCode_(code), preview_(false)
{ {
cmdName_ = getDefaultCmd(code); cmdName_ = getDefaultCmd(code);
info_ = findInfo(code, cmdName_); info_ = findInfo(code, cmdName_);
BOOST_ASSERT(info_);
params_.resize(info_->n);
} }
@ -58,12 +107,10 @@ InsetCommandParams::InsetCommandParams(InsetCode code,
: insetCode_(code), cmdName_(cmdName), preview_(false) : insetCode_(code), cmdName_(cmdName), preview_(false)
{ {
info_ = findInfo(code, cmdName); info_ = findInfo(code, cmdName);
BOOST_ASSERT(info_);
params_.resize(info_->n);
} }
CommandInfo const * InsetCommandParams::findInfo( ParamInfo const & InsetCommandParams::findInfo(
InsetCode code, string const & cmdName) InsetCode code, string const & cmdName)
{ {
switch (code) { switch (code) {
@ -96,7 +143,8 @@ CommandInfo const * InsetCommandParams::findInfo(
default: default:
BOOST_ASSERT(false); BOOST_ASSERT(false);
} }
return 0; static const ParamInfo pi;
return pi; // to silence the warning
} }
@ -131,7 +179,7 @@ string InsetCommandParams::getDefaultCmd(InsetCode code) {
default: default:
BOOST_ASSERT(false); BOOST_ASSERT(false);
} }
return string(); //silence the warning return string(); // silence the warning
} }
@ -168,7 +216,7 @@ bool InsetCommandParams::isCompatibleCommand(
default: default:
BOOST_ASSERT(false); BOOST_ASSERT(false);
} }
return false; //silence the warning return false; // silence the warning
} }
@ -182,21 +230,7 @@ void InsetCommandParams::setCmdName(string const & name)
} }
cmdName_ = name; cmdName_ = name;
CommandInfo const * const info = findInfo(insetCode_, cmdName_); info_ = findInfo(insetCode_, cmdName_);
if (!info) {
LYXERR0("Command '" << name << "' is not compatible with a '" <<
insetType() << "' inset.");
return;
}
ParamVector params(info->n);
// Overtake parameters with the same name
for (size_t i = 0; i < info_->n; ++i) {
int j = findToken(info->paramnames, info_->paramnames[i]);
if (j >= 0)
params[j] = params_[i];
}
info_ = info;
swap(params, params_);
} }
@ -231,11 +265,6 @@ void InsetCommandParams::read(Lexer & lex)
} }
info_ = findInfo(insetCode_, cmdName_); info_ = findInfo(insetCode_, cmdName_);
if (!info_) {
lex.printError("InsetCommandParams: Unknown inset name `$$Token'");
throw ExceptionMessage(WarningException,
_("Unknown inset name: "), from_utf8(insetType()));
}
string token; string token;
while (lex.isOK()) { while (lex.isOK()) {
@ -248,10 +277,9 @@ void InsetCommandParams::read(Lexer & lex)
preview_ = lex.getBool(); preview_ = lex.getBool();
continue; continue;
} }
int const i = findToken(info_->paramnames, token); if (info_.hasParam(token)) {
if (i >= 0) {
lex.next(true); lex.next(true);
params_[i] = lex.getDocString(); params_[token] = lex.getDocString();
} else { } else {
lex.printError("Unknown parameter name `$$Token' for command " + cmdName_); lex.printError("Unknown parameter name `$$Token' for command " + cmdName_);
throw ExceptionMessage(WarningException, throw ExceptionMessage(WarningException,
@ -275,12 +303,18 @@ void InsetCommandParams::write(ostream & os) const
os << "LatexCommand " << cmdName_ << '\n'; os << "LatexCommand " << cmdName_ << '\n';
if (preview_) if (preview_)
os << "preview true\n"; os << "preview true\n";
for (size_t i = 0; i < info_->n; ++i) ParamInfo::const_iterator it = info_.begin();
if (!params_[i].empty()) ParamInfo::const_iterator end = info_.end();
for (; it != end; ++it) {
std::string const & name = it->name();
docstring const & data = (*this)[name];
if (!data.empty()) {
// FIXME UNICODE // FIXME UNICODE
os << info_->paramnames[i] << ' ' os << name << ' '
<< Lexer::quoteString(to_utf8(params_[i])) << Lexer::quoteString(to_utf8(data))
<< '\n'; << '\n';
}
}
} }
@ -288,28 +322,36 @@ docstring const InsetCommandParams::getCommand() const
{ {
docstring s = '\\' + from_ascii(cmdName_); docstring s = '\\' + from_ascii(cmdName_);
bool noparam = true; bool noparam = true;
for (size_t i = 0; i < info_->n; ++i) { ParamInfo::const_iterator it = info_.begin();
if (info_->optional[i]) { ParamInfo::const_iterator end = info_.end();
if (params_[i].empty()) { for (; it != end; ++it) {
// We need to write this parameter even if std::string const & name = it->name();
// it is empty if nonempty optional parameters docstring const & data = (*this)[name];
// follow before the next required parameter. if (!it->isOptional()) {
for (size_t j = i + 1; j < info_->n; ++j) { s += '{' + data + '}';
if (!info_->optional[j])
break;
if (!params_[j].empty()) {
s += "[]";
noparam = false;
break;
}
}
} else {
s += '[' + params_[i] + ']';
noparam = false;
}
} else {
s += '{' + params_[i] + '}';
noparam = false; noparam = false;
continue;
}
if (!data.empty()) {
s += '[' + data + ']';
noparam = false;
continue;
}
// This param is therefore optional but empty.
// But we need to write it anyway if nonempty
// optional parameters follow before the next
// required parameter.
ParamInfo::const_iterator it2 = it;
for (++it2; it2 != end; ++it2) {
if (!it2->isOptional())
break;
std::string const & name2 = it2->name();
docstring const & data2 = (*this)[name2];
if (!data2.empty()) {
s += "[]";
noparam = false;
break;
}
} }
} }
if (noparam) if (noparam)
@ -320,36 +362,47 @@ docstring const InsetCommandParams::getCommand() const
} }
namespace {
//predicate for what follows
bool paramIsNonOptional(ParamInfo::ParamData pi)
{
return !pi.isOptional();
}
}
docstring const InsetCommandParams::getFirstNonOptParam() const docstring const InsetCommandParams::getFirstNonOptParam() const
{ {
for (size_t i = 0; i < info_->n; ++i) ParamInfo::const_iterator it =
if (!info_->optional[i]) find_if(info_.begin(), info_.end(), paramIsNonOptional);
return params_[i]; if (it == info_.end())
BOOST_ASSERT(false); BOOST_ASSERT(false);
return docstring(); return (*this)[it->name()];
} }
docstring const & InsetCommandParams::operator[](string const & name) const docstring const & InsetCommandParams::operator[](string const & name) const
{ {
int const i = findToken(info_->paramnames, name); static const docstring dummy; //so we don't return a ref to temporary
BOOST_ASSERT(i >= 0); if (!info_.hasParam(name))
return params_[i]; BOOST_ASSERT(false);
ParamMap::const_iterator data = params_.find(name);
if (data == params_.end() || data->second.empty())
return dummy;
return data->second;
} }
docstring & InsetCommandParams::operator[](string const & name) docstring & InsetCommandParams::operator[](string const & name)
{ {
int const i = findToken(info_->paramnames, name); if (!info_.hasParam(name))
BOOST_ASSERT(i >= 0); BOOST_ASSERT(false);
return params_[i]; return params_[name];
} }
void InsetCommandParams::clear() void InsetCommandParams::clear()
{ {
for (size_t i = 0; i < info_->n; ++i) params_.clear();
params_[i].clear();
} }

View File

@ -20,21 +20,57 @@
#include <iosfwd> #include <iosfwd>
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
namespace lyx { namespace lyx {
class Lexer; class Lexer;
// No parameter may be named "preview", because that is a required class ParamInfo {
// flag for all commands. public:
struct CommandInfo { ///
/// Number of parameters class ParamData {
size_t n; // No parameter may be named "preview", because that is a required
/// Parameter names. paramnames[n] must be "". // flag for all commands.
char const * const * paramnames; public:
/// Tells whether a parameter is optional ///
bool const * optional; ParamData(std::string const &, bool);
///
std::string name() const { return name_; }
///
bool isOptional() const { return optional_; }
///
bool operator==(ParamData const &) const;
///
bool operator!=(ParamData const & rhs) const
{ return !(*this == rhs); }
private:
///
std::string name_;
///
bool optional_;
};
/// adds a new parameter
void add(std::string const & name, bool optional);
///
bool empty() const { return info_.empty(); }
///
size_t size() const { return info_.size(); }
///
typedef std::vector<ParamData>::const_iterator const_iterator;
///
const_iterator begin() const { return info_.begin(); }
///
const_iterator end() const { return info_.end(); }
///
bool hasParam(std::string const & name) const;
///
bool operator==(ParamInfo const &) const;
private:
///
std::vector<ParamData> info_;
}; };
@ -81,29 +117,27 @@ private:
/// ///
/// Get information for inset type \p code. /// Get information for inset type \p code.
/// Returns 0 if the inset is not known. /// Returns 0 if the inset is not known.
static CommandInfo const * findInfo(InsetCode code); static ParamInfo const & findInfo(InsetCode code);
/// Get information for \p code and command \p cmdName. /// Get information for \p code and command \p cmdName.
/// Returns 0 if the combination is not known. /// Returns 0 if the combination is not known.
/// Don't call this without first making sure the command name is /// Don't call this without first making sure the command name is
/// acceptable to the inset. /// acceptable to the inset.
static CommandInfo const * findInfo(InsetCode code, static ParamInfo const & findInfo(InsetCode code,
std::string const & cmdName); std::string const & cmdName);
/// ///
static bool isCompatibleCommand(InsetCode code, std::string const & s); static bool isCompatibleCommand(InsetCode code, std::string const & s);
/// ///
std::string getDefaultCmd(InsetCode); std::string getDefaultCmd(InsetCode);
/// Description of all command properties /// Description of all command properties
CommandInfo const * info_; ParamInfo info_;
/// what kind of inset we're the parameters for /// what kind of inset we're the parameters for
InsetCode insetCode_; InsetCode insetCode_;
/// The name of this command as it appears in .lyx and .tex files /// The name of this command as it appears in .lyx and .tex files
std::string cmdName_; std::string cmdName_;
/// ///
typedef std::vector<docstring> ParamVector; typedef std::map<std::string, docstring> ParamMap;
/// The parameters (both optional and required ones). The order is /// The parameters, by name.
/// the same that is required for LaTeX output. The size of params_ ParamMap params_;
/// is always info_->n.
ParamVector params_;
/// ///
bool preview_; bool preview_;
/// ///
@ -111,10 +145,8 @@ private:
InsetCommandParams const &); InsetCommandParams const &);
}; };
/// ///
bool operator==(InsetCommandParams const &, InsetCommandParams const &); bool operator==(InsetCommandParams const &, InsetCommandParams const &);
/// ///
bool operator!=(InsetCommandParams const &, InsetCommandParams const &); bool operator!=(InsetCommandParams const &, InsetCommandParams const &);

View File

@ -48,12 +48,13 @@ InsetFloatList::InsetFloatList(string const & type)
} }
CommandInfo const * InsetFloatList::findInfo(string const & /* cmdName */) ParamInfo const & InsetFloatList::findInfo(string const & /* cmdName */)
{ {
static const char * const paramnames[] = {"type", ""}; static ParamInfo param_info_;
static const bool isoptional[] = {false}; if (param_info_.empty()) {
static const CommandInfo info = {1, paramnames, isoptional}; param_info_.add("type", false);
return &info; }
return param_info_;
} }

View File

@ -50,16 +50,17 @@ public:
/// ///
void validate(LaTeXFeatures & features) const; void validate(LaTeXFeatures & features) const;
/// ///
static CommandInfo const * findInfo(std::string const & cmdName = ""); static ParamInfo const & findInfo(std::string const &);
/// ///
static std::string defaultCommand() { return "listoftables"; }; static std::string defaultCommand() { return "listoftables"; };
/// ///
static bool isCompatibleCommand(std::string const & s); static bool isCompatibleCommand(std::string const & s);
private: private:
///
virtual Inset * clone() const virtual Inset * clone() const
{ { return new InsetFloatList(to_ascii(getParam("type"))); }
return new InsetFloatList(to_ascii(getParam("type"))); ///
} static ParamInfo param_info_;
}; };

View File

@ -30,11 +30,10 @@ InsetHFill::InsetHFill()
{} {}
CommandInfo const * InsetHFill::findInfo(string const & /* cmdName */) ParamInfo const & InsetHFill::findInfo(string const & /* cmdName */)
{ {
static const char * const paramnames[] = {""}; static ParamInfo param_info_;
static const CommandInfo info = {0, paramnames, 0}; return param_info_;
return &info;
} }

View File

@ -44,13 +44,14 @@ public:
// a line separator)? // a line separator)?
bool isSpace() const; bool isSpace() const;
/// ///
static CommandInfo const * findInfo(std::string const &); static ParamInfo const & findInfo(std::string const &);
/// ///
static std::string defaultCommand() { return "hfill"; }; static std::string defaultCommand() { return "hfill"; };
/// ///
static bool isCompatibleCommand(std::string const & s) static bool isCompatibleCommand(std::string const & s)
{ return s == "hfill"; } { return s == "hfill"; }
private: private:
///
virtual Inset * clone() const; virtual Inset * clone() const;
}; };

View File

@ -33,13 +33,15 @@ InsetHyperlink::InsetHyperlink(InsetCommandParams const & p)
{} {}
CommandInfo const * InsetHyperlink::findInfo(string const & /* cmdName */) ParamInfo const & InsetHyperlink::findInfo(string const & /* cmdName */)
{ {
static const char * const paramnames[] = static ParamInfo param_info_;
{"name", "target", "type", ""}; if (param_info_.empty()) {
static const bool isoptional[] = {true, false}; param_info_.add("name", true);
static const CommandInfo info = {3, paramnames, isoptional}; param_info_.add("target", false);
return &info; param_info_.add("type", false);
}
return param_info_;
} }

View File

@ -49,7 +49,7 @@ public:
/// the string that is passed to the TOC /// the string that is passed to the TOC
void textString(Buffer const &, odocstream &) const; void textString(Buffer const &, odocstream &) const;
/// ///
static CommandInfo const * findInfo(std::string const &); static ParamInfo const & findInfo(std::string const &);
/// ///
static std::string defaultCommand() { return "href"; }; static std::string defaultCommand() { return "href"; };
/// ///

View File

@ -5,6 +5,7 @@
* *
* \author Lars Gullik Bjønnes * \author Lars Gullik Bjønnes
* \author Richard Heck (conversion to InsetCommand) * \author Richard Heck (conversion to InsetCommand)
* \author Bo Peng (embedding stuff)
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -164,15 +165,18 @@ InsetInclude::InsetInclude(InsetInclude const & other)
} }
CommandInfo const * InsetInclude::findInfo(string const & /* cmdName */) ParamInfo const & InsetInclude::findInfo(string const & /* cmdName */)
{ {
// FIXME // FIXME
// This is only correct for the case of listings, but it'll do for now. // This is only correct for the case of listings, but it'll do for now.
// In the other cases, this second parameter should just be empty. // In the other cases, this second parameter should just be empty.
static const char * const paramnames[] = {"filename", "embed", "lstparams", ""}; static ParamInfo param_info_;
static const bool isoptional[] = {false, false, true}; if (param_info_.empty()) {
static const CommandInfo info = {3, paramnames, isoptional}; param_info_.add("filename", false);
return &info; param_info_.add("embed", false);
param_info_.add("lstparams", true);
}
return param_info_;
} }

View File

@ -96,7 +96,7 @@ public:
/// ///
void updateEmbeddedFile(Buffer const & buf, EmbeddedFile const & file); void updateEmbeddedFile(Buffer const & buf, EmbeddedFile const & file);
/// ///
static CommandInfo const * findInfo(std::string const &); static ParamInfo const & findInfo(std::string const &);
/// ///
static std::string defaultCommand() { return "include"; }; static std::string defaultCommand() { return "include"; };
/// ///

View File

@ -80,12 +80,13 @@ InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
{} {}
CommandInfo const * InsetPrintIndex::findInfo(string const & /* cmdName */) ParamInfo const & InsetPrintIndex::findInfo(string const & /* cmdName */)
{ {
static const char * const paramnames[] = {"name", ""}; static ParamInfo param_info_;
static const bool isoptional[] = {false}; if (param_info_.empty()) {
static const CommandInfo info = {1, paramnames, isoptional}; param_info_.add("name", false);
return &info; }
return param_info_;
} }

View File

@ -65,7 +65,7 @@ public:
/// ///
docstring const getScreenLabel(Buffer const &) const; docstring const getScreenLabel(Buffer const &) const;
/// ///
static CommandInfo const * findInfo(std::string const & cmdName = ""); static ParamInfo const & findInfo(std::string const &);
/// ///
static std::string defaultCommand() { return "printindex"; }; static std::string defaultCommand() { return "printindex"; };
/// ///

View File

@ -33,12 +33,13 @@ InsetLabel::InsetLabel(InsetCommandParams const & p)
{} {}
CommandInfo const * InsetLabel::findInfo(string const & /* cmdName */) ParamInfo const & InsetLabel::findInfo(string const & /* cmdName */)
{ {
static const char * const paramnames[] = {"name", ""}; static ParamInfo param_info_;
static const bool isoptional[] = {false}; if (param_info_.empty()) {
static const CommandInfo info = {1, paramnames, isoptional}; param_info_.add("name", false);
return &info; }
return param_info_;
} }

View File

@ -36,15 +36,17 @@ public:
/// ///
int docbook(Buffer const &, odocstream &, OutputParams const &) const; int docbook(Buffer const &, odocstream &, OutputParams const &) const;
/// ///
static CommandInfo const * findInfo(std::string const &); static ParamInfo const & findInfo(std::string const &);
/// ///
static std::string defaultCommand() { return "label"; }; static std::string defaultCommand() { return "label"; };
/// ///
static bool isCompatibleCommand(std::string const & s) static bool isCompatibleCommand(std::string const & s)
{ return s == "label"; } { return s == "label"; }
protected: protected:
///
virtual void doDispatch(Cursor & cur, FuncRequest & cmd); virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
private: private:
///
virtual Inset * clone() const; virtual Inset * clone() const;
}; };

View File

@ -35,12 +35,15 @@ InsetNomencl::InsetNomencl(InsetCommandParams const & p)
{} {}
CommandInfo const * InsetNomencl::findInfo(string const & /* cmdName */) ParamInfo const & InsetNomencl::findInfo(string const & /* cmdName */)
{ {
static const char * const paramnames[] = {"prefix", "symbol", "description", ""}; static ParamInfo param_info_;
static const bool isoptional[] = {true, false, false}; if (param_info_.empty()) {
static const CommandInfo info = {3, paramnames, isoptional}; param_info_.add("prefix", true);
return &info; param_info_.add("symbol", false);
param_info_.add("description", false);
}
return param_info_;
} }
@ -85,12 +88,13 @@ InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p)
{} {}
CommandInfo const * InsetPrintNomencl::findInfo(string const & /* cmdName */) ParamInfo const & InsetPrintNomencl::findInfo(string const & /* cmdName */)
{ {
static const char * const paramnames[] = {"labelwidth", ""}; static ParamInfo param_info_;
static const bool isoptional[] = {true}; if (param_info_.empty()) {
static const CommandInfo info = {1, paramnames, isoptional}; param_info_.add("labelwidth", true);
return &info; }
return param_info_;
} }

View File

@ -41,7 +41,7 @@ public:
/// ///
int docbookGlossary(odocstream &) const; int docbookGlossary(odocstream &) const;
/// ///
static CommandInfo const * findInfo(std::string const &); static ParamInfo const & findInfo(std::string const &);
/// ///
static std::string defaultCommand() { return "nomenclature"; }; static std::string defaultCommand() { return "nomenclature"; };
/// ///
@ -78,7 +78,7 @@ public:
/// ///
docstring const getScreenLabel(Buffer const &) const; docstring const getScreenLabel(Buffer const &) const;
/// ///
static CommandInfo const * findInfo(std::string const &); static ParamInfo const & findInfo(std::string const &);
/// ///
static std::string defaultCommand() { return "printnomenclature"; }; static std::string defaultCommand() { return "printnomenclature"; };
/// ///

View File

@ -52,12 +52,14 @@ bool InsetRef::isCompatibleCommand(string const & s) {
} }
CommandInfo const * InsetRef::findInfo(string const & /* cmdName */) ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
{ {
static const char * const paramnames[] = {"name", "reference", ""}; static ParamInfo param_info_;
static const bool isoptional[] = {true, false}; if (param_info_.empty()) {
static const CommandInfo info = {2, paramnames, isoptional}; param_info_.add("name", true);
return &info; param_info_.add("reference", false);
}
return param_info_;
} }

View File

@ -57,7 +57,7 @@ public:
/// ///
void validate(LaTeXFeatures & features) const; void validate(LaTeXFeatures & features) const;
/// ///
static CommandInfo const * findInfo(std::string const &); static ParamInfo const & findInfo(std::string const &);
/// ///
static std::string defaultCommand() { return "ref"; }; static std::string defaultCommand() { return "ref"; };
/// ///

View File

@ -32,12 +32,13 @@ InsetTOC::InsetTOC(InsetCommandParams const & p)
{} {}
CommandInfo const * InsetTOC::findInfo(string const & /* cmdName */) ParamInfo const & InsetTOC::findInfo(string const & /* cmdName */)
{ {
static const char * const paramnames[] = {"type", ""}; static ParamInfo param_info_;
static const bool isoptional[] = {false}; if (param_info_.empty()) {
static const CommandInfo info = {1, paramnames, isoptional}; param_info_.add("type", false);
return &info; }
return param_info_;
} }

View File

@ -38,7 +38,7 @@ public:
int docbook(Buffer const &, odocstream &, int docbook(Buffer const &, odocstream &,
OutputParams const &) const; OutputParams const &) const;
/// ///
static CommandInfo const * findInfo(std::string const &); static ParamInfo const & findInfo(std::string const &);
/// ///
static std::string defaultCommand() { return "tableofcontents"; }; static std::string defaultCommand() { return "tableofcontents"; };
/// ///