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