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