4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Stefan Schimanski
10 * Full author contact details are available in file CREDITS.
13 #ifndef MATH_MACROTABLE_H
14 #define MATH_MACROTABLE_H
16 #include "support/docstring.h"
33 MacroData(docstring const & definition,
34 std::vector<docstring> const & defaults, int nargs, int optionals,
35 docstring const & display, std::string const & requires);
37 docstring const & definition() const { return definition_; }
39 docstring const & display() const { return display_; }
40 /// arity including optional arguments (if there is any)
41 size_t numargs() const { return numargs_; }
42 /// replace #1,#2,... by given MathAtom 0,1,.., _including_ the possible
44 void expand(std::vector<MathData> const & from, MathData & to) const;
45 /// number of optional arguments
46 size_t optionals() const;
48 std::vector<docstring> const & defaults() const;
50 std::string requires() const { return requires_; }
52 std::string & requires() { return requires_; }
54 /// lock while being drawn to avoid recursions
55 int lock() const { return ++lockCount_; }
56 /// is it being drawn?
57 bool locked() const { return lockCount_ != 0; }
62 bool redefinition() const { return redefinition_; }
64 void setRedefinition(bool redefined) { redefinition_ = redefined; }
67 bool operator==(MacroData const & x) const {
68 return definition_ == x.definition_
69 && numargs_ == x.numargs_
70 && display_ == x.display_
71 && requires_ == x.requires_
72 && optionals_ == x.optionals_
73 && defaults_ == x.defaults_;
76 bool operator!=(MacroData const & x) const { return !operator==(x); }
80 docstring definition_;
86 std::string requires_;
88 mutable int lockCount_;
94 std::vector<docstring> defaults_;
98 /// A lookup table of macro definitions.
100 * This contains a table of "global" macros that are always accessible,
101 * either because they implement a feature of standard LaTeX or some
102 * hack to display certain contents nicely.
105 class MacroTable : public std::map<docstring, MacroData>
108 /// Parse full "\\def..." or "\\newcommand..." or ...
109 void insert(docstring const & definition, std::string const &);
110 /// Insert pre-digested macro definition
111 void insert(docstring const & name, MacroData const & data);
112 /// Do we have a macro by that name?
113 bool has(docstring const & name) const;
115 MacroData const & get(docstring const & name) const;
120 static MacroTable & globalMacros();
124 /// A context to lookup macros at a certain position in a buffer.
126 * The MacroContext is used during metrics calculation to resolve
127 * macro instances according to the position of them in the buffer
128 * document. Only macro definition in front of the macro instance
129 * are visible and are resolved.
134 /// construct context for insets in par (not including the ones
135 /// defined in par itself)
136 MacroContext(Buffer const & buf, Paragraph const & par);
139 bool has(docstring const & name) const;
141 MacroData const & get(docstring const & name) const;
143 /// Insert pre-digested macro definition
144 void insert(docstring const & name, MacroData const & data);
147 /// context local macros
152 Paragraph const & par_;