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
This commit is contained in:
Richard Heck 2008-02-24 16:59:49 +00:00
parent 69de04feac
commit 4c6180d209
16 changed files with 75 additions and 75 deletions

View File

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

View File

@ -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 <config.h>
#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<bool, BaseClassIndex> 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<bool, BaseClassIndex> 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<bool, lyx::BaseClassIndex> 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;

View File

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

View File

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

View File

@ -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<bool, lyx::BaseClassIndex> 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

View File

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

View File

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

View File

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

View File

@ -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<bool, BaseClassIndex> 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<bool, BaseClassIndex> 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);

View File

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

View File

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

View File

@ -38,21 +38,6 @@ 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

@ -12,6 +12,7 @@
#include <config.h>
#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"

View File

@ -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<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
TextClass const & GuiDocument::textClass() const
{
return textclasslist[bp_.baseClass()];
return baseclasslist[bp_.baseClass()];
}

View File

@ -14,6 +14,7 @@
#include "InsetInclude.h"
#include "BaseClassList.h"
#include "Buffer.h"
#include "buffer_funcs.h"
#include "BufferList.h"

View File

@ -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<bool, lyx::BaseClassIndex> pp = textclasslist.numberOfClass(name_);
pair<bool, lyx::BaseClassIndex> pp = baseclasslist.numberOfClass(name_);
setText(pp.first ? _("yes") : _("no"),
bp.getFont(), false);
break;