3 * \file InsetCommandParams.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
11 * Full author contact details are available in file CREDITS.
14 #ifndef INSETCOMMANDPARAMS_H
15 #define INSETCOMMANDPARAMS_H
17 #include "InsetCode.h"
18 #include "support/docstring.h"
30 // No parameter may be named "preview", because that is a required
31 // flag for all commands.
33 /// Number of parameters
35 /// Parameter names. paramnames[n] must be "".
36 char const * const * paramnames;
37 /// Tells whether a parameter is optional
38 bool const * optional;
42 class InsetCommandParams {
44 /// Construct parameters for inset of type \p code.
45 explicit InsetCommandParams(InsetCode code);
46 /// Construct parameters for inset of type \p code with
47 /// command name \p cmdName.
48 explicit InsetCommandParams(InsetCode code,
49 std::string const & cmdName);
51 std::string insetType() const { return insetName(insetCode_); }
53 InsetCode code() const { return insetCode_; }
58 void write(std::ostream &) const;
59 /// Build the complete LaTeX command
60 docstring const getCommand() const;
61 /// Return the command name
62 std::string const & getCmdName() const { return cmdName_; }
63 /// Set the name to \p n. This must be a known name. All parameters
64 /// are cleared except those that exist also in the new command.
65 /// What matters here is the parameter name, not position.
66 void setCmdName(std::string const & n);
67 /// FIXME Would be better removed, but is used in BufferView.cpp in
68 /// ways that make removal hard.
69 docstring const getFirstNonOptParam() const;
70 /// get parameter \p name
71 docstring const & operator[](std::string const & name) const;
72 /// set parameter \p name
73 docstring & operator[](std::string const & name);
75 bool preview() const { return preview_; }
77 void preview(bool p) { preview_ = p; }
78 /// Clear the values of all parameters
83 /// Get information for inset type \p code.
84 /// Returns 0 if the inset is not known.
85 static CommandInfo const * findInfo(InsetCode code);
86 /// Get information for \p code and command \p cmdName.
87 /// Returns 0 if the combination is not known.
88 /// Don't call this without first making sure the command name is
89 /// acceptable to the inset.
90 static CommandInfo const * findInfo(InsetCode code,
91 std::string const & cmdName);
93 static bool isCompatibleCommand(InsetCode code, std::string const & s);
95 std::string getDefaultCmd(InsetCode);
96 /// Description of all command properties
97 CommandInfo const * info_;
98 /// what kind of inset we're the parameters for
100 /// The name of this command as it appears in .lyx and .tex files
101 std::string cmdName_;
103 typedef std::vector<docstring> ParamVector;
104 /// The parameters (both optional and required ones). The order is
105 /// the same that is required for LaTeX output. The size of params_
106 /// is always info_->n.
111 friend bool operator==(InsetCommandParams const &,
112 InsetCommandParams const &);
117 bool operator==(InsetCommandParams const &, InsetCommandParams const &);
120 bool operator!=(InsetCommandParams const &, InsetCommandParams const &);