]> git.lyx.org Git - lyx.git/blob - src/LayoutModuleList.h
listerrors.lyx : Update a link.
[lyx.git] / src / LayoutModuleList.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 LAYOUTMODULELIST_H
13 #define LAYOUTMODULELIST_H
14
15 #include <list>
16 #include <string>
17
18 namespace lyx {
19
20 class LayoutFile;
21
22 /**
23         Represents a list of modules, such as might be associated with 
24         a particular document. Provides methods for adding modules, checking
25         if a module can be added, and, importantly, adapting the list to a 
26         new DocumentClass.
27 */
28 class LayoutModuleList {
29 public:
30         ///
31         typedef std::list<std::string>::const_iterator const_iterator;
32         ///
33         typedef std::list<std::string>::iterator iterator;
34         ///
35         iterator begin() { return lml_.begin(); }
36         ///
37         iterator end() { return lml_.end(); }
38         ///
39         const_iterator begin() const { return lml_.begin(); }
40         ///
41         const_iterator end() const { return lml_.end(); }
42         ///
43         void clear() { lml_.clear(); }
44         ///
45         bool empty() const { return lml_.empty(); }
46         ///
47         iterator erase(iterator pos) { return lml_.erase(pos); }
48         ///
49         iterator insert(iterator pos, std::string const & str)
50                 { return lml_.insert(pos, str); }
51         ///
52         void push_back(std::string const & str) { lml_.push_back(str); }
53         /// 
54         size_t size() const { return lml_.size(); }
55         /// This is needed in GuiDocument. It seems better than an
56         /// implicit conversion.
57         std::list<std::string> const & list() const { return lml_; }
58         /// Checks to make sure module's requriements are satisfied, that it does
59         /// not conflict with already-present modules, isn't already loaded, etc.
60         bool moduleCanBeAdded(std::string const & modName, 
61                         LayoutFile const * const lay) const;
62         /// If the user changes the base class for a given document, then the
63         /// associated module list has to be updated. This just calls
64         /// (i)   removeBadModules()
65         /// (ii)  addDefaultModules()
66         /// (iii) checkModuleConsistency()
67         /// in that order, for which see below.
68         /// \param lay The new base class.
69         /// \param removedModules Modules the user explicitly removed and so
70         /// which should not be included.
71         /// \return true if no changes had to be made, false if some did have
72         /// to be made.
73         bool adaptToBaseClass(LayoutFile const * const lay,
74                         std::list<std::string> const & removedModules);
75 private:
76         /// Removes modules excluded by, provided by, etc, the base class.
77         /// \param lay The document class against which to check.
78         /// \return true, if modules were consistent, false if changes had
79         /// to be made.
80         bool removeBadModules(LayoutFile const * const lay);
81         /// Adds default modules, if they're addable.
82         /// \param lay The base class from which to get default modules.
83         /// \param removedModules Modules the user has explicitly removed.
84         void addDefaultModules(LayoutFile const * const lay,
85                         std::list<std::string> removedModules);
86         /// Checks for consistency among modules: makes sure requirements
87         /// are met, no modules exclude one another, etc, and resolves any
88         /// such conflicts, leaving us with a consistent collection.
89         /// \param lay The base class against which to check.
90         /// \return true if modules were consistent, false if changes had
91         /// to be made.
92         bool checkModuleConsistency(LayoutFile const * const lay);
93         ///
94         std::list<std::string> lml_;
95 };
96 }
97 #endif