]> git.lyx.org Git - lyx.git/blob - src/CmdDef.h
* gcc does not like missing characters in keywords
[lyx.git] / src / CmdDef.h
1 // -*- C++ -*-
2 /**
3  * \file CmdDef.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Bernhard Roider
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef CMDDEF_H
13 #define CMDDEF_H
14
15 #include "FuncRequest.h"
16
17 #include "support/docstream.h"
18
19 #include <boost/shared_ptr.hpp>
20
21 #include <map>
22
23
24 namespace lyx {
25
26 /// Creates command definitions
27 class CmdDef {
28 private:
29         /// information for a definition
30         struct CmdDefInfo {
31                 CmdDefInfo(FuncRequest const & f): func(f), locked(false) {}
32                 /// the expanded FuncRequest
33                 FuncRequest func;
34                 /// to avoid recursive calls
35                 bool locked;
36         };
37
38
39         /// type for map between a macro name and its info
40         typedef std::map<std::string, boost::shared_ptr<CmdDefInfo> > CmdDefMap;
41
42 public:
43
44         /// Parse a def file
45         bool read(std::string const & def_file);
46
47         /**
48          * Look up a definition, lock it and return the
49          * associated action if it is not locked.
50          * @param name the name of the command
51          * @param func contains the action on success
52          * @return true if lock was successful
53          */
54         bool lock(std::string const & name, FuncRequest & func);
55
56         /// release a locked definition
57         void release(std::string const & name);
58
59 private:
60
61         /// possible reasons for not allowed definitions
62         enum newCmdDefResult {
63                 CmdDefOk,
64                 CmdDefNameEmpty,
65                 CmdDefInvalid,
66                 CmdDefExists
67         };
68
69         /**
70          * Add a new command definition.
71          * @param name internal recursion level
72          */
73         newCmdDefResult newCmdDef(std::string const & name, 
74                 std::string const & def);
75
76         ///
77         CmdDefMap cmdDefMap;
78 };
79
80 /// Implementation is in LyX.cpp
81 extern CmdDef & theTopLevelCmdDef();
82
83
84 } // namespace lyx
85
86 #endif // CMDDEF_H