diff --git a/src/BaseClassList.cpp b/src/BaseClassList.cpp index 91e86bf60a..535bb21799 100644 --- a/src/BaseClassList.cpp +++ b/src/BaseClassList.cpp @@ -33,6 +33,13 @@ using boost::bind; using boost::regex; using boost::smatch; +BaseClassList & BaseClassList::get() +{ + static BaseClassList baseclasslist; + return baseclasslist; +} + + // Gets textclass number from name pair const BaseClassList::numberOfClass(string const & textclass) const @@ -206,8 +213,7 @@ BaseClassList::addTextClass(string const & textclass, string const & path) tmpl.load(path); // Do not add this local TextClass to classlist_ if it has // already been loaded by, for example, a master buffer. - pair pp = - baseclasslist.numberOfClass(textclass); + pair pp = numberOfClass(textclass); // only layouts from the same directory are considered to be identical. if (pp.first && classlist_[pp.second].description() == tmpl.description()) return pp; @@ -225,9 +231,6 @@ BaseClassList::addTextClass(string const & textclass, string const & path) } -// Global variable: textclass table. -BaseClassList baseclasslist; - BaseClassIndex defaultBaseclass() { @@ -235,7 +238,7 @@ BaseClassIndex defaultBaseclass() // true in the returned pair, then `second' is the textclass // number; if it is false, second is 0. In both cases, second // is what we want. - return baseclasslist.numberOfClass("article").second; + return BaseClassList::get().numberOfClass("article").second; } @@ -245,7 +248,7 @@ bool LyXSetStyle() { LYXERR(Debug::TCLASS, "LyXSetStyle: parsing configuration..."); - if (!baseclasslist.read()) { + if (!BaseClassList::get().read()) { LYXERR(Debug::TCLASS, "LyXSetStyle: an error occured " "during parsing.\n Exiting."); return false; diff --git a/src/BaseClassList.h b/src/BaseClassList.h index 9a5b29e6b1..cd873ccbe6 100644 --- a/src/BaseClassList.h +++ b/src/BaseClassList.h @@ -41,10 +41,14 @@ private: }; /// A list of base document classes (*.layout files). +/// This is a singleton class. The sole instance is accessed +/// via BaseClassList::get() class BaseClassList { public: /// BaseClassList() {} + /// \return The sole instance of this class. + static BaseClassList & get(); /// typedef std::vector ClassList; /// @@ -84,8 +88,6 @@ private: mutable ClassList classlist_; }; -/// -extern BaseClassList baseclasslist; /// BaseClassIndex defaultBaseclass(); diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 14389a7f7a..15c7d8a72b 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -466,12 +466,12 @@ string const BufferParams::readToken(Lexer & lex, string const & token, pair pp = make_pair(false, BaseClassIndex(0)); if (!filepath.empty()) - pp = baseclasslist.addTextClass( + pp = BaseClassList::get().addTextClass( classname, filepath.absFilename()); if (pp.first) setBaseClass(pp.second); else { - pp = baseclasslist.numberOfClass(classname); + pp = BaseClassList::get().numberOfClass(classname); if (pp.first) setBaseClass(pp.second); else { @@ -678,7 +678,7 @@ void BufferParams::writeFile(ostream & os) const // Prints out the buffer info into the .lyx file given by file // the textclass - os << "\\textclass " << baseclasslist[pimpl_->baseClass_].name() << '\n'; + os << "\\textclass " << BaseClassList::get()[pimpl_->baseClass_].name() << '\n'; // then the preamble if (!preamble.empty()) { @@ -1344,7 +1344,7 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, void BufferParams::useClassDefaults() { - TextClass const & tclass = baseclasslist[pimpl_->baseClass_]; + TextClass const & tclass = BaseClassList::get()[pimpl_->baseClass_]; sides = tclass.sides(); columns = tclass.columns(); @@ -1360,7 +1360,7 @@ void BufferParams::useClassDefaults() bool BufferParams::hasClassDefaults() const { - TextClass const & tclass = baseclasslist[pimpl_->baseClass_]; + TextClass const & tclass = BaseClassList::get()[pimpl_->baseClass_]; return sides == tclass.sides() && columns == tclass.columns() @@ -1390,14 +1390,14 @@ void BufferParams::setDocumentClass(DocumentClass const * const tc) { bool BufferParams::setBaseClass(BaseClassIndex tc) { - if (baseclasslist[tc].load()) { + if (BaseClassList::get()[tc].load()) { pimpl_->baseClass_ = tc; return true; } docstring s = bformat(_("The document class %1$s could not be loaded."), - from_utf8(baseclasslist[tc].name())); + from_utf8(BaseClassList::get()[tc].name())); frontend::Alert::error(_("Could not load class"), s); return false; } @@ -1411,7 +1411,7 @@ BaseClassIndex BufferParams::baseClass() const void BufferParams::makeDocumentClass() { - doc_class_ = &(DocumentClassBundle::get().newClass(baseclasslist[baseClass()])); + doc_class_ = &(DocumentClassBundle::get().newClass(BaseClassList::get()[baseClass()])); //FIXME It might be worth loading the children's modules here, //just as we load their bibliographies and such, instead of just diff --git a/src/LyX.cpp b/src/LyX.cpp index 9a60901d84..56cf176cf1 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -576,7 +576,7 @@ void LyX::execBatchCommands() // aknowledged. // if reconfiguration is needed. - while (baseclasslist.empty()) { + while (BaseClassList::get().empty()) { switch (Alert::prompt( _("No textclass is found"), _("LyX cannot continue because no textclass is found. " diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index b5789e0069..d3dbc7f082 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -718,7 +718,7 @@ void showPrintError(string const & name) void loadTextClass(string const & name, string const & buf_path) { pair const tc_pair = - baseclasslist.numberOfClass(name); + BaseClassList::get().numberOfClass(name); if (!tc_pair.first) { lyxerr << "Document class \"" << name @@ -729,10 +729,10 @@ void loadTextClass(string const & name, string const & buf_path) BaseClassIndex const tc = tc_pair.second; - if (!baseclasslist[tc].load(buf_path)) { + if (!BaseClassList::get()[tc].load(buf_path)) { docstring s = bformat(_("The document class %1$s." "could not be loaded."), - from_utf8(baseclasslist[tc].name())); + from_utf8(BaseClassList::get()[tc].name())); Alert::error(_("Could not load class"), s); } } @@ -1611,7 +1611,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) loadTextClass(argument, buffer->filePath()); pair const tc_pair = - baseclasslist.numberOfClass(argument); + BaseClassList::get().numberOfClass(argument); if (!tc_pair.first) break; @@ -1638,7 +1638,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) Buffer * buffer = lyx_view_->buffer(); DocumentClass * oldClass = buffer->params().documentClassPtr(); BaseClassIndex const tc = buffer->params().baseClass(); - baseclasslist.reset(tc); + BaseClassList::get().reset(tc); buffer->params().setBaseClass(tc); buffer->params().makeDocumentClass(); updateLayout(oldClass, buffer); diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 9e3edc0e9e..30e4a46c55 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -879,8 +879,8 @@ GuiDocument::GuiDocument(GuiView & lv) //FIXME This seems too involved with the kernel. Some of this //should be moved to the kernel---which should perhaps just //give us a list of entries or something of the sort. - for (BaseClassList::const_iterator cit = baseclasslist.begin(); - cit != baseclasslist.end(); ++cit) { + for (BaseClassList::const_iterator cit = BaseClassList::get().begin(); + cit != BaseClassList::get().end(); ++cit) { if (cit->isTeXClassAvailable()) { latexModule->classCO->addItem(toqstr(cit->description())); } else { @@ -2113,7 +2113,7 @@ vector const GuiDocument::getSelectedModules() TextClass const & GuiDocument::textClass() const { - return baseclasslist[bp_.baseClass()]; + return BaseClassList::get()[bp_.baseClass()]; } diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index 83f4e4699a..39a9517b44 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -202,7 +202,7 @@ void InsetInfo::updateInfo() break; case TEXTCLASS_INFO: { // name_ is the class name - pair pp = baseclasslist.numberOfClass(name_); + pair pp = BaseClassList::get().numberOfClass(name_); setText(pp.first ? _("yes") : _("no"), bp.getFont(), false); break;