]> git.lyx.org Git - lyx.git/blob - src/ModuleList.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / ModuleList.h
1 // -*- C++ -*-
2 /**
3  * \file ModuleList.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Richard Kimberly Heck
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef MODULELIST_H
13 #define MODULELIST_H
14
15 #include <string>
16 #include <vector>
17
18 namespace lyx {
19
20 /**
21  *  This class represents a particular LyX "module", which is like a layout
22  *  file, except that it does not stand alone. In that sense, it is more like
23  *  a LaTeX package, where a layout file corresponds to a LaTeX class. Or, in
24  *  LyX's own terms, a module is more like an included file that can be used
25  *  with various document classes. The difference is that using a module only
26  *  means selecting it in the Document>Settings dialog, whereas including a
27  *  layout file means layout file editing.
28  *
29  *  In general, a given module can be used with any document class. That said,
30  *  one module may `require' another, or it may `exclude' some other module.
31  *  The requires and excludes are given in comments within the module file,
32  *  which must begin roughly so:
33  *   #\DeclareLyXModule{Theorems (By Section)}
34  *   #\DeclateCategory{Theorems}
35  *   #DescriptionBegin
36  *   #Numbers theorems and the like by section.
37  *   #DescriptionEnd
38  *   #Requires: theorems-std | theorems-ams
39  *   #Excludes: theorems-chap
40  *  The description is used in the gui to give information to the user. The
41  *  Requires, Excludes, and Category lines are read by the configuration script
42  *  and written to a file lyxmodules.lst in the user configuration directory.
43  *  That file is then read on startup to populate the ModuleList, below.
44  *
45  *  Modules can also be "provided" or "excluded" by document classes, using
46  *  the ProvidesModule and ExcludesModule tags.
47  */
48
49 class LyXModule {
50 public:
51         ///
52         LyXModule(std::string const & name, std::string const & id,
53                   std::string const & description,
54                   std::vector<std::string> const & packagelist,
55                           std::vector<std::string> const & required,
56                   std::vector<std::string> const & excludes,
57                   std::string const & catgy, bool const local);
58         /// whether the required packages are available
59         bool isAvailable() const;
60         /// the missing prerequisites, if any
61         std::vector<std::string> prerequisites() const;
62         ///
63         std::string const & getName() const { return name_; }
64         ///
65         std::string const & getID() const { return id_; }
66         ///
67         std::string const & getFilename() const { return filename_; }
68         ///
69         std::string const & getDescription() const { return description_; }
70         ///
71         std::vector<std::string> const & getPackageList() const
72                 { return package_list_; }
73         ///
74         std::vector<std::string> const & getRequiredModules() const
75                 { return required_modules_; }
76         /// Modules this one excludes: the list should be treated disjunctively
77         std::vector<std::string> const & getExcludedModules() const
78                 { return excluded_modules_; }
79         ///
80         std::string category() const { return category_; }
81         /// Is this a local module (from the user directory)?
82         bool isLocal() const { return local_; }
83         /// \return true if the module is compatible with this one, i.e.,
84         /// it does not exclude us and we do not exclude it.
85         /// this will also return true if modname is unknown and we do not
86         /// exclude it, since in that case we cannot check its exclusions.
87         bool isCompatible(std::string const & modname) const;
88         ///
89         static bool areCompatible(std::string const & mod1, std::string const & mod2);
90 private:
91         /// what appears in the ui
92         std::string name_;
93         /// the module's unique identifier
94         /// at present, this is the filename, without the extension
95         std::string id_;
96         /// the filename
97         std::string filename_;
98         /// a short description for use in the ui
99         std::string description_;
100         /// the LaTeX packages on which this depends, if any
101         std::vector<std::string> package_list_;
102         /// Modules this one requires: at least one
103         std::vector<std::string> required_modules_;
104         /// Modules this one excludes: none of these
105         std::vector<std::string> excluded_modules_;
106         /// Category, also used in the UI
107         std::string category_;
108         // these are mutable because they are used to cache the results
109         // or an otherwise const operation.
110         ///
111         mutable bool checked_;
112         ///
113         mutable bool available_;
114         ///
115         mutable bool local_;
116         ///
117         mutable std::vector<std::string> prerequisites_;
118 };
119
120 typedef std::vector<LyXModule> LyXModuleList;
121
122 /**
123  *  The ModuleList represents the various LyXModule's that are available at
124  *  present.
125  */
126 class ModuleList {
127 public:
128         ///
129         ModuleList() {}
130         /// reads the modules from a file generated by configure.py
131         bool read();
132         ///
133         LyXModuleList::const_iterator begin() const;
134         ///
135         LyXModuleList::iterator begin();
136         ///
137         LyXModuleList::const_iterator end() const;
138         ///
139         LyXModuleList::iterator end();
140         ///
141         bool empty() const { return modlist_.empty(); }
142         /// Returns a pointer to the LyXModule with filename str.
143         /// Returns a null pointer if no such module is found.
144         LyXModule const * operator[](std::string const & str) const;
145         ///
146         LyXModule * operator[](std::string const & str);
147         private:
148         /// noncopyable
149         ModuleList(ModuleList const &);
150         ///
151         void operator=(ModuleList const &);
152         /// add a module to the list
153         void addLayoutModule(std::string const &, std::string const &,
154                 std::string const &, std::vector<std::string> const &,
155                 std::vector<std::string> const &, std::vector<std::string> const &,
156                 std::string const &, bool const);
157         ///
158         std::vector<LyXModule> modlist_;
159 };
160
161 extern ModuleList theModuleList;
162 } // namespace lyx
163 #endif