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"
19 #include "support/docstring.h"
32 /// Types of parameters
34 LATEX_OPTIONAL, /// normal optional argument
35 LATEX_REQUIRED, /// normal required argument
36 LYX_INTERNAL /// a parameter used internally by LyX
40 // No parameter may be named "preview", because that is a required
41 // flag for all commands.
44 ParamData(std::string const &, ParamType);
46 std::string name() const { return name_; }
48 ParamType type() const { return type_; }
49 /// whether this is an optional LaTeX argument
50 bool isOptional() const;
52 bool operator==(ParamData const &) const;
54 bool operator!=(ParamData const & rhs) const
55 { return !(*this == rhs); }
63 /// adds a new parameter
64 void add(std::string const & name, ParamType type);
66 bool empty() const { return info_.empty(); }
68 size_t size() const { return info_.size(); }
70 typedef std::vector<ParamData>::const_iterator const_iterator;
72 const_iterator const begin() const { return info_.begin(); }
74 const_iterator const end() const { return info_.end(); }
75 /// \return true if name corresponds to a parameter of some sort.
76 /// \return false if the parameter does not exist at all of it it
77 bool hasParam(std::string const & name) const;
79 ParamData const & operator[](std::string const & name) const;
81 bool operator==(ParamInfo const &) const;
84 std::vector<ParamData> info_;
88 class InsetCommandParams {
90 /// Construct parameters for inset of type \p code.
91 explicit InsetCommandParams(InsetCode code);
92 /// Construct parameters for inset of type \p code with
93 /// command name \p cmdName.
94 explicit InsetCommandParams(InsetCode code,
95 std::string const & cmdName);
97 std::string insetType() const;
99 InsetCode code() const { return insetCode_; }
102 /// Parse the command
104 void write(std::ostream &) const;
105 /// Build the complete LaTeX command
106 docstring getCommand() const;
107 /// Return the command name
108 std::string const & getCmdName() const { return cmdName_; }
109 /// Set the name to \p n. This must be a known name. All parameters
110 /// are cleared except those that exist also in the new command.
111 /// What matters here is the parameter name, not position.
112 void setCmdName(std::string const & n);
113 /// FIXME Would be better removed, but is used in BufferView.cpp in
114 /// ways that make removal hard.
115 docstring getFirstNonOptParam() const;
116 /// get parameter \p name
117 /// LyX will assert if name is not a valid parameter.
118 docstring const & operator[](std::string const & name) const;
119 /// set parameter \p name
120 /// LyX will assert if name is not a valid parameter.
121 docstring & operator[](std::string const & name);
123 bool preview() const { return preview_; }
125 void preview(bool p) { preview_ = p; }
126 /// Clear the values of all parameters
129 static bool isCompatibleCommand(InsetCode code, std::string const & s);
132 std::string getDefaultCmd(InsetCode code);
133 /// checks whether we need to write an empty optional parameter
134 /// \return true if a non-empty optional parameter follows ci
135 bool writeEmptyOptional(ParamInfo::const_iterator ci) const;
137 /// Description of all command properties
139 /// what kind of inset we're the parameters for
140 InsetCode insetCode_;
141 /// The name of this command as it appears in .lyx and .tex files
142 std::string cmdName_;
144 // if we need to allow more than one value for a parameter, this
145 // could be made a multimap. it may be that the only thing that
146 // would then need changing is operator[].
147 typedef std::map<std::string, docstring> ParamMap;
148 /// The parameters, by name.
153 friend bool operator==(InsetCommandParams const &,
154 InsetCommandParams const &);
158 bool operator==(InsetCommandParams const &, InsetCommandParams const &);
160 bool operator!=(InsetCommandParams const &, InsetCommandParams const &);