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;
44 ICPInfo(std::string const & s, bool b);
46 std::string paramName;
47 /// Whether it is optional.
51 typedef std::list<ICPInfo> PList;
56 PList::const_iterator begin() { return plist_.begin(); }
58 PList::const_iterator end() { return plist_.end(); }
60 void clear() { plist_.clear(); }
62 void addParam(std::string const & s, bool b = false);
64 bool hasParam(std::string const & s);
72 class InsetCommandParams {
74 /// Construct parameters for inset of type \p code.
75 explicit InsetCommandParams(InsetCode code);
76 /// Construct parameters for inset of type \p code with
77 /// command name \p cmdName.
78 explicit InsetCommandParams(InsetCode code,
79 std::string const & cmdName);
81 std::string insetType() const { return insetName(insetCode_); }
83 InsetCode code() const { return insetCode_; }
88 void write(std::ostream &) const;
89 /// Build the complete LaTeX command
90 docstring const getCommand() const;
91 /// Return the command name
92 std::string const & getCmdName() const { return cmdName_; }
93 /// Set the name to \p n. This must be a known name. All parameters
94 /// are cleared except those that exist also in the new command.
95 /// What matters here is the parameter name, not position.
96 void setCmdName(std::string const & n);
97 /// FIXME Would be better removed, but is used in BufferView.cpp in
98 /// ways that make removal hard.
99 docstring const getFirstNonOptParam() const;
100 /// get parameter \p name
101 docstring const & operator[](std::string const & name) const;
102 /// set parameter \p name
103 docstring & operator[](std::string const & name);
105 bool preview() const { return preview_; }
107 void preview(bool p) { preview_ = p; }
108 /// Clear the values of all parameters
113 /// Get information for inset type \p code.
114 /// Returns 0 if the inset is not known.
115 static CommandInfo const * findInfo(InsetCode code);
116 /// Get information for \p code and command \p cmdName.
117 /// Returns 0 if the combination is not known.
118 /// Don't call this without first making sure the command name is
119 /// acceptable to the inset.
120 static CommandInfo const * findInfo(InsetCode code,
121 std::string const & cmdName);
123 static bool isCompatibleCommand(InsetCode code, std::string const & s);
125 std::string getDefaultCmd(InsetCode);
126 /// Description of all command properties
127 CommandInfo const * info_;
128 /// what kind of inset we're the parameters for
129 InsetCode insetCode_;
130 /// The name of this command as it appears in .lyx and .tex files
131 std::string cmdName_;
133 typedef std::vector<docstring> ParamVector;
134 /// The parameters (both optional and required ones). The order is
135 /// the same that is required for LaTeX output. The size of params_
136 /// is always info_->n.
141 friend bool operator==(InsetCommandParams const &,
142 InsetCommandParams const &);
147 bool operator==(InsetCommandParams const &, InsetCommandParams const &);
150 bool operator!=(InsetCommandParams const &, InsetCommandParams const &);