]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCommandParams.h
f02d2a6ebd195a17bc8e9529e5c55da5b32910f0
[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 "support/docstring.h"
17
18 #include <iosfwd>
19 #include <vector>
20
21
22 namespace lyx {
23
24 class Lexer;
25
26 class InsetCommandParams {
27 public:
28         /// Construct parameters for inset \p insetType, using
29         /// \p insetType as default for \p cmdName_.
30         explicit InsetCommandParams(std::string const & insetType);
31         /// Construct parameters for inset \p insetType with
32         /// command name \p cmdName.
33         explicit InsetCommandParams(std::string const & insetType,
34                         std::string const & cmdName);
35         ///
36         std::string insetType() { return insetType_; }
37         ///
38         void read(Lexer &);
39         /// Parse the command
40         /// FIXME remove
41         void scanCommand(std::string const &);
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         /// this is used by listings package.
49         std::string const getOptions() const;
50         /// FIXME remove
51         std::string const getContents() const;
52         /// Set the name to \p n. This must be a known name. All parameters
53         /// are cleared except those that exist also in the new command.
54         /// What matters here is the parameter name, not position.
55         void setCmdName(std::string const & n);
56         /// this is used by the listings package
57         void setOptions(std::string const &);
58         /// FIXME remove
59         void setContents(std::string const &);
60         /// get parameter \p name
61         docstring const & operator[](std::string const & name) const;
62         /// set parameter \p name
63         docstring & operator[](std::string const & name);
64         ///
65         bool preview() const { return preview_; }
66         ///
67         void preview(bool p) { preview_ = p; }
68         /// Clear the values of all parameters
69         void clear();
70
71 private:
72         /// FIXME remove
73         std::string const getSecOptions() const;
74         /// FIXME remove
75         void setSecOptions(std::string const &);
76         ///
77         struct CommandInfo {
78                 /// Number of parameters
79                 size_t n;
80                 /// Parameter names. paramnames[n] must be "".
81                 char const * const * paramnames;
82                 /// Tells whether a parameter is optional
83                 bool const * optional;
84         };
85         /// Get information for inset type \p insetType.
86         /// Returns 0 if the inset is not known.
87         static CommandInfo const * findInfo(std::string const & insetType);
88         /// Get information for \p insetType and command \p cmdName.
89         /// Returns 0 if the combination is not known.
90         /// Don't call this without first making sure the command name is
91         /// acceptable to the inset.
92         static CommandInfo const * findInfo(std::string const & insetType,
93                                             std::string const & cmdName);
94         ///
95         std::string getDefaultCmd(std::string insetType);
96         /// Description of all command properties
97         CommandInfo const * info_;
98         /// what kind of inset we're the parameters for
99         std::string insetType_;
100         /// The name of this command as it appears in .lyx and .tex files
101         std::string cmdName_;
102         ///
103         typedef std::vector<docstring> ParamVector;
104         /// The parameters (both optional and required ones). The order is
105         /// the same that is required for LaTeX output. The size of params_
106         /// is always info_->n.
107         ParamVector params_;
108         ///
109         bool preview_;
110         ///
111         friend bool operator==(InsetCommandParams const &,
112                         InsetCommandParams const &);
113 };
114
115
116 ///
117 bool operator==(InsetCommandParams const &, InsetCommandParams const &);
118
119 ///
120 bool operator!=(InsetCommandParams const &, InsetCommandParams const &);
121
122
123 } // namespace lyx
124
125 #endif