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"
34 // No parameter may be named "preview", because that is a required
35 // flag for all commands.
38 ParamData(std::string const &, bool);
40 std::string name() const { return name_; }
42 bool isOptional() const { return optional_; }
44 bool operator==(ParamData const &) const;
46 bool operator!=(ParamData const & rhs) const
47 { return !(*this == rhs); }
55 /// adds a new parameter
56 void add(std::string const & name, bool optional);
58 bool empty() const { return info_.empty(); }
60 size_t size() const { return info_.size(); }
62 typedef std::vector<ParamData>::const_iterator const_iterator;
64 const_iterator begin() const { return info_.begin(); }
66 const_iterator end() const { return info_.end(); }
68 bool hasParam(std::string const & name) const;
70 bool operator==(ParamInfo const &) const;
73 std::vector<ParamData> info_;
77 class InsetCommandParams {
79 /// Construct parameters for inset of type \p code.
80 explicit InsetCommandParams(InsetCode code);
81 /// Construct parameters for inset of type \p code with
82 /// command name \p cmdName.
83 explicit InsetCommandParams(InsetCode code,
84 std::string const & cmdName);
86 std::string insetType() const { return insetName(insetCode_); }
88 InsetCode code() const { return insetCode_; }
93 void write(std::ostream &) const;
94 /// Build the complete LaTeX command
95 docstring const getCommand() const;
96 /// Return the command name
97 std::string const & getCmdName() const { return cmdName_; }
98 /// Set the name to \p n. This must be a known name. All parameters
99 /// are cleared except those that exist also in the new command.
100 /// What matters here is the parameter name, not position.
101 void setCmdName(std::string const & n);
102 /// FIXME Would be better removed, but is used in BufferView.cpp in
103 /// ways that make removal hard.
104 docstring const getFirstNonOptParam() const;
105 /// get parameter \p name
106 docstring const & operator[](std::string const & name) const;
107 /// set parameter \p name
108 docstring & operator[](std::string const & name);
110 bool preview() const { return preview_; }
112 void preview(bool p) { preview_ = p; }
113 /// Clear the values of all parameters
118 /// Get information for inset type \p code.
119 /// Returns 0 if the inset is not known.
120 static ParamInfo const & findInfo(InsetCode code);
121 /// Get information for \p code and command \p cmdName.
122 /// Returns 0 if the combination is not known.
123 /// Don't call this without first making sure the command name is
124 /// acceptable to the inset.
125 static ParamInfo const & findInfo(InsetCode code,
126 std::string const & cmdName);
128 static bool isCompatibleCommand(InsetCode code, std::string const & s);
130 std::string getDefaultCmd(InsetCode);
131 /// Description of all command properties
133 /// what kind of inset we're the parameters for
134 InsetCode insetCode_;
135 /// The name of this command as it appears in .lyx and .tex files
136 std::string cmdName_;
138 typedef std::map<std::string, docstring> ParamMap;
139 /// The parameters, by name.
144 friend bool operator==(InsetCommandParams const &,
145 InsetCommandParams const &);
149 bool operator==(InsetCommandParams const &, InsetCommandParams const &);
151 bool operator!=(InsetCommandParams const &, InsetCommandParams const &);