]> git.lyx.org Git - features.git/blob - src/mathed/MathMacroTable.h
ac1a9853148f7db1f83402f5300f22a599a1d976
[features.git] / src / mathed / MathMacroTable.h
1 // -*- C++ -*-
2 /**
3  * \file MathMacroTable.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author AndrÈ Pˆnitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef MATH_MACROTABLE_H
13 #define MATH_MACROTABLE_H
14
15 #include "support/docstring.h"
16
17 #include <boost/assert.hpp>
18
19 #include <map>
20 #include <vector>
21
22 namespace lyx {
23
24 class MathArray;
25
26 ///
27 class MacroData {
28 public:
29         ///
30         MacroData();
31         ///
32         MacroData(docstring const & def, int nargs, docstring const & disp, std::string const &);
33         ///
34         docstring def() const { return def_; }
35         ///
36         docstring disp() const { return disp_; }
37         ///
38         int numargs() const { return numargs_; }
39         /// replace #1,#2,... by given MathAtom 0,1,..
40         void expand(std::vector<MathArray> const & from, MathArray & to) const;
41         ///
42         std::string requires() const { return requires_; }
43         ///
44         std::string & requires() { return requires_; }
45         
46         ///
47         int lock() { return ++lockCount_; }
48         ///
49         bool locked() const { return lockCount_ != 0; }
50         ///
51         void unlock() { --lockCount_; BOOST_ASSERT(lockCount_ >= 0); }
52         
53 private:
54         ///
55         docstring def_;
56         ///
57         int numargs_;
58         ///
59         docstring disp_;
60         ///
61         std::string requires_;
62         ///
63         int lockCount_;
64 };
65
66
67 // This contains a table of "global" macros that are always accessible,
68 // either because they implement a feature of standard LaTeX or some
69 // hack to display certain contents nicely.
70
71 class MacroTable : public std::map<docstring, MacroData>
72 {
73 public:
74         /// Parse full "\\def..." or "\\newcommand..." or ...
75         void insert(docstring const & definition, std::string const &);
76         /// Insert pre-digested macro definition
77         void insert(docstring const & name, MacroData const & data);
78         /// Do we have a macro by that name?
79         bool has(docstring const & name) const;
80         ///
81         MacroData const & get(docstring const & name) const;
82         ///
83         void dump();
84
85         /// the global list
86         static MacroTable & globalMacros();
87         /// the local list hack
88         //static MacroTable & localMacros();
89 };
90
91
92 } // namespace lyx
93
94 #endif