]> git.lyx.org Git - lyx.git/blob - src/ModuleList.h
Re-fix #11146 with recent LaTeX
[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 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 a 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  *   #DescriptionBegin
35  *   #Numbers theorems and the like by section.
36  *   #DescriptionEnd
37  *   #Requires: theorems-std | theorems-ams
38  *   #Excludes: theorems-chap
39  *   #Category: theorems
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 & requires,
56                   std::vector<std::string> const & excludes,
57                   std::string const & catgy);
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         /// \return true if the module is compatible with this one, i.e.,
82         /// it does not exclude us and we do not exclude it.
83         /// this will also return true if modname is unknown and we do not
84         /// exclude it, since in that case we cannot check its exclusions.
85         bool isCompatible(std::string const & modname) const;
86         ///
87         static bool areCompatible(std::string const & mod1, std::string const & mod2);
88 private:
89         /// what appears in the ui
90         std::string name_;
91         /// the module's unique identifier
92         /// at present, this is the filename, without the extension
93         std::string id_;
94         /// the filename
95         std::string filename_;
96         /// a short description for use in the ui
97         std::string description_;
98         /// the LaTeX packages on which this depends, if any
99         std::vector<std::string> package_list_;
100         /// Modules this one requires: at least one
101         std::vector<std::string> required_modules_;
102         /// Modules this one excludes: none of these
103         std::vector<std::string> excluded_modules_;
104         /// Category, also used in the UI
105         std::string category_;
106         // these are mutable because they are used to cache the results
107         // or an otherwise const operation.
108         ///
109         mutable bool checked_;
110         ///
111         mutable bool available_;
112         ///
113         mutable std::vector<std::string> prerequisites_;
114 };
115
116 typedef std::vector<LyXModule> LyXModuleList;
117
118 /**
119  *  The ModuleList represents the various LyXModule's that are available at
120  *  present.
121  */
122 class ModuleList {
123 public:
124         ///
125         ModuleList() {}
126         /// reads the modules from a file generated by configure.py
127         bool read();
128         ///
129         LyXModuleList::const_iterator begin() const;
130         ///
131         LyXModuleList::iterator begin();
132         ///
133         LyXModuleList::const_iterator end() const;
134         ///
135         LyXModuleList::iterator end();
136         ///
137         bool empty() const { return modlist_.empty(); }
138         /// Returns a pointer to the LyXModule with filename str.
139         /// Returns a null pointer if no such module is found.
140         LyXModule const * operator[](std::string const & str) const;
141         ///
142         LyXModule * operator[](std::string const & str);
143         private:
144         /// noncopyable
145         ModuleList(ModuleList const &);
146         ///
147         void operator=(ModuleList const &);
148         /// add a module to the list
149         void addLayoutModule(std::string const &, std::string const &,
150                 std::string const &, std::vector<std::string> const &,
151                 std::vector<std::string> const &, std::vector<std::string> const &,
152                 std::string const &);
153         ///
154         std::vector<LyXModule> modlist_;
155 };
156
157 extern ModuleList theModuleList;
158 } // namespace lyx
159 #endif