From 4c6180d209ddd3940790059136e9c0be6169e0cf Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Sun, 24 Feb 2008 16:59:49 +0000 Subject: [PATCH] Try to make the distinction between base classes and text classes clearer in the code. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23198 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/scons/scons_manifest.py | 4 +-- src/{TextClassList.cpp => BaseClassList.cpp} | 32 +++++++++--------- src/{TextClassList.h => BaseClassList.h} | 34 ++++++++++++++------ src/Buffer.cpp | 2 +- src/BufferParams.cpp | 22 ++++++------- src/BufferParams.h | 2 +- src/CutAndPaste.cpp | 2 +- src/LyX.cpp | 4 +-- src/LyXFunc.cpp | 12 +++---- src/Makefile.am | 4 +-- src/ModuleList.cpp | 2 +- src/TextClass.h | 15 --------- src/buffer_funcs.cpp | 2 +- src/frontends/qt4/GuiDocument.cpp | 8 ++--- src/insets/InsetInclude.cpp | 1 + src/insets/InsetInfo.cpp | 4 +-- 16 files changed, 75 insertions(+), 75 deletions(-) rename src/{TextClassList.cpp => BaseClassList.cpp} (90%) rename src/{TextClassList.h => BaseClassList.h} (71%) diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index cb5046010b..0b178cb71e 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -30,6 +30,7 @@ TOP_extra_files = Split(''' src_header_files = Split(''' ASpell_local.h Author.h + BaseClassList.h BiblioInfo.h Bidi.h Box.h @@ -112,7 +113,6 @@ src_header_files = Split(''' TexRow.h Text.h TextClass.h - TextClassList.h TextClassPtr.h TextMetrics.h Thesaurus.h @@ -143,6 +143,7 @@ src_header_files = Split(''' src_pre_files = Split(''' Author.cpp + BaseClassList.cpp BiblioInfo.cpp Bidi.cpp BranchList.cpp @@ -213,7 +214,6 @@ src_pre_files = Split(''' Text2.cpp Text3.cpp TextClass.cpp - TextClassList.cpp TextMetrics.cpp TocBackend.cpp ToolbarBackend.cpp diff --git a/src/TextClassList.cpp b/src/BaseClassList.cpp similarity index 90% rename from src/TextClassList.cpp rename to src/BaseClassList.cpp index 87191b53b0..8baa64abf5 100644 --- a/src/TextClassList.cpp +++ b/src/BaseClassList.cpp @@ -1,5 +1,5 @@ /** - * \file TextClassList.cpp + * \file BaseClassList.cpp * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -11,7 +11,7 @@ #include -#include "TextClassList.h" +#include "BaseClassList.h" #include "TextClass.h" #include "Lexer.h" @@ -35,7 +35,7 @@ using boost::smatch; // Gets textclass number from name pair const -TextClassList::numberOfClass(string const & textclass) const +BaseClassList::numberOfClass(string const & textclass) const { ClassList::const_iterator cit = find_if(classlist_.begin(), classlist_.end(), @@ -51,7 +51,7 @@ TextClassList::numberOfClass(string const & textclass) const // Gets a textclass structure from number TextClass const & -TextClassList::operator[](BaseClassIndex textclass) const +BaseClassList::operator[](BaseClassIndex textclass) const { if (textclass >= classlist_.size()) return classlist_[0]; @@ -82,14 +82,14 @@ public: // Reads LyX textclass definitions according to textclass config file -bool TextClassList::read() +bool BaseClassList::read() { Lexer lex(0, 0); FileName const real_file = libFileSearch("", "textclass.lst"); LYXERR(Debug::TCLASS, "Reading textclasses from `" << real_file << '\''); if (real_file.empty()) { - lyxerr << "TextClassList::Read: unable to find " + lyxerr << "BaseClassList::Read: unable to find " "textclass file `" << to_utf8(makeDisplayPath(real_file.absFilename(), 1000)) << "'. Exiting." << endl; @@ -102,13 +102,13 @@ bool TextClassList::read() } if (!lex.setFile(real_file)) { - lyxerr << "TextClassList::Read: " + lyxerr << "BaseClassList::Read: " "lyxlex was not able to set file: " << real_file << endl; } if (!lex.isOK()) { - lyxerr << "TextClassList::Read: unable to open " + lyxerr << "BaseClassList::Read: unable to open " "textclass file `" << to_utf8(makeDisplayPath(real_file.absFilename(), 1000)) << "'\nCheck your installation. LyX can't continue." @@ -157,7 +157,7 @@ bool TextClassList::read() // in this case. This gives users a second chance to configure lyx if // initial configuration fails. (c.f. bug 2829) if (classlist_.empty()) - lyxerr << "TextClassList::Read: no textclasses found!" + lyxerr << "BaseClassList::Read: no textclasses found!" << endl; else // Ok everything loaded ok, now sort the list. @@ -166,7 +166,7 @@ bool TextClassList::read() } -void TextClassList::reset(BaseClassIndex const textclass) { +void BaseClassList::reset(BaseClassIndex const textclass) { if (textclass >= classlist_.size()) return; TextClass const & tc = classlist_[textclass]; @@ -177,7 +177,7 @@ void TextClassList::reset(BaseClassIndex const textclass) { pair const -TextClassList::addTextClass(string const & textclass, string const & path) +BaseClassList::addTextClass(string const & textclass, string const & path) { // only check for textclass.layout file, .cls can be anywhere in $TEXINPUTS // NOTE: latex class name is defined in textclass.layout, which can be different from textclass @@ -207,7 +207,7 @@ TextClassList::addTextClass(string const & textclass, string const & path) // Do not add this local TextClass to classlist_ if it has // already been loaded by, for example, a master buffer. pair pp = - textclasslist.numberOfClass(textclass); + baseclasslist.numberOfClass(textclass); // only layouts from the same directory are considered to be identical. if (pp.first && classlist_[pp.second].description() == tmpl.description()) return pp; @@ -226,16 +226,16 @@ TextClassList::addTextClass(string const & textclass, string const & path) // Global variable: textclass table. -TextClassList textclasslist; +BaseClassList baseclasslist; -BaseClassIndex defaultTextclass() +BaseClassIndex defaultBaseclass() { // We want to return the article class. if `first' is // 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 textclasslist.numberOfClass("article").second; + return baseclasslist.numberOfClass("article").second; } @@ -245,7 +245,7 @@ bool LyXSetStyle() { LYXERR(Debug::TCLASS, "LyXSetStyle: parsing configuration..."); - if (!textclasslist.read()) { + if (!baseclasslist.read()) { LYXERR(Debug::TCLASS, "LyXSetStyle: an error occured " "during parsing.\n Exiting."); return false; diff --git a/src/TextClassList.h b/src/BaseClassList.h similarity index 71% rename from src/TextClassList.h rename to src/BaseClassList.h index 3b0870df40..9a5b29e6b1 100644 --- a/src/TextClassList.h +++ b/src/BaseClassList.h @@ -1,6 +1,6 @@ // -*- C++ -*- /** - * \file TextClassList.h + * \file BaseClassList.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -9,8 +9,8 @@ * Full author contact details are available in file CREDITS. */ -#ifndef TEXTCLASSLIST_H -#define TEXTCLASSLIST_H +#ifndef BASECLASSLIST_H +#define BASECLASSLIST_H #include "TextClass.h" @@ -26,11 +26,25 @@ class Layout; /// Reads the style files extern bool LyXSetStyle(); -/// -class TextClassList { +/// Index into BaseClassList. Basically a 'strong typedef'. +class BaseClassIndex { public: /// - TextClassList() {} + typedef size_t base_type; + /// + BaseClassIndex(base_type t) { data_ = t; } + /// + operator base_type() const { return data_; } + /// +private: + base_type data_; +}; + +/// A list of base document classes (*.layout files). +class BaseClassList { +public: + /// + BaseClassList() {} /// typedef std::vector ClassList; /// @@ -62,18 +76,18 @@ public: private: /// noncopyable - TextClassList(TextClassList const &); + BaseClassList(BaseClassList const &); /// nonassignable - void operator=(TextClassList const &); + void operator=(BaseClassList const &); /// mutable ClassList classlist_; }; /// -extern TextClassList textclasslist; +extern BaseClassList baseclasslist; /// -BaseClassIndex defaultTextclass(); +BaseClassIndex defaultBaseclass(); } // namespace lyx diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 3a074cba94..5615355fae 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -14,6 +14,7 @@ #include "Buffer.h" #include "Author.h" +#include "BaseClassList.h" #include "BiblioInfo.h" #include "BranchList.h" #include "buffer_funcs.h" @@ -54,7 +55,6 @@ #include "sgml.h" #include "TexRow.h" #include "TexStream.h" -#include "TextClassList.h" #include "Text.h" #include "TocBackend.h" #include "Undo.h" diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 66e829e437..bcb4123db8 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -18,6 +18,7 @@ #include "BufferParams.h" #include "Author.h" +#include "BaseClassList.h" #include "BranchList.h" #include "buffer_funcs.h" #include "Bullet.h" @@ -29,7 +30,6 @@ #include "Font.h" #include "Lexer.h" #include "LyXRC.h" -#include "TextClassList.h" #include "OutputParams.h" #include "Spacing.h" #include "TexRow.h" @@ -314,7 +314,7 @@ void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr) BufferParams::BufferParams() : pimpl_(new Impl) { - setBaseClass(defaultTextclass()); + setBaseClass(defaultBaseclass()); makeTextClass(); paragraph_separation = PARSEP_INDENT; quotes_language = InsetQuotes::EnglishQ; @@ -466,17 +466,17 @@ string const BufferParams::readToken(Lexer & lex, string const & token, pair pp = make_pair(false, BaseClassIndex(0)); if (!filepath.empty()) - pp = textclasslist.addTextClass( + pp = baseclasslist.addTextClass( classname, filepath.absFilename()); if (pp.first) setBaseClass(pp.second); else { - pp = textclasslist.numberOfClass(classname); + pp = baseclasslist.numberOfClass(classname); if (pp.first) setBaseClass(pp.second); else { // a warning will be given for unknown class - setBaseClass(defaultTextclass()); + setBaseClass(defaultBaseclass()); return classname; } } @@ -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 " << textclasslist[pimpl_->baseClass_].name() << '\n'; + os << "\\textclass " << baseclasslist[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 = textclasslist[pimpl_->baseClass_]; + TextClass const & tclass = baseclasslist[pimpl_->baseClass_]; sides = tclass.sides(); columns = tclass.columns(); @@ -1360,7 +1360,7 @@ void BufferParams::useClassDefaults() bool BufferParams::hasClassDefaults() const { - TextClass const & tclass = textclasslist[pimpl_->baseClass_]; + TextClass const & tclass = baseclasslist[pimpl_->baseClass_]; return sides == tclass.sides() && columns == tclass.columns() @@ -1389,14 +1389,14 @@ void BufferParams::setTextClass(TextClassPtr tc) { bool BufferParams::setBaseClass(BaseClassIndex tc) { - if (textclasslist[tc].load()) { + if (baseclasslist[tc].load()) { pimpl_->baseClass_ = tc; return true; } docstring s = bformat(_("The document class %1$s could not be loaded."), - from_utf8(textclasslist[tc].name())); + from_utf8(baseclasslist[tc].name())); frontend::Alert::error(_("Could not load class"), s); return false; } @@ -1410,7 +1410,7 @@ BaseClassIndex BufferParams::baseClass() const void BufferParams::makeTextClass() { - textClass_.reset(new TextClass(textclasslist[baseClass()])); + textClass_.reset(new TextClass(baseclasslist[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/BufferParams.h b/src/BufferParams.h index 279dfbe387..35089e1858 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -33,6 +33,7 @@ class FileName; } class AuthorList; +class BaseClassIndex; class BranchList; class Bullet; class Encoding; @@ -42,7 +43,6 @@ class LatexFeatures; class PDFOptions; class Spacing; class TextClass; -class BaseClassIndex; class TexRow; class VSpace; diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index fcf9633520..c596ca4ad6 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -15,6 +15,7 @@ #include "CutAndPaste.h" +#include "BaseClassList.h" #include "Buffer.h" #include "buffer_funcs.h" #include "BufferParams.h" @@ -30,7 +31,6 @@ #include "LyXFunc.h" #include "LyXRC.h" #include "Text.h" -#include "TextClassList.h" #include "Paragraph.h" #include "paragraph_funcs.h" #include "ParagraphParameters.h" diff --git a/src/LyX.cpp b/src/LyX.cpp index 29c8defc23..40d76173a2 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -17,6 +17,7 @@ #include "LyX.h" +#include "BaseClassList.h" #include "Buffer.h" #include "BufferList.h" #include "CmdDef.h" @@ -39,7 +40,6 @@ #include "Server.h" #include "ServerSocket.h" #include "Session.h" -#include "TextClassList.h" #include "ToolbarBackend.h" #include "frontends/alert.h" @@ -582,7 +582,7 @@ void LyX::execBatchCommands() // aknowledged. // if reconfiguration is needed. - while (textclasslist.empty()) { + while (baseclasslist.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 4443be2891..84bb7b85cd 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -21,6 +21,7 @@ #include "LyXFunc.h" +#include "BaseClassList.h" #include "BranchList.h" #include "buffer_funcs.h" #include "Buffer.h" @@ -54,7 +55,6 @@ #include "Row.h" #include "Server.h" #include "Session.h" -#include "TextClassList.h" #include "insets/InsetBox.h" #include "insets/InsetBranch.h" @@ -715,7 +715,7 @@ void showPrintError(string const & name) void loadTextClass(string const & name, string const & buf_path) { pair const tc_pair = - textclasslist.numberOfClass(name); + baseclasslist.numberOfClass(name); if (!tc_pair.first) { lyxerr << "Document class \"" << name @@ -726,10 +726,10 @@ void loadTextClass(string const & name, string const & buf_path) BaseClassIndex const tc = tc_pair.second; - if (!textclasslist[tc].load(buf_path)) { + if (!baseclasslist[tc].load(buf_path)) { docstring s = bformat(_("The document class %1$s." "could not be loaded."), - from_utf8(textclasslist[tc].name())); + from_utf8(baseclasslist[tc].name())); Alert::error(_("Could not load class"), s); } } @@ -1608,7 +1608,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) loadTextClass(argument, buffer->filePath()); pair const tc_pair = - textclasslist.numberOfClass(argument); + baseclasslist.numberOfClass(argument); if (!tc_pair.first) break; @@ -1635,7 +1635,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) Buffer * buffer = lyx_view_->buffer(); TextClassPtr oldClass = buffer->params().textClassPtr(); BaseClassIndex const tc = buffer->params().baseClass(); - textclasslist.reset(tc); + baseclasslist.reset(tc); buffer->params().setBaseClass(tc); buffer->params().makeTextClass(); updateLayout(oldClass, buffer); diff --git a/src/Makefile.am b/src/Makefile.am index 2e7e2e0a7a..e30ac8fad6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -76,6 +76,7 @@ endif SOURCEFILESCORE = \ Author.cpp \ + BaseClassList.cpp \ BiblioInfo.cpp \ Bidi.cpp \ boost.cpp \ @@ -156,7 +157,6 @@ SOURCEFILESCORE = \ Text2.cpp \ Text3.cpp \ TexStream.cpp \ - TextClassList.cpp \ TextMetrics.cpp \ TocBackend.cpp \ ToolbarBackend.cpp \ @@ -170,6 +170,7 @@ SOURCEFILESCORE = \ HEADERFILESCORE = \ Author.h \ + BaseClassList.h \ BiblioInfo.h \ Bidi.h \ BranchList.h \ @@ -260,7 +261,6 @@ HEADERFILESCORE = \ TexStream.h \ Text.h \ TextClass.h \ - TextClassList.h \ TextClassPtr.h \ TextMetrics.h \ TocBackend.h \ diff --git a/src/ModuleList.cpp b/src/ModuleList.cpp index 0f49217812..ac0f69de6b 100644 --- a/src/ModuleList.cpp +++ b/src/ModuleList.cpp @@ -76,7 +76,7 @@ public: }; -//Much of this is borrowed from TextClassList::read() +//Much of this is borrowed from BaseClassList::read() bool ModuleList::load() { FileName const real_file = libFileSearch("", "lyxmodules.lst"); diff --git a/src/TextClass.h b/src/TextClass.h index f7f4d1b11c..07b4f16893 100644 --- a/src/TextClass.h +++ b/src/TextClass.h @@ -38,21 +38,6 @@ class FloatList; /// List of inset layouts typedef std::map InsetLayouts; -/// Index into global list of base classes (i.e., *.layout). -/// Basically a 'strong typedef'. -class BaseClassIndex { -public: - /// - typedef size_t base_type; - /// - BaseClassIndex(base_type t) { data_ = t; } - /// - operator base_type() const { return data_; } - /// -private: - base_type data_; -}; - /// Stores the layout specification of a LyX document class. class TextClass { public: diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index 6e8e612f94..a25bce28d3 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -12,6 +12,7 @@ #include +#include "BaseClassList.h" #include "buffer_funcs.h" #include "Buffer.h" #include "BufferList.h" @@ -29,7 +30,6 @@ #include "LayoutPtr.h" #include "LyX.h" #include "TextClass.h" -#include "TextClassList.h" #include "Paragraph.h" #include "paragraph_funcs.h" #include "ParagraphList.h" diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index bc5e201bbb..bf694e826b 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -13,6 +13,7 @@ #include "GuiDocument.h" +#include "BaseClassList.h" #include "BranchList.h" #include "buffer_funcs.h" #include "Buffer.h" @@ -37,7 +38,6 @@ #include "PDFOptions.h" #include "qt_helpers.h" #include "Spacing.h" -#include "TextClassList.h" #include "Validator.h" #include "insets/InsetListingsParams.h" @@ -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 (TextClassList::const_iterator cit = textclasslist.begin(); - cit != textclasslist.end(); ++cit) { + for (BaseClassList::const_iterator cit = baseclasslist.begin(); + cit != baseclasslist.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 textclasslist[bp_.baseClass()]; + return baseclasslist[bp_.baseClass()]; } diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 686d445f53..0601a99350 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -14,6 +14,7 @@ #include "InsetInclude.h" +#include "BaseClassList.h" #include "Buffer.h" #include "buffer_funcs.h" #include "BufferList.h" diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index 5168447a41..2c564698d3 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -27,7 +27,7 @@ #include "MenuBackend.h" #include "MetricsInfo.h" #include "ParagraphParameters.h" -#include "TextClassList.h" +#include "BaseClassList.h" #include "frontends/Application.h" @@ -202,7 +202,7 @@ void InsetInfo::updateInfo(Buffer const & buf) break; case TEXTCLASS_INFO: { // name_ is the class name - pair pp = textclasslist.numberOfClass(name_); + pair pp = baseclasslist.numberOfClass(name_); setText(pp.first ? _("yes") : _("no"), bp.getFont(), false); break;