3 * \file LayoutModuleList.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Richard Kimberly Heck
9 * Full author contact details are available in file CREDITS.
12 #ifndef LAYOUTMODULELIST_H
13 #define LAYOUTMODULELIST_H
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
28 class LayoutModuleList {
31 typedef std::list<std::string>::const_iterator const_iterator;
33 typedef std::list<std::string>::iterator iterator;
35 iterator begin() { return lml_.begin(); }
37 iterator end() { return lml_.end(); }
39 const_iterator begin() const { return lml_.begin(); }
41 const_iterator end() const { return lml_.end(); }
43 void clear() { lml_.clear(); }
45 bool empty() const { return lml_.empty(); }
47 iterator erase(iterator pos) { return lml_.erase(pos); }
49 iterator insert(iterator pos, std::string const & str)
50 { return lml_.insert(pos, str); }
52 void push_back(std::string const & str) { lml_.push_back(str); }
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
76 bool adaptToBaseClass(LayoutFile const * const lay,
77 std::list<std::string> const & removedModules);
79 bool operator==(LayoutModuleList const & other) const {
80 return lml_ == other.lml_;
83 bool operator!=(LayoutModuleList const & other) const {
84 return !operator==(other);
87 /// Removes modules excluded by, provided by, etc, the base class.
88 /// \param lay The document class against which to check.
89 /// \return true, if modules were consistent, false if changes had
91 bool removeBadModules(LayoutFile const * const lay);
92 /// Adds default modules, if they're addable.
93 /// \param lay The base class from which to get default modules.
94 /// \param removedModules Modules the user has explicitly removed.
95 void addDefaultModules(LayoutFile const * const lay,
96 std::list<std::string> removedModules);
97 /// Checks for consistency among modules: makes sure requirements
98 /// are met, no modules exclude one another, etc, and resolves any
99 /// such conflicts, leaving us with a consistent collection.
100 /// \param lay The base class against which to check.
101 /// \return true if modules were consistent, false if changes had
103 bool checkModuleConsistency(LayoutFile const * const lay);
105 std::list<std::string> lml_;