Encapsulate Converter class

Now members are not directly accessible anymore.
This commit is contained in:
Georg Baum 2014-12-07 18:35:28 +01:00
parent 25344de51d
commit c86f299a50
7 changed files with 168 additions and 131 deletions

View File

@ -3988,7 +3988,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
Graph::EdgePath::const_iterator it = path.begin();
Graph::EdgePath::const_iterator en = path.end();
for (; it != en; ++it)
if (theConverters().get(*it).nice) {
if (theConverters().get(*it).nice()) {
need_nice_file = true;
break;
}

View File

@ -85,7 +85,7 @@ public:
ConverterEqual(string const & from, string const & to)
: from_(from), to_(to) {}
bool operator()(Converter const & c) const {
return c.from == from_ && c.to == to_;
return c.from() == from_ && c.to() == to_;
}
private:
string const from_;
@ -97,39 +97,39 @@ private:
Converter::Converter(string const & f, string const & t,
string const & c, string const & l)
: from(f), to(t), command(c), flags(l),
From(0), To(0), latex(false), xml(false),
need_aux(false), nice(false)
: from_(f), to_(t), command_(c), flags_(l),
From_(0), To_(0), latex_(false), xml_(false),
need_aux_(false), nice_(false)
{}
void Converter::readFlags()
{
string flag_list(flags);
string flag_list(flags_);
while (!flag_list.empty()) {
string flag_name, flag_value;
flag_list = split(flag_list, flag_value, ',');
flag_value = split(flag_value, flag_name, '=');
if (flag_name == "latex") {
latex = true;
latex_flavor = flag_value.empty() ?
latex_ = true;
latex_flavor_ = flag_value.empty() ?
"latex" : flag_value;
} else if (flag_name == "xml")
xml = true;
xml_ = true;
else if (flag_name == "needaux")
need_aux = true;
need_aux_ = true;
else if (flag_name == "resultdir")
result_dir = (flag_value.empty())
result_dir_ = (flag_value.empty())
? token_base : flag_value;
else if (flag_name == "resultfile")
result_file = flag_value;
result_file_ = flag_value;
else if (flag_name == "parselog")
parselog = flag_value;
parselog_ = flag_value;
else if (flag_name == "nice")
nice = true;
nice_ = true;
}
if (!result_dir.empty() && result_file.empty())
result_file = "index." + formats.extension(to);
if (!result_dir_.empty() && result_file_.empty())
result_file_ = "index." + formats.extension(to_);
//if (!contains(command, token_from))
// latex = true;
}
@ -172,36 +172,36 @@ void Converters::add(string const & from, string const & to,
Converter converter(from, to, command, flags);
if (it != converterlist_.end() && !flags.empty() && flags[0] == '*') {
converter = *it;
converter.command = command;
converter.flags = flags;
converter.setCommand(command);
converter.setFlags(flags);
}
converter.readFlags();
// The latex_command is used to update the .aux file when running
// a converter that uses it.
if (converter.latex) {
if (converter.latex()) {
if (latex_command_.empty() ||
converter.latex_flavor == "latex")
converter.latex_flavor() == "latex")
latex_command_ = subst(command, token_from, "");
if (dvilualatex_command_.empty() ||
converter.latex_flavor == "dvilualatex")
converter.latex_flavor() == "dvilualatex")
dvilualatex_command_ = subst(command, token_from, "");
if (lualatex_command_.empty() ||
converter.latex_flavor == "lualatex")
converter.latex_flavor() == "lualatex")
lualatex_command_ = subst(command, token_from, "");
if (pdflatex_command_.empty() ||
converter.latex_flavor == "pdflatex")
converter.latex_flavor() == "pdflatex")
pdflatex_command_ = subst(command, token_from, "");
if (xelatex_command_.empty() ||
converter.latex_flavor == "xelatex")
converter.latex_flavor() == "xelatex")
xelatex_command_ = subst(command, token_from, "");
}
if (it == converterlist_.end()) {
converterlist_.push_back(converter);
} else {
converter.From = it->From;
converter.To = it->To;
converter.setFrom(it->From());
converter.setTo(it->To());
*it = converter;
}
}
@ -230,8 +230,8 @@ void Converters::update(Formats const & formats)
ConverterList::iterator it = converterlist_.begin();
ConverterList::iterator end = converterlist_.end();
for (; it != end; ++it) {
it->From = formats.getFormat(it->from);
it->To = formats.getFormat(it->to);
it->setFrom(formats.getFormat(it->from()));
it->setTo(formats.getFormat(it->to()));
}
}
@ -242,8 +242,8 @@ void Converters::updateLast(Formats const & formats)
{
if (converterlist_.begin() != converterlist_.end()) {
ConverterList::iterator it = converterlist_.end() - 1;
it->From = formats.getFormat(it->from);
it->To = formats.getFormat(it->to);
it->setFrom(formats.getFormat(it->from()));
it->setTo(formats.getFormat(it->to()));
}
}
@ -254,19 +254,19 @@ OutputParams::FLAVOR Converters::getFlavor(Graph::EdgePath const & path,
for (Graph::EdgePath::const_iterator cit = path.begin();
cit != path.end(); ++cit) {
Converter const & conv = converterlist_[*cit];
if (conv.latex) {
if (conv.latex_flavor == "latex")
if (conv.latex()) {
if (conv.latex_flavor() == "latex")
return OutputParams::LATEX;
if (conv.latex_flavor == "xelatex")
if (conv.latex_flavor() == "xelatex")
return OutputParams::XETEX;
if (conv.latex_flavor == "lualatex")
if (conv.latex_flavor() == "lualatex")
return OutputParams::LUATEX;
if (conv.latex_flavor == "dvilualatex")
if (conv.latex_flavor() == "dvilualatex")
return OutputParams::DVILUATEX;
if (conv.latex_flavor == "pdflatex")
if (conv.latex_flavor() == "pdflatex")
return OutputParams::PDFLATEX;
}
if (conv.xml)
if (conv.xml())
return OutputParams::XML;
}
return buffer ? buffer->params().getOutputFlavor()
@ -369,25 +369,25 @@ bool Converters::convert(Buffer const * buffer,
for (Graph::EdgePath::const_iterator cit = edgepath.begin();
cit != edgepath.end(); ++cit) {
Converter const & conv = converterlist_[*cit];
bool dummy = conv.To->dummy() && conv.to != "program";
bool dummy = conv.To()->dummy() && conv.to() != "program";
if (!dummy) {
LYXERR(Debug::FILES, "Converting from "
<< conv.from << " to " << conv.to);
<< conv.from() << " to " << conv.to());
}
infile = outfile;
outfile = FileName(conv.result_file.empty()
? changeExtension(from_file.absFileName(), conv.To->extension())
: addName(subst(conv.result_dir,
outfile = FileName(conv.result_file().empty()
? changeExtension(from_file.absFileName(), conv.To()->extension())
: addName(subst(conv.result_dir(),
token_base, from_base),
subst(conv.result_file,
subst(conv.result_file(),
token_base, onlyFileName(from_base))));
// if input and output files are equal, we use a
// temporary file as intermediary (JMarc)
FileName real_outfile;
if (!conv.result_file.empty())
if (!conv.result_file().empty())
real_outfile = FileName(changeExtension(from_file.absFileName(),
conv.To->extension()));
conv.To()->extension()));
if (outfile == infile) {
real_outfile = infile;
// when importing, a buffer does not necessarily exist
@ -398,9 +398,9 @@ bool Converters::convert(Buffer const * buffer,
"tmpfile.out"));
}
if (conv.latex) {
if (conv.latex()) {
run_latex = true;
string command = conv.command;
string command = conv.command();
command = subst(command, token_from, "");
command = subst(command, token_latex_encoding, buffer ?
buffer->params().encoding().latexName() : string());
@ -408,7 +408,7 @@ bool Converters::convert(Buffer const * buffer,
if (!runLaTeX(*buffer, command, runparams, errorList))
return false;
} else {
if (conv.need_aux && !run_latex) {
if (conv.need_aux() && !run_latex) {
string command;
switch (runparams.flavor) {
case OutputParams::DVILUATEX:
@ -443,7 +443,7 @@ bool Converters::convert(Buffer const * buffer,
string const outfile2 =
to_utf8(makeRelPath(from_utf8(outfile.absFileName()), from_utf8(path)));
string command = conv.command;
string command = conv.command();
command = subst(command, token_from, quoteName(infile2));
command = subst(command, token_base, quoteName(from_base));
command = subst(command, token_to, quoteName(outfile2));
@ -452,13 +452,13 @@ bool Converters::convert(Buffer const * buffer,
command = subst(command, token_orig_from, quoteName(onlyFileName(orig_from.absFileName())));
command = subst(command, token_encoding, buffer ? buffer->params().encoding().iconvName() : string());
if (!conv.parselog.empty())
if (!conv.parselog().empty())
command += " 2> " + quoteName(infile2 + ".out");
if (conv.from == "dvi" && conv.to == "ps")
if (conv.from() == "dvi" && conv.to() == "ps")
command = add_options(command,
buffer->params().dvips_options());
else if (conv.from == "dvi" && prefixIs(conv.to, "pdf"))
else if (conv.from() == "dvi" && prefixIs(conv.to(), "pdf"))
command = add_options(command,
dvipdfm_options(buffer->params()));
@ -481,7 +481,7 @@ bool Converters::convert(Buffer const * buffer,
buffer ? buffer->filePath()
: string());
if (!real_outfile.empty()) {
Mover const & mover = getMover(conv.to);
Mover const & mover = getMover(conv.to());
if (!mover.rename(outfile, real_outfile))
res = -1;
else
@ -491,10 +491,10 @@ bool Converters::convert(Buffer const * buffer,
// converters to use the renamed file...
outfile = real_outfile;
}
if (!conv.parselog.empty()) {
if (!conv.parselog().empty()) {
string const logfile = infile2 + ".log";
string const command2 = conv.parselog +
string const command2 = conv.parselog() +
" < " + quoteName(infile2 + ".out") +
" > " + quoteName(logfile);
one.startscript(Systemcall::Wait,
@ -506,7 +506,7 @@ bool Converters::convert(Buffer const * buffer,
}
if (res) {
if (conv.to == "program") {
if (conv.to() == "program") {
Alert::error(_("Build errors"),
_("There were errors during the build process."));
} else {
@ -522,18 +522,18 @@ bool Converters::convert(Buffer const * buffer,
}
Converter const & conv = converterlist_[edgepath.back()];
if (conv.To->dummy())
if (conv.To()->dummy())
return true;
if (!conv.result_dir.empty()) {
if (!conv.result_dir().empty()) {
// The converter has put the file(s) in a directory.
// In this case we ignore the given to_file.
if (from_base != to_base) {
string const from = subst(conv.result_dir,
string const from = subst(conv.result_dir(),
token_base, from_base);
string const to = subst(conv.result_dir,
string const to = subst(conv.result_dir(),
token_base, to_base);
Mover const & mover = getMover(conv.from);
Mover const & mover = getMover(conv.from());
if (!mover.rename(FileName(from), FileName(to))) {
Alert::error(_("Cannot convert file"),
bformat(_("Could not move a temporary directory from %1$s to %2$s."),
@ -545,7 +545,7 @@ bool Converters::convert(Buffer const * buffer,
} else {
if (conversionflags & try_cache)
ConverterCache::get().add(orig_from, to_format, outfile);
return move(conv.to, outfile, to_file, conv.latex);
return move(conv.to(), outfile, to_file, conv.latex());
}
}
@ -596,7 +596,7 @@ bool Converters::formatIsUsed(string const & format)
ConverterList::const_iterator cit = converterlist_.begin();
ConverterList::const_iterator end = converterlist_.end();
for (; cit != end; ++cit) {
if (cit->from == format || cit->to == format)
if (cit->from() == format || cit->to() == format)
return true;
}
return false;
@ -682,13 +682,13 @@ void Converters::buildGraph()
// clear graph's data structures
G_.init(formats.size());
// each of the converters knows how to convert one format to another
// so, for each of them, we create an arrow on the graph, going from
// so, for each of them, we create an arrow on the graph, going from
// the one to the other
ConverterList::iterator it = converterlist_.begin();
ConverterList::iterator const end = converterlist_.end();
for (; it != end ; ++it) {
int const from = formats.getNumber(it->from);
int const to = formats.getNumber(it->to);
int const from = formats.getNumber(it->from());
int const to = formats.getNumber(it->to());
G_.addEdge(from, to);
}
}

View File

@ -40,36 +40,73 @@ public:
///
void readFlags();
///
std::string from;
std::string const & from() const { return from_; }
///
std::string to;
std::string const & to() const { return to_; }
///
std::string command;
std::string const & command() const { return command_; }
///
std::string flags;
void setCommand(std::string const & command) { command_ = command; }
///
Format const * From;
std::string const & flags() const { return flags_; }
///
Format const * To;
void setFlags(std::string const & flags) { flags_ = flags; }
///
Format const * From() const { return From_; }
///
void setFrom(Format const * From) { From_ = From; }
///
void setTo(Format const * To) { To_ = To; }
///
Format const * To() const { return To_; }
///
bool latex() const { return latex_; }
///
std::string const & latex_flavor() const { return latex_flavor_; }
///
bool xml() const { return xml_; }
///
bool need_aux() const { return need_aux_; }
///
bool nice() const { return nice_; }
///
std::string const & result_dir() const { return result_dir_; }
///
std::string const & result_file() const { return result_file_; }
///
std::string const & parselog() const { return parselog_; }
private:
///
std::string from_;
///
std::string to_;
///
std::string command_;
///
std::string flags_;
///
Format const * From_;
///
Format const * To_;
/// The converter is latex or its derivatives
bool latex;
bool latex_;
/// The latex derivate
std::string latex_flavor;
std::string latex_flavor_;
/// The converter is xml
bool xml;
bool xml_;
/// This converter needs the .aux files
bool need_aux;
bool need_aux_;
/// we need a "nice" file from the backend, c.f. OutputParams.nice.
bool nice;
bool nice_;
/// If the converter put the result in a directory, then result_dir
/// is the name of the directory
std::string result_dir;
std::string result_dir_;
/// If the converter put the result in a directory, then result_file
/// is the name of the main file in that directory
std::string result_file;
std::string result_file_;
/// Command to convert the program output to a LaTeX log file format
std::string parselog;
std::string parselog_;
};

View File

@ -2330,7 +2330,7 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
}
if (tag != RC_LAST)
break;
case RC_NUMLASTFILES:
if (ignore_system_lyxrc ||
num_lastfiles != system_lyxrc.num_lastfiles) {
@ -2830,23 +2830,23 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
for (Converters::const_iterator cit = theConverters().begin();
cit != theConverters().end(); ++cit) {
Converter const * converter =
theSystemConverters().getConverter(cit->from,
cit->to);
theSystemConverters().getConverter(cit->from(),
cit->to());
if (!converter ||
converter->command != cit->command ||
converter->flags != cit->flags)
os << "\\converter \"" << cit->from << "\" \""
<< cit->to << "\" \""
<< escapeCommand(cit->command) << "\" \""
<< cit->flags << "\"\n";
converter->command() != cit->command() ||
converter->flags() != cit->flags())
os << "\\converter \"" << cit->from() << "\" \""
<< cit->to() << "\" \""
<< escapeCommand(cit->command()) << "\" \""
<< cit->flags() << "\"\n";
}
// New/modifed converters
for (Converters::const_iterator cit = theSystemConverters().begin();
cit != theSystemConverters().end(); ++cit)
if (!theConverters().getConverter(cit->from, cit->to))
os << "\\converter \"" << cit->from
<< "\" \"" << cit->to << "\" \"\" \"\"\n";
if (!theConverters().getConverter(cit->from(), cit->to()))
os << "\\converter \"" << cit->from()
<< "\" \"" << cit->to() << "\" \"\" \"\"\n";
if (tag != RC_LAST)
break;

View File

@ -232,7 +232,7 @@ QString browseRelToSub(QString const & filename, QString const & relpath,
QString testname = reloutname;
testname.remove(QRegExp("^(\\.\\./)+"));
if (testname.contains("/"))
return outname;
else
@ -600,8 +600,8 @@ void PrefInput::on_scrollzoomEnableCB_toggled(bool enabled)
{
scrollzoomValueCO->setEnabled(enabled);
}
/////////////////////////////////////////////////////////////////////
//
// PrefCompletion
@ -1097,7 +1097,7 @@ namespace {
struct ColorSorter
{
bool operator()(ColorCode lhs, ColorCode rhs) const {
return
return
compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
}
};
@ -1541,12 +1541,12 @@ void PrefSpellchecker::update(LyXRC const & rc)
void PrefSpellchecker::on_spellcheckerCB_currentIndexChanged(int index)
{
QString spellchecker = spellcheckerCB->itemData(index).toString();
compoundWordCB->setEnabled(spellchecker == QString("aspell"));
}
/////////////////////////////////////////////////////////////////////
//
// PrefConverters
@ -1634,8 +1634,8 @@ void PrefConverters::updateGui()
Converters::const_iterator cend = form_->converters().end();
for (; ccit != cend; ++ccit) {
QString const name =
qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
qt_(ccit->From()->prettyname()) + " -> " + qt_(ccit->To()->prettyname());
int type = form_->converters().getNumber(ccit->From()->name(), ccit->To()->name());
new QListWidgetItem(name, convertersLW, type);
}
convertersLW->sortItems(Qt::AscendingOrder);
@ -1661,10 +1661,10 @@ void PrefConverters::switchConverter()
{
int const cnr = convertersLW->currentItem()->type();
Converter const & c(form_->converters().get(cnr));
converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
converterED->setText(toqstr(c.command));
converterFlagED->setText(toqstr(c.flags));
converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from()));
converterToCO->setCurrentIndex(form_->formats().getNumber(c.to()));
converterED->setText(toqstr(c.command()));
converterFlagED->setText(toqstr(c.flags()));
updateButtons();
}
@ -1693,8 +1693,8 @@ void PrefConverters::updateButtons()
if (convertersLW->count() > 0) {
int const cnr = convertersLW->currentItem()->type();
Converter const & c = form_->converters().get(cnr);
old_command = c.command;
old_flag = c.flags;
old_command = c.command();
old_flag = c.flags();
}
string const new_command = fromqstr(converterED->text());
@ -2133,13 +2133,13 @@ namespace {
void updateComboBox(LyXRC::Alternatives const & alts,
string const & fmt, QComboBox * combo)
{
LyXRC::Alternatives::const_iterator it =
LyXRC::Alternatives::const_iterator it =
alts.find(fmt);
if (it != alts.end()) {
LyXRC::CommandSet const & cmds = it->second;
LyXRC::CommandSet::const_iterator sit =
LyXRC::CommandSet::const_iterator sit =
cmds.begin();
LyXRC::CommandSet::const_iterator const sen =
LyXRC::CommandSet::const_iterator const sen =
cmds.end();
for (; sit != sen; ++sit) {
QString const qcmd = toqstr(*sit);
@ -2316,7 +2316,7 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
if (!lang)
continue;
// never remove the currently selected language
if (name != form->rc().gui_language
if (name != form->rc().gui_language
&& name != lyxrc.gui_language
&& (!Messages::available(lang->code())
|| added.find(lang->code()) != added.end()))
@ -3004,7 +3004,7 @@ void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
if (items.isEmpty())
return;
KeyMap::ItemType tag =
KeyMap::ItemType tag =
static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
if (tag == KeyMap::UserUnbind)
removePB->setText(qt_("Res&tore"));
@ -3044,7 +3044,7 @@ void PrefShortcuts::removeShortcut()
string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
string lfun = fromqstr(items[i]->text(0));
FuncRequest func = lyxaction.lookupFunc(lfun);
KeyMap::ItemType tag =
KeyMap::ItemType tag =
static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
switch (tag) {
@ -3183,7 +3183,7 @@ void PrefShortcuts::shortcutOkPressed()
if (oldBinding == func)
// nothing has changed
return;
// make sure this key isn't already bound---and, if so, prompt user
FuncCode const unbind = user_unbind_.getBinding(k).action();
docstring const action_string = makeCmdString(oldBinding);
@ -3330,7 +3330,7 @@ GuiPreferences::GuiPreferences(GuiView & lv)
addModule(new PrefSpellchecker(this));
//for strftime validator
PrefOutput * output = new PrefOutput(this);
PrefOutput * output = new PrefOutput(this);
addModule(output);
addModule(new PrefPrinter(this));
addModule(new PrefLatex(this));
@ -3409,11 +3409,11 @@ bool GuiPreferences::initialiseParams(string const &)
movers_ = theMovers();
colors_.clear();
update_screen_font_ = false;
updateRc(rc_);
// Make sure that the bc is in the INITIAL state
if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
bc().restore();
// Make sure that the bc is in the INITIAL state
if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
bc().restore();
return true;
}
@ -3429,7 +3429,7 @@ void GuiPreferences::dispatchParams()
prefsApplied(rc_);
// FIXME: these need lfuns
// FIXME UNICODE
Author const & author =
Author const & author =
Author(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
theBufferList().recordCurrentAuthor(author);

View File

@ -356,16 +356,16 @@ static void build_script(string const & from_file,
// Build the conversion command
string const infile = outfile;
string const infile_base = changeExtension(infile, string());
outfile = conv.result_file.empty()
? addExtension(to_base, conv.To->extension())
: addName(subst(conv.result_dir,
outfile = conv.result_file().empty()
? addExtension(to_base, conv.To()->extension())
: addName(subst(conv.result_dir(),
token_base, infile_base),
subst(conv.result_file,
subst(conv.result_file(),
token_base, onlyFileName(infile_base)));
// If two formats share the same extension we may get identical names
if (outfile == infile && conv.result_file.empty()) {
TempFile tempfile(addExtension("gconvertXXXXXX", conv.To->extension()));
if (outfile == infile && conv.result_file().empty()) {
TempFile tempfile(addExtension("gconvertXXXXXX", conv.To()->extension()));
tempfile.setAutoRemove(false);
outfile = tempfile.name().toFilesystemEncoding();
}
@ -381,7 +381,7 @@ static void build_script(string const & from_file,
// See comment about extra " quotes above (although that
// applies only for the first loop run here).
string command = conv.command;
string command = conv.command();
command = subst(command, token_from, "' + '\"' + infile + '\"' + '");
command = subst(command, token_base, "' + '\"' + infile_base + '\"' + '");
command = subst(command, token_to, "' + '\"' + outfile + '\"' + '");

View File

@ -538,7 +538,7 @@ void PreviewLoader::Impl::startLoading(bool wait)
// Create an InProgress instance to place in the map of all
// such processes if it starts correctly.
InProgress inprogress(filename_base, pending_, pconverter_->to);
InProgress inprogress(filename_base, pending_, pconverter_->to());
// clear pending_, so we're ready to start afresh.
pending_.clear();
@ -585,7 +585,7 @@ void PreviewLoader::Impl::startLoading(bool wait)
// The conversion command.
ostringstream cs;
cs << pconverter_->command
cs << pconverter_->command()
<< " " << quoteName(latexfile.toFilesystemEncoding())
<< " --dpi " << int(font_scaling_factor);