]> git.lyx.org Git - lyx.git/blob - src/LayoutModuleList.h
prepare Qt 5.6 builds
[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         /// Like !moduleCanBeAdded(), but does not check requirements
63         bool moduleConflicts(std::string const & modName,
64                         LayoutFile const * const lay) const;
65         /// If the user changes the base class for a given document, then the
66         /// associated module list has to be updated. This just calls
67         /// (i)   removeBadModules()
68         /// (ii)  addDefaultModules()
69         /// (iii) checkModuleConsistency()
70         /// in that order, for which see below.
71         /// \param lay The new base class.
72         /// \param removedModules Modules the user explicitly removed and so
73         /// which should not be included.
74         /// \return true if no changes had to be made, false if some did have
75         /// to be made.
76         bool adaptToBaseClass(LayoutFile const * const lay,
77                         std::list<std::string> const & removedModules);
78 private:
79         /// Removes modules excluded by, provided by, etc, the base class.
80         /// \param lay The document class against which to check.
81         /// \return true, if modules were consistent, false if changes had
82         /// to be made.
83         bool removeBadModules(LayoutFile const * const lay);
84         /// Adds default modules, if they're addable.
85         /// \param lay The base class from which to get default modules.
86         /// \param removedModules Modules the user has explicitly removed.
87         void addDefaultModules(LayoutFile const * const lay,
88                         std::list<std::string> removedModules);
89         /// Checks for consistency among modules: makes sure requirements
90         /// are met, no modules exclude one another, etc, and resolves any
91         /// such conflicts, leaving us with a consistent collection.
92         /// \param lay The base class against which to check.
93         /// \return true if modules were consistent, false if changes had
94         /// to be made.
95         bool checkModuleConsistency(LayoutFile const * const lay);
96         ///
97         std::list<std::string> lml_;
98 };
99 }
100 #endif