]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotable.h
macro rework
[lyx.git] / src / mathed / math_macrotable.h
1 // -*- C++ -*-
2 /**
3  * \file math_macrotable.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 <string>
17 #include <vector>
18
19 class MathArray;
20
21 ///
22 class MacroData {
23 public:
24         ///
25         MacroData();
26         ///
27         MacroData(std::string const & def, int nargs, std::string const & disp);
28         ///
29         std::string def() const { return def_; }
30         ///
31         std::string disp() const { return disp_; }
32         ///
33         int numargs() const { return numargs_; }
34         /// replace #1,#2,... by given MathAtom 0,1,..
35         void expand(MathArray const & from, MathArray & to) const;
36
37 private:
38         ///
39         std::string def_;       
40         ///
41         int numargs_;
42         ///
43         std::string disp_;
44 };
45
46
47 // This contains a table of "global" macros that are always accessible,
48 // either because they implement a feature of standard LaTeX or some
49 // hack to display certain contents nicely.
50
51 class MacroTable {
52 public:
53         /// Parse full "\def..." or "\newcommand..." or ...
54         void insert(std::string const & definition);
55         /// Insert pre-digested macro definition
56         void insert(std::string const & name, MacroData const & data);
57         /// Do we have a macro by that name?
58         bool has(std::string const & name) const;
59         ///
60         MacroData const & get(std::string const & name) const;
61         ///
62         void dump();
63
64         /// the global list
65         static MacroTable & globalMacros();
66
67 private:
68         ///
69         typedef std::map<std::string, MacroData> table_type;
70
71         ///
72         table_type macros_;
73 };
74
75 #endif