* mover.h

- SpecialisedMover(): add virtual destructor (fix bug 2916)
  - Movers: rename iterator to const_iterator.
  - theMovers(), theSystemMovers(), getMover(), setMover(): new extern definitions.

* mover.C: 
  - SpecialisedMover::operator(): get rid of bogus MSVC warning.
  - delete global variable movers and system_movers.

* lyx_main.C:
  - LyX::Singletons: new movers_ ans system_movers members.
  - implement Movers access functions.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16743 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-01-18 08:42:53 +00:00
parent 8f7b5e4952
commit 3d2184730a
12 changed files with 73 additions and 30 deletions

View File

@ -226,7 +226,7 @@ void ConverterCache::add(FileName const & orig_from, string const & to_format,
CacheItem * item = pimpl_->find(orig_from, to_format);
time_t const timestamp = fs::last_write_time(orig_from.toFilesystemEncoding());
Mover const & mover = movers(to_format);
Mover const & mover = getMover(to_format);
if (item) {
lyxerr[Debug::FILES] << "ConverterCache::add(" << orig_from << "):\n"
"The file is already in the cache."
@ -337,7 +337,7 @@ bool ConverterCache::copy(FileName const & orig_from, string const & to_format,
CacheItem * const item = pimpl_->find(orig_from, to_format);
BOOST_ASSERT(item);
Mover const & mover = movers(to_format);
Mover const & mover = getMover(to_format);
return mover.copy(item->cache_name, dest);
}

View File

@ -431,7 +431,7 @@ bool Converters::convert(Buffer const * buffer,
res = one.startscript(type, command);
if (!real_outfile.empty()) {
Mover const & mover = movers(conv.to);
Mover const & mover = getMover(conv.to);
if (!mover.rename(outfile, real_outfile))
res = -1;
else
@ -483,7 +483,7 @@ bool Converters::convert(Buffer const * buffer,
token_base, from_base);
string const to = subst(conv.result_dir,
token_base, to_base);
Mover const & mover = movers(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."),
@ -525,7 +525,7 @@ bool Converters::move(string const & fmt,
lyxerr[Debug::FILES] << "moving " << from2
<< " to " << to2 << endl;
Mover const & mover = movers(fmt);
Mover const & mover = getMover(fmt);
bool const moved = copy
? mover.copy(*it, FileName(to2))
: mover.rename(*it, FileName(to2));

View File

@ -132,7 +132,7 @@ CopyStatus copyFile(string const & format,
}
}
Mover const & mover = movers(format);
Mover const & mover = getMover(format);
if (!mover.copy(sourceFile, destFile, latexFile))
Alert::error(_("Couldn't copy file"),
bformat(_("Copying %1$s to %2$s failed."),

View File

@ -50,7 +50,7 @@ bool ControlPrefs::initialiseParams(std::string const &)
formats_ = lyx::formats;
converters_ = theConverters();
converters_.update(formats_);
movers_ = lyx::movers;
movers_ = theMovers();
colors_.clear();
update_screen_font_ = false;
@ -74,7 +74,7 @@ void ControlPrefs::dispatchParams()
theConverters().update(lyx::formats);
theConverters().buildGraph();
lyx::movers = movers_;
theMovers() = movers_;
vector<string>::const_iterator it = colors_.begin();
vector<string>::const_iterator const end = colors_.end();

View File

@ -1066,7 +1066,7 @@ void PrefCopiers::update()
// The browser widget
AllCopiersLW->clear();
for (Movers::iterator it = form_->movers().begin(),
for (Movers::const_iterator it = form_->movers().begin(),
end = form_->movers().end();
it != end; ++it) {
std::string const & command = it->second.command();

View File

@ -252,7 +252,7 @@ void updateExternal(InsetExternalParams const & params,
unsigned long const temp_checksum = support::sum(temp_file);
if (from_checksum != temp_checksum) {
Mover const & mover = movers(from_format);
Mover const & mover = getMover(from_format);
if (!mover.copy(params.filename, temp_file)) {
lyxerr[Debug::EXTERNAL]
<< "external::updateExternal. "

View File

@ -464,7 +464,7 @@ copyFileIfNeeded(FileName const & file_in, FileName const & file_out)
// Nothing to do...
return std::make_pair(IDENTICAL_CONTENTS, file_out);
Mover const & mover = movers(formats.getFormatFromFile(file_in));
Mover const & mover = getMover(formats.getFormatFromFile(file_in));
bool const success = mover.copy(file_in, file_out);
if (!success) {
// FIXME UNICODE

View File

@ -184,6 +184,12 @@ struct LyX::Singletons
// The system converters copy after reading lyxrc.defaults.
Converters system_converters_;
///
Movers movers_;
///
Movers system_movers_;
};
///
@ -857,7 +863,7 @@ bool LyX::init()
system_lyxrc = lyxrc;
system_formats = formats;
pimpl_->system_converters_ = pimpl_->converters_;
system_movers = movers;
pimpl_->system_movers_ = pimpl_->movers_;
system_lcolor = lcolor;
// This one is edited through the preferences dialog.
@ -1472,6 +1478,30 @@ Converters & theSystemConverters()
}
Movers & theMovers()
{
return LyX::ref().pimpl_->movers_;
}
Mover const & getMover(std::string const & fmt)
{
return LyX::ref().pimpl_->movers_(fmt);
}
void setMover(std::string const & fmt, std::string const & command)
{
LyX::ref().pimpl_->movers_.set(fmt, command);
}
Movers & theSystemMovers()
{
return LyX::ref().pimpl_->system_movers_;
}
IconvProcessor & utf8ToUcs4()
{
return LyX::ref().iconvProcessor();

View File

@ -32,6 +32,8 @@ class LyXServer;
class LyXServerSocket;
class LyXView;
class Messages;
class Mover;
class Movers;
class Session;
class kb_keymap;
@ -162,6 +164,11 @@ private:
/// Use the Pimpl idiom to hide the internals.
struct Singletons;
boost::scoped_ptr<Singletons> pimpl_;
friend Movers & theMovers();
friend Mover const & getMover(std::string const & fmt);
friend void setMover(std::string const & fmt, std::string const & command);
friend Movers & theSystemMovers();
};
} // namespace lyx

View File

@ -1033,7 +1033,7 @@ int LyXRC::read(LyXLex & lexrc)
if (lexrc.next()) {
command = lexrc.getString();
}
movers.set(fmt, command);
setMover(fmt, command);
break;
}
@ -2111,12 +2111,13 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
<< "#\n\n";
// Look for new movers
Movers::iterator const sysbegin = system_movers.begin();
Movers::iterator const sysend = system_movers.end();
Movers::const_iterator const sysbegin = theSystemMovers().begin();
Movers::const_iterator const sysend = theSystemMovers().end();
Movers::const_iterator it = theMovers().begin();
Movers::const_iterator end = theMovers().end();
for (Movers::iterator it = movers.begin(), end = movers.end();
it != end; ++it) {
Movers::iterator const sysit =
for (; it != end; ++it) {
Movers::const_iterator const sysit =
std::find_if(sysbegin, sysend, SameMover(*it));
if (sysit == sysend) {
std::string const & fmt = it->first;

View File

@ -20,15 +20,10 @@
#include <fstream>
#include <sstream>
namespace lyx {
using std::ios;
using std::string;
Movers movers;
Movers system_movers;
namespace lyx {
bool Mover::copy(support::FileName const & from, support::FileName const & to,
unsigned long int mode) const
@ -104,7 +99,9 @@ void Movers::set(string const & fmt, string const & command)
Mover const & Movers::operator()(string const & fmt) const
{
SpecialsMap::const_iterator const it = specials_.find(fmt);
return (it == specials_.end()) ? default_ : it->second;
if (it == specials_.end())
return default_;
return it->second;
}

View File

@ -104,6 +104,8 @@ class SpecialisedMover : public Mover
public:
SpecialisedMover() {}
virtual ~SpecialisedMover() {}
/** @c command should be of the form
* <code>
* python $$s/scripts/fig_copy.py $$i $$o $$l
@ -162,9 +164,9 @@ private:
typedef std::map<std::string, SpecialisedMover> SpecialsMap;
public:
typedef SpecialsMap::const_iterator iterator;
iterator begin() const { return specials_.begin(); }
iterator end() const { return specials_.end(); }
typedef SpecialsMap::const_iterator const_iterator;
const_iterator begin() const { return specials_.begin(); }
const_iterator end() const { return specials_.end(); }
private:
Mover default_;
@ -172,8 +174,14 @@ private:
};
extern Movers movers;
extern Movers system_movers;
extern Movers & theMovers();
/// @c returns the Mover registered for format @c fmt.
extern Mover const & getMover(std::string const & fmt);
/** Register a specialised @c command to be used to copy a file
* of format @c fmt.
*/
extern void setMover(std::string const & fmt, std::string const & command);
extern Movers & theSystemMovers();
} // namespace lyx