4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef MATH_MACROTABLE_H
13 #define MATH_MACROTABLE_H
15 #include "support/docstring.h"
17 #include <boost/assert.hpp>
32 MacroData(docstring const & def, int nargs, docstring const & disp, std::string const &);
34 docstring def() const { return def_; }
36 docstring disp() const { return disp_; }
38 int numargs() const { return numargs_; }
39 /// replace #1,#2,... by given MathAtom 0,1,..
40 void expand(std::vector<MathData> const & from, MathData & to) const;
42 std::string requires() const { return requires_; }
44 std::string & requires() { return requires_; }
45 /// lock while being drawn
46 int lock() const { return ++lockCount_; }
47 /// is it being drawn?
48 bool locked() const { return lockCount_ != 0; }
50 void unlock() const { --lockCount_; BOOST_ASSERT(lockCount_ >= 0); }
53 bool operator==(MacroData const & x) const {
54 return def_ == x.def_ &&
55 numargs_ == x.numargs_ &&
57 requires_ == x.requires_;
60 bool operator!=(MacroData const & x) const { return !operator==(x); }
70 std::string requires_;
72 mutable int lockCount_;
76 // This contains a table of "global" macros that are always accessible,
77 // either because they implement a feature of standard LaTeX or some
78 // hack to display certain contents nicely.
80 class MacroTable : public std::map<docstring, MacroData>
83 /// Parse full "\\def..." or "\\newcommand..." or ...
84 void insert(docstring const & definition, std::string const &);
85 /// Insert pre-digested macro definition
86 void insert(docstring const & name, MacroData const & data);
87 /// Do we have a macro by that name?
88 bool has(docstring const & name) const;
90 MacroData const & get(docstring const & name) const;
95 static MacroTable & globalMacros();
96 /// the local list hack
97 //static MacroTable & localMacros();