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 /// List of modules as a comma-separated string
59 std::string asString() const;
60 /// Checks to make sure module's requriements are satisfied, that it does
61 /// not conflict with already-present modules, isn't already loaded, etc.
62 bool moduleCanBeAdded(std::string const & modName,
63 LayoutFile const * const lay) const;
64 /// Like !moduleCanBeAdded(), but does not check requirements
65 bool moduleConflicts(std::string const & modName,
66 LayoutFile const * const lay) const;
67 /// If the user changes the base class for a given document, then the
68 /// associated module list has to be updated. This just calls
69 /// (i) removeBadModules()
70 /// (ii) addDefaultModules()
71 /// (iii) checkModuleConsistency()
72 /// in that order, for which see below.
73 /// \param lay The new base class.
74 /// \param removedModules Modules the user explicitly removed and so
75 /// which should not be included.
76 /// \return true if no changes had to be made, false if some did have
78 bool adaptToBaseClass(LayoutFile const * const lay,
79 std::list<std::string> const & removedModules);
81 bool operator==(LayoutModuleList const & other) const {
82 return lml_ == other.lml_;
85 bool operator!=(LayoutModuleList const & other) const {
86 return !operator==(other);
89 /// Removes modules excluded by, provided by, etc, the base class.
90 /// \param lay The document class against which to check.
91 /// \return true, if modules were consistent, false if changes had
93 bool removeBadModules(LayoutFile const * const lay);
94 /// Adds default modules, if they're addable.
95 /// \param lay The base class from which to get default modules.
96 /// \param removedModules Modules the user has explicitly removed.
97 void addDefaultModules(LayoutFile const * const lay,
98 std::list<std::string> removedModules);
99 /// Checks for consistency among modules: makes sure requirements
100 /// are met, no modules exclude one another, etc, and resolves any
101 /// such conflicts, leaving us with a consistent collection.
102 /// \param lay The base class against which to check.
103 /// \return true if modules were consistent, false if changes had
105 bool checkModuleConsistency(LayoutFile const * const lay);
107 std::list<std::string> lml_;