]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCommandParams.h
a5dd8c462f85b8b2d2ac0112a3ded088927599dc
[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         /// FIXME remove
43         void scanCommand(std::string const &);
44         ///
45         void write(std::ostream &) const;
46         /// Build the complete LaTeX command
47         docstring const getCommand() const;
48         /// Return the command name
49         std::string const & getCmdName() const { return cmdName_; }
50         /// this is used by listings package.
51         std::string const getOptions() const;
52         /// FIXME remove
53         std::string const getContents() const;
54         /// Set the name to \p n. This must be a known name. All parameters
55         /// are cleared except those that exist also in the new command.
56         /// What matters here is the parameter name, not position.
57         void setCmdName(std::string const & n);
58         /// this is used by the listings package
59         void setOptions(std::string const &);
60         /// FIXME remove
61         void setContents(std::string const &);
62         /// get parameter \p name
63         docstring const & operator[](std::string const & name) const;
64         /// set parameter \p name
65         docstring & operator[](std::string const & name);
66         ///
67         bool preview() const { return preview_; }
68         ///
69         void preview(bool p) { preview_ = p; }
70         /// Clear the values of all parameters
71         void clear();
72
73 private:
74         /// FIXME remove
75         std::string const getSecOptions() const;
76         /// FIXME remove
77         void setSecOptions(std::string const &);
78         ///
79         struct CommandInfo {
80                 /// Number of parameters
81                 size_t n;
82                 /// Parameter names. paramnames[n] must be "".
83                 char const * const * paramnames;
84                 /// Tells whether a parameter is optional
85                 bool const * optional;
86         };
87         /// Get information for inset type \p code.
88         /// Returns 0 if the inset is not known.
89         static CommandInfo const * findInfo(InsetCode code);
90         /// Get information for \p code and command \p cmdName.
91         /// Returns 0 if the combination is not known.
92         /// Don't call this without first making sure the command name is
93         /// acceptable to the inset.
94         static CommandInfo const * findInfo(InsetCode code,
95                                             std::string const & cmdName);
96         ///
97         std::string getDefaultCmd(InsetCode);
98         /// Description of all command properties
99         CommandInfo const * info_;
100         /// what kind of inset we're the parameters for
101         InsetCode insetCode_;
102         /// The name of this command as it appears in .lyx and .tex files
103         std::string cmdName_;
104         ///
105         typedef std::vector<docstring> ParamVector;
106         /// The parameters (both optional and required ones). The order is
107         /// the same that is required for LaTeX output. The size of params_
108         /// is always info_->n.
109         ParamVector params_;
110         ///
111         bool preview_;
112         ///
113         friend bool operator==(InsetCommandParams const &,
114                         InsetCommandParams const &);
115 };
116
117
118 ///
119 bool operator==(InsetCommandParams const &, InsetCommandParams const &);
120
121 ///
122 bool operator!=(InsetCommandParams const &, InsetCommandParams const &);
123
124
125 } // namespace lyx
126
127 #endif