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
This commit is contained in:
Richard Heck 2008-02-24 16:29:40 +00:00
parent 5f18e5ea81
commit 69de04feac
13 changed files with 54 additions and 62 deletions

View File

@ -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<bool, lyx::textclass_type> pp =
make_pair(false, textclass_type(0));
pair<bool, lyx::BaseClassIndex> 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_;
}

View File

@ -23,7 +23,6 @@
#include "insets/InsetQuotes.h"
#include "support/copied_ptr.h"
#include "support/types.h"
#include <vector>
@ -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_;
///

View File

@ -16,7 +16,6 @@
#include "TextClassPtr.h"
#include "support/types.h"
#include "support/docstring.h"
#include "frontends/Clipboard.h"

View File

@ -714,7 +714,7 @@ void showPrintError(string const & name)
void loadTextClass(string const & name, string const & buf_path)
{
pair<bool, textclass_type> const tc_pair =
pair<bool, BaseClassIndex> 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<bool, textclass_type> const tc_pair =
pair<bool, BaseClassIndex> 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();

View File

@ -38,6 +38,21 @@ class FloatList;
/// List of inset layouts
typedef std::map<docstring, InsetLayout> 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:

View File

@ -34,7 +34,7 @@ using boost::regex;
using boost::smatch;
// Gets textclass number from name
pair<bool, textclass_type> const
pair<bool, BaseClassIndex> 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<bool, textclass_type> const
pair<bool, BaseClassIndex> 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<bool, lyx::textclass_type> pp =
pair<bool, lyx::BaseClassIndex> 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

View File

@ -15,7 +15,6 @@
#include "TextClass.h"
#include "support/strfwd.h"
#include "support/types.h"
#include <vector>
@ -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<bool, textclass_type> const
numberOfClass(std::string const & textclass) const;
std::pair<bool, BaseClassIndex> 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<bool, textclass_type> const
addTextClass(std::string const & textclass, std::string const & path);
std::pair<bool, BaseClassIndex> 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

View File

@ -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()) {

View File

@ -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"

View File

@ -202,7 +202,7 @@ void InsetInfo::updateInfo(Buffer const & buf)
break;
case TEXTCLASS_INFO: {
// name_ is the class name
pair<bool, lyx::textclass_type> pp = textclasslist.numberOfClass(name_);
pair<bool, lyx::BaseClassIndex> pp = textclasslist.numberOfClass(name_);
setText(pp.first ? _("yes") : _("no"),
bp.getFont(), false);
break;

View File

@ -17,8 +17,6 @@
#include "ColorCode.h"
#include "Text.h"
#include "support/types.h"
#include <set>
namespace lyx {

View File

@ -29,7 +29,6 @@
#include "support/convert.h"
#include "support/debug.h"
#include "support/lstrings.h"
#include "support/types.h"
#include <boost/next_prior.hpp>

View File

@ -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
///