]> git.lyx.org Git - lyx.git/blob - src/mathed/MacroTable.h
* src/frontends/controllers/Dialog.{cpp,h}:
[lyx.git] / src / mathed / MacroTable.h
1 // -*- C++ -*-
2 /**
3  * \file 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 "support/docstring.h"
16
17 #include <boost/assert.hpp>
18
19 #include <map>
20 #include <vector>
21
22 namespace lyx {
23
24 class MathData;
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<MathData> const & from, MathData & to) const;
41         ///
42         std::string requires() const { return requires_; }
43         ///
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; }
49         ///
50         void unlock() const { --lockCount_; BOOST_ASSERT(lockCount_ >= 0); }
51
52         ///
53         bool operator==(MacroData const & x) const {
54                 return def_ == x.def_ &&
55                         numargs_ == x.numargs_ &&
56                         disp_ == x.disp_ &&
57                         requires_ == x.requires_;
58         }
59         ///
60         bool operator!=(MacroData const & x) const { return !operator==(x); }
61
62 private:
63         ///
64         docstring def_;
65         ///
66         int numargs_;
67         ///
68         docstring disp_;
69         ///
70         std::string requires_;
71         ///
72         mutable int lockCount_;
73 };
74
75
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.
79
80 class MacroTable : public std::map<docstring, MacroData>
81 {
82 public:
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;
89         ///
90         MacroData const & get(docstring const & name) const;
91         ///
92         void dump();
93
94         /// the global list
95         static MacroTable & globalMacros();
96         /// the local list hack
97         //static MacroTable & localMacros();
98 };
99
100
101 } // namespace lyx
102
103 #endif