From 56146a93460bd4c56eaecc459ccd36aa0313ff9b Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 14 Aug 2009 15:46:10 +0000 Subject: [PATCH] Constify a bunch of stuff that can be const. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31037 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ModuleList.cpp | 19 +++++++++++++++---- src/ModuleList.h | 12 ++++++++---- src/frontends/qt4/GuiDocument.cpp | 4 ++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/ModuleList.cpp b/src/ModuleList.cpp index 34c47b7cf3..85066a899e 100644 --- a/src/ModuleList.cpp +++ b/src/ModuleList.cpp @@ -45,7 +45,7 @@ LyXModule::LyXModule(string const & n, string const & i, } -bool LyXModule::isAvailable() { +bool LyXModule::isAvailable() const { #ifdef TEX2LYX return true; #else @@ -242,15 +242,26 @@ LyXModuleList::iterator ModuleList::end() } -LyXModule * ModuleList::operator[](string const & str) +LyXModule const * ModuleList::operator[](string const & str) const { - LyXModuleList::iterator it = modlist_.begin(); + LyXModuleList::const_iterator it = modlist_.begin(); for (; it != modlist_.end(); ++it) if (it->getID() == str) { - LyXModule & mod = *it; + LyXModule const & mod = *it; return &mod; } return 0; } +LyXModule * ModuleList::operator[](string const & str) +{ + LyXModuleList::iterator it = modlist_.begin(); + for (; it != modlist_.end(); ++it) + if (it->getID() == str) { + LyXModule & mod = *it; + return &mod; + } + return 0; +} + } // namespace lyx diff --git a/src/ModuleList.h b/src/ModuleList.h index d79138f213..c9a6f1f4d7 100644 --- a/src/ModuleList.h +++ b/src/ModuleList.h @@ -57,7 +57,7 @@ public: std::vector const & excludes, std::string const & catgy); /// whether the required packages are available - bool isAvailable(); + bool isAvailable() const; /// std::string const & getName() const { return name_; } /// @@ -102,10 +102,12 @@ private: std::vector excluded_modules_; /// Category, also used in the UI std::string category_; + // these are mutable because they are used to cache the results + // or an otherwise const operation. /// - bool checked_; + mutable bool checked_; /// - bool available_; + mutable bool available_; }; typedef std::vector LyXModuleList; @@ -132,8 +134,10 @@ public: bool empty() const { return modlist_.empty(); } /// Returns a pointer to the LyXModule with filename str. /// Returns a null pointer if no such module is found. + LyXModule const * operator[](std::string const & str) const; + /// LyXModule * operator[](std::string const & str); -private: + private: /// noncopyable ModuleList(ModuleList const &); /// diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 39ee411fae..b62b415c22 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -243,7 +243,7 @@ vector getPackageList(string const & modName) bool isModuleAvailable(string const & modName) { - LyXModule * mod = theModuleList[modName]; + LyXModule const * const mod = theModuleList[modName]; if (!mod) return false; return mod->isAvailable(); @@ -2694,7 +2694,7 @@ list const for (; it != end; ++it) { modInfoStruct m; m.id = *it; - LyXModule * mod = theModuleList[*it]; + LyXModule const * const mod = theModuleList[*it]; if (mod) // FIXME Unicode m.name = toqstr(translateIfPossible(from_utf8(mod->getName()))); -- 2.39.2