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"
29 // No parameter may be named "preview", because that is a required
30 // flag for all commands.
32 /// Number of parameters
34 /// Parameter names. paramnames[n] must be "".
35 char const * const * paramnames;
36 /// Tells whether a parameter is optional
37 bool const * optional;
41 class InsetCommandParams {
43 /// Construct parameters for inset of type \p code.
44 explicit InsetCommandParams(InsetCode code);
45 /// Construct parameters for inset of type \p code with
46 /// command name \p cmdName.
47 explicit InsetCommandParams(InsetCode code,
48 std::string const & cmdName);
50 std::string insetType() const { return insetName(insetCode_); }
52 InsetCode code() const { return insetCode_; }
57 void write(std::ostream &) const;
58 /// Build the complete LaTeX command
59 docstring const getCommand() const;
60 /// Return the command name
61 std::string const & getCmdName() const { return cmdName_; }
62 /// Set the name to \p n. This must be a known name. All parameters
63 /// are cleared except those that exist also in the new command.
64 /// What matters here is the parameter name, not position.
65 void setCmdName(std::string const & n);
66 /// FIXME Would be better removed, but is used in BufferView.cpp in
67 /// ways that make removal hard.
68 docstring const getFirstNonOptParam() const;
69 /// get parameter \p name
70 docstring const & operator[](std::string const & name) const;
71 /// set parameter \p name
72 docstring & operator[](std::string const & name);
74 bool preview() const { return preview_; }
76 void preview(bool p) { preview_ = p; }
77 /// Clear the values of all parameters
82 /// Get information for inset type \p code.
83 /// Returns 0 if the inset is not known.
84 static CommandInfo const * findInfo(InsetCode code);
85 /// Get information for \p code and command \p cmdName.
86 /// Returns 0 if the combination is not known.
87 /// Don't call this without first making sure the command name is
88 /// acceptable to the inset.
89 static CommandInfo const * findInfo(InsetCode code,
90 std::string const & cmdName);
92 static bool isCompatibleCommand(InsetCode code, std::string const & s);
94 std::string getDefaultCmd(InsetCode);
95 /// Description of all command properties
96 CommandInfo const * info_;
97 /// what kind of inset we're the parameters for
99 /// The name of this command as it appears in .lyx and .tex files
100 std::string cmdName_;
102 typedef std::vector<docstring> ParamVector;
103 /// The parameters (both optional and required ones). The order is
104 /// the same that is required for LaTeX output. The size of params_
105 /// is always info_->n.
110 friend bool operator==(InsetCommandParams const &,
111 InsetCommandParams const &);
116 bool operator==(InsetCommandParams const &, InsetCommandParams const &);
119 bool operator!=(InsetCommandParams const &, InsetCommandParams const &);