]> git.lyx.org Git - features.git/blob - src/mathed/MathMacroTable.h
Fix bug 1395 by Stefan Schimanski:
[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 <map>
16 #include <vector>
17
18 #include "support/docstring.h"
19
20 namespace lyx {
21
22 class MathArray;
23
24 ///
25 class MacroData {
26 public:
27         ///
28         MacroData();
29         ///
30         MacroData(docstring const & def, int nargs, docstring const & disp, std::string const &);
31         ///
32         docstring def() const { return def_; }
33         ///
34         docstring disp() const { return disp_; }
35         ///
36         int numargs() const { return numargs_; }
37         /// replace #1,#2,... by given MathAtom 0,1,..
38         void expand(std::vector<MathArray> const & from, MathArray & to) const;
39         ///
40         std::string requires() const { return requires_; }
41         ///
42         std::string & requires() { return requires_; }
43         
44         ///
45         int lock() { return ++lockCount_; }
46         ///
47         bool locked() const { return lockCount_!=0; }
48         ///
49         void unlock() { --lockCount_; assert(lockCount_>=0); }
50         
51 private:
52         ///
53         docstring def_;
54         ///
55         int numargs_;
56         ///
57         docstring disp_;
58         ///
59         std::string requires_;
60         ///
61         int lockCount_;
62 };
63
64
65 // This contains a table of "global" macros that are always accessible,
66 // either because they implement a feature of standard LaTeX or some
67 // hack to display certain contents nicely.
68
69 class MacroTable : public std::map<docstring, MacroData>
70 {
71 public:
72         /// Parse full "\\def..." or "\\newcommand..." or ...
73         void insert(docstring const & definition, std::string const &);
74         /// Insert pre-digested macro definition
75         void insert(docstring const & name, MacroData const & data);
76         /// Do we have a macro by that name?
77         bool has(docstring const & name) const;
78         ///
79         MacroData const & get(docstring const & name) const;
80         ///
81         void dump();
82
83         /// the global list
84         static MacroTable & globalMacros();
85         /// the local list hack
86         //static MacroTable & localMacros();
87 };
88
89
90 } // namespace lyx
91
92 #endif