]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCommandParams.h
This should be the last of the commits refactoring the InsetLayout code.
[lyx.git] / src / insets / InsetCommandParams.h
1 // -*- C++ -*-
2 /**
3  * \file InsetCommandParams.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  * \author Georg Baum
9  * \author Richard Heck
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef INSETCOMMANDPARAMS_H
15 #define INSETCOMMANDPARAMS_H
16
17 #include "InsetCode.h"
18 #include "support/docstring.h"
19
20 #include <iosfwd>
21 #include <string>
22 #include <vector>
23
24
25 namespace lyx {
26
27 class Lexer;
28
29 // No parameter may be named "preview", because that is a required
30 // flag for all commands.
31 struct CommandInfo {
32         /// Number of parameters
33         size_t n;
34         /// Parameter names. paramnames[n] must be "".
35         char const * const * paramnames;
36         /// Tells whether a parameter is optional
37         bool const * optional;
38 };
39
40
41 class InsetCommandParams {
42 public:
43         /// Construct parameters for inset of type \p code.
44         explicit InsetCommandParams(InsetCode code);
45         /// Construct parameters for inset of type \p code with
46         /// command name \p cmdName.
47         explicit InsetCommandParams(InsetCode code,
48                         std::string const & cmdName);
49         ///
50         std::string insetType() const { return insetName(insetCode_); }
51         ///
52         InsetCode code() const { return insetCode_; }
53         ///
54         void read(Lexer &);
55         /// Parse the command
56         ///
57         void write(std::ostream &) const;
58         /// Build the complete LaTeX command
59         docstring const getCommand() const;
60         /// Return the command name
61         std::string const & getCmdName() const { return cmdName_; }
62         /// Set the name to \p n. This must be a known name. All parameters
63         /// are cleared except those that exist also in the new command.
64         /// What matters here is the parameter name, not position.
65         void setCmdName(std::string const & n);
66         /// FIXME Would be better removed, but is used in BufferView.cpp in 
67         /// ways that make removal hard.
68         docstring const getFirstNonOptParam() const;
69         /// get parameter \p name
70         docstring const & operator[](std::string const & name) const;
71         /// set parameter \p name
72         docstring & operator[](std::string const & name);
73         ///
74         bool preview() const { return preview_; }
75         ///
76         void preview(bool p) { preview_ = p; }
77         /// Clear the values of all parameters
78         void clear();
79
80 private:
81         ///
82         /// Get information for inset type \p code.
83         /// Returns 0 if the inset is not known.
84         static CommandInfo const * findInfo(InsetCode code);
85         /// Get information for \p code and command \p cmdName.
86         /// Returns 0 if the combination is not known.
87         /// Don't call this without first making sure the command name is
88         /// acceptable to the inset.
89         static CommandInfo const * findInfo(InsetCode code,
90                                             std::string const & cmdName);
91         ///
92         static bool isCompatibleCommand(InsetCode code, std::string const & s);
93         ///
94         std::string getDefaultCmd(InsetCode);
95         /// Description of all command properties
96         CommandInfo const * info_;
97         /// what kind of inset we're the parameters for
98         InsetCode insetCode_;
99         /// The name of this command as it appears in .lyx and .tex files
100         std::string cmdName_;
101         ///
102         typedef std::vector<docstring> ParamVector;
103         /// The parameters (both optional and required ones). The order is
104         /// the same that is required for LaTeX output. The size of params_
105         /// is always info_->n.
106         ParamVector params_;
107         ///
108         bool preview_;
109         ///
110         friend bool operator==(InsetCommandParams const &,
111                         InsetCommandParams const &);
112 };
113
114
115 ///
116 bool operator==(InsetCommandParams const &, InsetCommandParams const &);
117
118 ///
119 bool operator!=(InsetCommandParams const &, InsetCommandParams const &);
120
121
122 } // namespace lyx
123
124 #endif