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