From 69de04feac27ca813a34e765b7f16cc537493206 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Sun, 24 Feb 2008 16:29:40 +0000 Subject: [PATCH] Restore Andre's TextClassIndex, but now in the form of BaseClassIndex. It seems worth distinguishing more clearly than we do at the moment between TextClass's and BaseClass's. The latter correspond to *.layout files; the former are based upon *.layout files but may be modified by modules. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23197 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferParams.cpp | 21 +++++++++++---------- src/BufferParams.h | 8 +++----- src/CutAndPaste.h | 1 - src/LyXFunc.cpp | 12 ++++++------ src/TextClass.h | 15 +++++++++++++++ src/TextClassList.cpp | 18 +++++++++--------- src/TextClassList.h | 16 ++++++++-------- src/frontends/qt4/GuiDocument.cpp | 2 +- src/frontends/qt4/GuiDocument.h | 2 -- src/insets/InsetInfo.cpp | 2 +- src/insets/InsetText.h | 2 -- src/output_docbook.cpp | 1 - src/support/types.h | 16 ---------------- 13 files changed, 54 insertions(+), 62 deletions(-) diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index d037fc67ff..66e829e437 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -283,11 +283,12 @@ public: */ VSpace defskip; PDFOptions pdfoptions; + BaseClassIndex baseClass_; }; BufferParams::Impl::Impl() - : defskip(VSpace::MEDSKIP) + : defskip(VSpace::MEDSKIP), baseClass_(0) { // set initial author // FIXME UNICODE @@ -462,8 +463,8 @@ string const BufferParams::readToken(Lexer & lex, string const & token, string const classname = lex.getString(); // if there exists a local layout file, ignore the system one // NOTE: in this case, the textclass (.cls file) is assumed to be available. - pair pp = - make_pair(false, textclass_type(0)); + pair pp = + make_pair(false, BaseClassIndex(0)); if (!filepath.empty()) pp = textclasslist.addTextClass( classname, filepath.absFilename()); @@ -677,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[baseClass_].name() << '\n'; + os << "\\textclass " << textclasslist[pimpl_->baseClass_].name() << '\n'; // then the preamble if (!preamble.empty()) { @@ -1343,7 +1344,7 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, void BufferParams::useClassDefaults() { - TextClass const & tclass = textclasslist[baseClass_]; + TextClass const & tclass = textclasslist[pimpl_->baseClass_]; sides = tclass.sides(); columns = tclass.columns(); @@ -1359,7 +1360,7 @@ void BufferParams::useClassDefaults() bool BufferParams::hasClassDefaults() const { - TextClass const & tclass = textclasslist[baseClass_]; + TextClass const & tclass = textclasslist[pimpl_->baseClass_]; return sides == tclass.sides() && columns == tclass.columns() @@ -1386,10 +1387,10 @@ void BufferParams::setTextClass(TextClassPtr tc) { } -bool BufferParams::setBaseClass(textclass_type tc) +bool BufferParams::setBaseClass(BaseClassIndex tc) { if (textclasslist[tc].load()) { - baseClass_ = tc; + pimpl_->baseClass_ = tc; return true; } @@ -1401,9 +1402,9 @@ bool BufferParams::setBaseClass(textclass_type tc) } -textclass_type BufferParams::baseClass() const +BaseClassIndex BufferParams::baseClass() const { - return baseClass_; + return pimpl_->baseClass_; } diff --git a/src/BufferParams.h b/src/BufferParams.h index 2a57dff066..279dfbe387 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -23,7 +23,6 @@ #include "insets/InsetQuotes.h" #include "support/copied_ptr.h" -#include "support/types.h" #include @@ -43,6 +42,7 @@ class LatexFeatures; class PDFOptions; class Spacing; class TextClass; +class BaseClassIndex; class TexRow; class VSpace; @@ -107,11 +107,11 @@ public: /// std::string fontsize; ///Get the LyX TextClass (that is, the layout file) this document is using. - textclass_type baseClass() const; + BaseClassIndex baseClass() const; /// Set the LyX TextClass (that is, the layout file) this document is using. /// NOTE: This does not call makeTextClass() to update the local TextClass. /// That needs to be done manually. - bool setBaseClass(textclass_type); + bool setBaseClass(BaseClassIndex); /// Adds the module information to the baseClass information to /// create our local TextClass. void makeTextClass(); @@ -327,8 +327,6 @@ private: /// for use with natbib biblio::CiteEngine cite_engine_; - /// the base TextClass associated with the document - textclass_type baseClass_; /// the possibly modular TextClass actually in use TextClassPtr textClass_; /// diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index e3ba435b03..5cfb521492 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -16,7 +16,6 @@ #include "TextClassPtr.h" -#include "support/types.h" #include "support/docstring.h" #include "frontends/Clipboard.h" diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 24a0b3c6cc..4443be2891 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -714,7 +714,7 @@ void showPrintError(string const & name) void loadTextClass(string const & name, string const & buf_path) { - pair const tc_pair = + pair const tc_pair = textclasslist.numberOfClass(name); if (!tc_pair.first) { @@ -724,7 +724,7 @@ void loadTextClass(string const & name, string const & buf_path) return; } - textclass_type const tc = tc_pair.second; + BaseClassIndex const tc = tc_pair.second; if (!textclasslist[tc].load(buf_path)) { docstring s = bformat(_("The document class %1$s." @@ -1607,14 +1607,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd) loadTextClass(argument, buffer->filePath()); - pair const tc_pair = + pair const tc_pair = textclasslist.numberOfClass(argument); if (!tc_pair.first) break; - textclass_type const old_class = buffer->params().baseClass(); - textclass_type const new_class = tc_pair.second; + BaseClassIndex const old_class = buffer->params().baseClass(); + BaseClassIndex const new_class = tc_pair.second; if (old_class == new_class) // nothing to do @@ -1634,7 +1634,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) BOOST_ASSERT(lyx_view_); Buffer * buffer = lyx_view_->buffer(); TextClassPtr oldClass = buffer->params().textClassPtr(); - textclass_type const tc = buffer->params().baseClass(); + BaseClassIndex const tc = buffer->params().baseClass(); textclasslist.reset(tc); buffer->params().setBaseClass(tc); buffer->params().makeTextClass(); diff --git a/src/TextClass.h b/src/TextClass.h index 07b4f16893..f7f4d1b11c 100644 --- a/src/TextClass.h +++ b/src/TextClass.h @@ -38,6 +38,21 @@ 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/TextClassList.cpp b/src/TextClassList.cpp index eb721bfc9c..87191b53b0 100644 --- a/src/TextClassList.cpp +++ b/src/TextClassList.cpp @@ -34,7 +34,7 @@ using boost::regex; using boost::smatch; // Gets textclass number from name -pair const +pair const TextClassList::numberOfClass(string const & textclass) const { ClassList::const_iterator cit = @@ -44,14 +44,14 @@ TextClassList::numberOfClass(string const & textclass) const textclass)); return cit != classlist_.end() ? - make_pair(true, textclass_type(cit - classlist_.begin())) : - make_pair(false, textclass_type(0)); + make_pair(true, BaseClassIndex(cit - classlist_.begin())) : + make_pair(false, BaseClassIndex(0)); } // Gets a textclass structure from number TextClass const & -TextClassList::operator[](textclass_type textclass) const +TextClassList::operator[](BaseClassIndex textclass) const { if (textclass >= classlist_.size()) return classlist_[0]; @@ -166,7 +166,7 @@ bool TextClassList::read() } -void TextClassList::reset(textclass_type const textclass) { +void TextClassList::reset(BaseClassIndex const textclass) { if (textclass >= classlist_.size()) return; TextClass const & tc = classlist_[textclass]; @@ -176,7 +176,7 @@ void TextClassList::reset(textclass_type const textclass) { } -pair const +pair const TextClassList::addTextClass(string const & textclass, string const & path) { // only check for textclass.layout file, .cls can be anywhere in $TEXINPUTS @@ -206,7 +206,7 @@ TextClassList::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 = + pair pp = textclasslist.numberOfClass(textclass); // only layouts from the same directory are considered to be identical. if (pp.first && classlist_[pp.second].description() == tmpl.description()) @@ -221,7 +221,7 @@ TextClassList::addTextClass(string const & textclass, string const & path) } } // If .layout is not in local directory, or an invalid layout is found, return false - return make_pair(false, textclass_type(0)); + return make_pair(false, BaseClassIndex(0)); } @@ -229,7 +229,7 @@ TextClassList::addTextClass(string const & textclass, string const & path) TextClassList textclasslist; -textclass_type defaultTextclass() +BaseClassIndex defaultTextclass() { // We want to return the article class. if `first' is // true in the returned pair, then `second' is the textclass diff --git a/src/TextClassList.h b/src/TextClassList.h index 8c1b3744d6..3b0870df40 100644 --- a/src/TextClassList.h +++ b/src/TextClassList.h @@ -15,7 +15,6 @@ #include "TextClass.h" #include "support/strfwd.h" -#include "support/types.h" #include @@ -44,26 +43,27 @@ public: bool empty() const { return classlist_.empty(); } /// Gets textclass number from name, -1 if textclass name does not exist - std::pair const - numberOfClass(std::string const & textclass) const; + std::pair const + numberOfClass(std::string const & textclass) const; /// - TextClass const & operator[](textclass_type textclass) const; + TextClass const & operator[](BaseClassIndex textclass) const; /// Read textclass list. Returns false if this fails. bool read(); /// Clears the textclass so as to force it to be reloaded - void reset(textclass_type const textclass); + void reset(BaseClassIndex const textclass); /// add a textclass from user local directory. /// Return ture/false, and textclass number - std::pair const - addTextClass(std::string const & textclass, std::string const & path); + std::pair const + addTextClass(std::string const & textclass, std::string const & path); private: /// noncopyable TextClassList(TextClassList const &); + /// nonassignable void operator=(TextClassList const &); /// @@ -73,7 +73,7 @@ private: /// extern TextClassList textclasslist; /// -textclass_type defaultTextclass(); +BaseClassIndex defaultTextclass(); } // namespace lyx diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 163d591f3e..bc5e201bbb 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -1212,7 +1212,7 @@ void GuiDocument::updatePagestyle(string const & items, string const & sel) void GuiDocument::classChanged() { - textclass_type const tc = latexModule->classCO->currentIndex(); + BaseClassIndex const tc = latexModule->classCO->currentIndex(); bp_.setBaseClass(tc); if (lyxrc.auto_reset_options) { if (applyPB->isEnabled()) { diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index bdcc026082..bc5dc1c4b0 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -21,8 +21,6 @@ #include "GuiIdListModel.h" #include "GuiSelectionManager.h" -#include "support/types.h" - #include "ui_DocumentUi.h" #include "ui_EmbeddedFilesUi.h" #include "ui_FontUi.h" diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index caca07c6ce..5168447a41 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -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 = textclasslist.numberOfClass(name_); setText(pp.first ? _("yes") : _("no"), bp.getFont(), false); break; diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 0101724cb1..9a75d67d36 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -17,8 +17,6 @@ #include "ColorCode.h" #include "Text.h" -#include "support/types.h" - #include namespace lyx { diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp index fb52f221d8..c89ca569d0 100644 --- a/src/output_docbook.cpp +++ b/src/output_docbook.cpp @@ -29,7 +29,6 @@ #include "support/convert.h" #include "support/debug.h" #include "support/lstrings.h" -#include "support/types.h" #include diff --git a/src/support/types.h b/src/support/types.h index 206d2818b1..94acd680ec 100644 --- a/src/support/types.h +++ b/src/support/types.h @@ -39,9 +39,6 @@ namespace lyx { /// a type for sizes typedef size_t size_type; - /// a type used for numbering text classes - typedef size_t textclass_type; - #else // These structs wrap simple things to make them distinguishible @@ -60,19 +57,6 @@ namespace lyx { base_type data_; }; - struct textclass_type { - /// - typedef size_t base_type; - /// - textclass_type(base_type t) { data_ = t; } - /// - operator base_type() const { return data_; } - /// - private: - base_type data_; - }; - - #endif /// -- 2.39.2