#define INSETCOMMANDPARAMS_H
#include "InsetCode.h"
+
#include "support/docstring.h"
-#include <iosfwd>
-#include <list>
#include <string>
#include <vector>
+#include <map>
namespace lyx {
class Lexer;
-// No parameter may be named "preview", because that is a required
-// flag for all commands.
-struct CommandInfo {
- /// Number of parameters
- size_t n;
- /// Parameter names. paramnames[n] must be "".
- char const * const * paramnames;
- /// Tells whether a parameter is optional
- bool const * optional;
-};
-
-///
-struct ICPInfo {
+class ParamInfo {
+public:
+ /// Types of parameters
+ enum ParamType {
+ LATEX_OPTIONAL, /// normal optional argument
+ LATEX_REQUIRED, /// normal required argument
+ LYX_INTERNAL /// a parameter used internally by LyX
+ };
///
- ICPInfo(std::string const & s, bool b);
- /// Parameter name.
- std::string paramName;
- /// Whether it is optional.
- bool optional;
-};
-///
-typedef std::list<ICPInfo> PList;
-///
-class ICPList {
+ class ParamData {
+ // No parameter may be named "preview", because that is a required
+ // flag for all commands.
public:
///
- PList::const_iterator begin() { return plist_.begin(); }
+ ParamData(std::string const &, ParamType);
///
- PList::const_iterator end() { return plist_.end(); }
+ std::string name() const { return name_; }
///
- void clear() { plist_.clear(); }
+ ParamType type() const { return type_; }
+ /// whether this is an optional LaTeX argument
+ bool isOptional() const;
///
- void addParam(std::string const & s, bool b = false);
- ///
- bool hasParam(std::string const & s);
+ bool operator==(ParamData const &) const;
+ ///
+ bool operator!=(ParamData const & rhs) const
+ { return !(*this == rhs); }
private:
///
- PList plist_;
-
+ std::string name_;
+ ///
+ ParamType type_;
+ };
+
+ /// adds a new parameter
+ void add(std::string const & name, ParamType type);
+ ///
+ bool empty() const { return info_.empty(); }
+ ///
+ size_t size() const { return info_.size(); }
+ ///
+ typedef std::vector<ParamData>::const_iterator const_iterator;
+ ///
+ const_iterator const begin() const { return info_.begin(); }
+ ///
+ const_iterator const end() const { return info_.end(); }
+ /// \return true if name corresponds to a parameter of some sort.
+ /// \return false if the parameter does not exist at all of it it
+ bool hasParam(std::string const & name) const;
+ ///
+ ParamData const & operator[](std::string const & name) const;
+ ///
+ bool operator==(ParamInfo const &) const;
+private:
+ ///
+ std::vector<ParamData> info_;
};
explicit InsetCommandParams(InsetCode code,
std::string const & cmdName);
///
- std::string insetType() const { return insetName(insetCode_); }
+ std::string insetType() const;
///
InsetCode code() const { return insetCode_; }
///
///
void write(std::ostream &) const;
/// Build the complete LaTeX command
- docstring const getCommand() const;
+ docstring getCommand() const;
/// Return the command name
std::string const & getCmdName() const { return cmdName_; }
/// Set the name to \p n. This must be a known name. All parameters
void setCmdName(std::string const & n);
/// FIXME Would be better removed, but is used in BufferView.cpp in
/// ways that make removal hard.
- docstring const getFirstNonOptParam() const;
+ docstring getFirstNonOptParam() const;
/// get parameter \p name
+ /// LyX will assert if name is not a valid parameter.
docstring const & operator[](std::string const & name) const;
/// set parameter \p name
+ /// LyX will assert if name is not a valid parameter.
docstring & operator[](std::string const & name);
///
bool preview() const { return preview_; }
void preview(bool p) { preview_ = p; }
/// Clear the values of all parameters
void clear();
-
-private:
- ///
- /// Get information for inset type \p code.
- /// Returns 0 if the inset is not known.
- static CommandInfo const * findInfo(InsetCode code);
- /// Get information for \p code and command \p cmdName.
- /// Returns 0 if the combination is not known.
- /// Don't call this without first making sure the command name is
- /// acceptable to the inset.
- static CommandInfo const * findInfo(InsetCode code,
- std::string const & cmdName);
///
static bool isCompatibleCommand(InsetCode code, std::string const & s);
- ///
- std::string getDefaultCmd(InsetCode);
+
+private:
+ std::string getDefaultCmd(InsetCode code);
+ /// checks whether we need to write an empty optional parameter
+ /// \return true if a non-empty optional parameter follows ci
+ bool writeEmptyOptional(ParamInfo::const_iterator ci) const;
+
/// Description of all command properties
- CommandInfo const * info_;
+ ParamInfo info_;
/// what kind of inset we're the parameters for
InsetCode insetCode_;
/// The name of this command as it appears in .lyx and .tex files
std::string cmdName_;
///
- typedef std::vector<docstring> ParamVector;
- /// The parameters (both optional and required ones). The order is
- /// the same that is required for LaTeX output. The size of params_
- /// is always info_->n.
- ParamVector params_;
+ // if we need to allow more than one value for a parameter, this
+ // could be made a multimap. it may be that the only thing that
+ // would then need changing is operator[].
+ typedef std::map<std::string, docstring> ParamMap;
+ /// The parameters, by name.
+ ParamMap params_;
///
bool preview_;
///
InsetCommandParams const &);
};
-
///
bool operator==(InsetCommandParams const &, InsetCommandParams const &);
-
///
bool operator!=(InsetCommandParams const &, InsetCommandParams const &);