]> git.lyx.org Git - lyx.git/blob - src/insets/insetcommandparams.h
3b26fbce7c962b1ba822343c61b51dc041166129
[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 class LyXLex;
23
24
25 class InsetCommandParams {
26 public:
27         /// Construct parameters for command \p name. \p name must be known.
28         explicit InsetCommandParams(std::string const & name);
29         ///
30         void read(LyXLex &);
31         /// Parse the command
32         /// FIXME remove
33         void scanCommand(std::string const &);
34         ///
35         void write(std::ostream &) const;
36         /// Build the complete LaTeX command
37         lyx::docstring const getCommand() const;
38         /// Return the command name
39         std::string const & getCmdName() const { return name_; }
40         /// FIXME remove
41         std::string const getOptions() const;
42         /// FIXME remove
43         std::string const getSecOptions() const;
44         /// FIXME remove
45         std::string const getContents() const;
46         /// Set the name to \p n. This must be a known name. All parameters
47         /// are cleared except those that exist also in the new command.
48         /// What matters here is the parameter name, not position.
49         void setCmdName(std::string const & n);
50         /// FIXME remove
51         void setOptions(std::string const &);
52         /// FIXME remove
53         void setSecOptions(std::string const &);
54         /// FIXME remove
55         void setContents(std::string const &);
56         /// get parameter \p name
57         lyx::docstring const & operator[](std::string const & name) const;
58         /// set parameter \p name
59         lyx::docstring & operator[](std::string const & name);
60         ///
61         bool preview() const { return preview_; }
62         ///
63         void preview(bool p) { preview_ = p; }
64         /// Clear the values of all parameters
65         void clear();
66
67 private:
68         ///
69         struct CommandInfo {
70                 /// Number of parameters
71                 size_t n;
72                 /// Parameter names. paramnames[n] must be "".
73                 char const * const * paramnames;
74                 /// Tells whether a parameter is optional
75                 bool const * optional;
76         };
77         /// Get information for command \p name.
78         /// Returns 0 if the command is not known.
79         static CommandInfo const * findInfo(std::string const & name);
80         /// Description of all command properties
81         CommandInfo const * info_;
82         /// The name of this command as it appears in .lyx and .tex files
83         std::string name_;
84         ///
85         typedef std::vector<lyx::docstring> ParamVector;
86         /// The parameters (both optional and required ones). The order is
87         /// the same that is required for LaTeX output. The size of params_
88         /// is always info_->n.
89         ParamVector params_;
90         ///
91         bool preview_;
92         ///
93         friend bool operator==(InsetCommandParams const &,
94                         InsetCommandParams const &);
95 };
96
97
98 ///
99 bool operator==(InsetCommandParams const &, InsetCommandParams const &);
100
101 ///
102 bool operator!=(InsetCommandParams const &, InsetCommandParams const &);
103
104 #endif