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