baseclasslist --> BaseClassList singleton. Prep for further type safety.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23322 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2008-02-28 14:49:01 +00:00
parent 5d0e49d4dc
commit 224e6ad0a3
7 changed files with 32 additions and 27 deletions

View File

@ -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<bool, BaseClassIndex> 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<bool, lyx::BaseClassIndex> pp =
baseclasslist.numberOfClass(textclass);
pair<bool, lyx::BaseClassIndex> 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;

View File

@ -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<TextClass> ClassList;
///
@ -84,8 +88,6 @@ private:
mutable ClassList classlist_;
};
///
extern BaseClassList baseclasslist;
///
BaseClassIndex defaultBaseclass();

View File

@ -466,12 +466,12 @@ string const BufferParams::readToken(Lexer & lex, string const & token,
pair<bool, lyx::BaseClassIndex> 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

View File

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

View File

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

View File

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

View File

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