]> git.lyx.org Git - lyx.git/blob - src/CmdDef.h
Fix scons and CmdDef.h for the introduction of CmdDef.
[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 <vector>
22 #include <deque>
23 #include <map>
24
25
26 namespace lyx {
27
28 /// Creates command definitions
29 class CmdDef {
30 private:
31         /// information for a definition
32         struct CmdDefInfo {
33                 CmdDefInfo(FuncRequest const & f): func(f), locked(false) {}
34                 /// the expanded FuncRequest
35                 FuncRequest func;
36                 /// to avoid recursive calls
37                 bool locked;
38         };
39
40
41         /// type for map between a macro name and its info
42         typedef std::map<std::string, boost::shared_ptr<CmdDefInfo> > CmdDefMap;
43
44 public:
45
46         /// Parse a def file
47         bool read(std::string const & def_file);
48
49         /**
50          * Look up a definition, lock it and return the
51          * associated action if it is not locked.
52          * @param name the name of the command
53          * @param func contains the action on success
54          * @return true if lock was successful
55          */
56         bool lock(std::string const & name, FuncRequest & func);
57
58         /// release a locked definition
59         void release(std::string const & name);
60
61 private:
62
63         /// possible reasons for not allowed definitions
64         enum newCmdDefResult {
65                 CmdDefOk,
66                 CmdDefNameEmpty,
67                 CmdDefInvalid,
68                 CmdDefExists
69         };
70
71         /**
72          * Add a new command definition.
73          * @param name internal recursion level
74          */
75         newCmdDefResult newCmdDef(std::string const & name, 
76                 std::string const & def);
77
78         ///
79         CmdDefMap cmdDefMap;
80 };
81
82 /// Implementation is in LyX.cpp
83 extern CmdDef & theTopLevelCmdDef();
84
85
86 } // namespace lyx
87
88 #endif // CMDDEF_H