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
10 * Full author contact details are available in file CREDITS.
13 #ifndef INSETCOMMANDPARAMS_H
14 #define INSETCOMMANDPARAMS_H
16 #include "InsetCode.h"
17 #include "support/docstring.h"
27 class InsetCommandParams {
29 /// Construct parameters for inset of type \p code.
30 explicit InsetCommandParams(InsetCode code);
31 /// Construct parameters for inset of type \p code with
32 /// command name \p cmdName.
33 explicit InsetCommandParams(InsetCode code,
34 std::string const & cmdName);
36 std::string insetType() const { return insetName(insetCode_); }
38 InsetCode code() const { return insetCode_; }
43 void scanCommand(std::string const &);
45 void write(std::ostream &) const;
46 /// Build the complete LaTeX command
47 docstring const getCommand() const;
48 /// Return the command name
49 std::string const & getCmdName() const { return cmdName_; }
50 /// this is used by listings package.
51 std::string const getOptions() const;
53 std::string const getContents() const;
54 /// Set the name to \p n. This must be a known name. All parameters
55 /// are cleared except those that exist also in the new command.
56 /// What matters here is the parameter name, not position.
57 void setCmdName(std::string const & n);
58 /// this is used by the listings package
59 void setOptions(std::string const &);
61 void setContents(std::string const &);
62 /// get parameter \p name
63 docstring const & operator[](std::string const & name) const;
64 /// set parameter \p name
65 docstring & operator[](std::string const & name);
67 bool preview() const { return preview_; }
69 void preview(bool p) { preview_ = p; }
70 /// Clear the values of all parameters
75 std::string const getSecOptions() const;
77 void setSecOptions(std::string const &);
80 /// Number of parameters
82 /// Parameter names. paramnames[n] must be "".
83 char const * const * paramnames;
84 /// Tells whether a parameter is optional
85 bool const * optional;
87 /// Get information for inset type \p code.
88 /// Returns 0 if the inset is not known.
89 static CommandInfo const * findInfo(InsetCode code);
90 /// Get information for \p code and command \p cmdName.
91 /// Returns 0 if the combination is not known.
92 /// Don't call this without first making sure the command name is
93 /// acceptable to the inset.
94 static CommandInfo const * findInfo(InsetCode code,
95 std::string const & cmdName);
97 std::string getDefaultCmd(InsetCode);
98 /// Description of all command properties
99 CommandInfo const * info_;
100 /// what kind of inset we're the parameters for
101 InsetCode insetCode_;
102 /// The name of this command as it appears in .lyx and .tex files
103 std::string cmdName_;
105 typedef std::vector<docstring> ParamVector;
106 /// The parameters (both optional and required ones). The order is
107 /// the same that is required for LaTeX output. The size of params_
108 /// is always info_->n.
113 friend bool operator==(InsetCommandParams const &,
114 InsetCommandParams const &);
119 bool operator==(InsetCommandParams const &, InsetCommandParams const &);
122 bool operator!=(InsetCommandParams const &, InsetCommandParams const &);