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