]> git.lyx.org Git - lyx.git/blob - src/mathed/MathMacroTable.h
Rename files in src/mathed and src/graphics from .C to .cpp, step 2
[lyx.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         /// 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 private:
53         ///
54         docstring def_;
55         ///
56         int numargs_;
57         ///
58         docstring disp_;
59         ///
60         std::string requires_;
61         ///
62         mutable int lockCount_;
63 };
64
65
66 // This contains a table of "global" macros that are always accessible,
67 // either because they implement a feature of standard LaTeX or some
68 // hack to display certain contents nicely.
69
70 class MacroTable : public std::map<docstring, MacroData>
71 {
72 public:
73         /// Parse full "\\def..." or "\\newcommand..." or ...
74         void insert(docstring const & definition, std::string const &);
75         /// Insert pre-digested macro definition
76         void insert(docstring const & name, MacroData const & data);
77         /// Do we have a macro by that name?
78         bool has(docstring const & name) const;
79         ///
80         MacroData const & get(docstring const & name) const;
81         ///
82         void dump();
83
84         /// the global list
85         static MacroTable & globalMacros();
86         /// the local list hack
87         //static MacroTable & localMacros();
88 };
89
90
91 } // namespace lyx
92
93 #endif