From 3d2184730a436d56dd4e3ddad1f067d8bb14200e Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 18 Jan 2007 08:42:53 +0000 Subject: [PATCH] * 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 --- src/ConverterCache.C | 4 +-- src/converter.C | 6 ++--- src/exporter.C | 2 +- src/frontends/controllers/ControlPrefs.C | 4 +-- src/frontends/qt4/QPrefsDialog.C | 2 +- src/insets/ExternalSupport.C | 2 +- src/insets/insetgraphics.C | 2 +- src/lyx_main.C | 32 +++++++++++++++++++++++- src/lyx_main.h | 7 ++++++ src/lyxrc.C | 13 +++++----- src/mover.C | 11 +++----- src/mover.h | 18 +++++++++---- 12 files changed, 73 insertions(+), 30 deletions(-) diff --git a/src/ConverterCache.C b/src/ConverterCache.C index b5e0c12d8c..6441e651eb 100644 --- a/src/ConverterCache.C +++ b/src/ConverterCache.C @@ -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); } diff --git a/src/converter.C b/src/converter.C index cfdf54ba01..0cea5a852f 100644 --- a/src/converter.C +++ b/src/converter.C @@ -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)); diff --git a/src/exporter.C b/src/exporter.C index 6121131b53..d5c0fe41f4 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -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."), diff --git a/src/frontends/controllers/ControlPrefs.C b/src/frontends/controllers/ControlPrefs.C index bdfd0a1e50..17a2538c0a 100644 --- a/src/frontends/controllers/ControlPrefs.C +++ b/src/frontends/controllers/ControlPrefs.C @@ -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::const_iterator it = colors_.begin(); vector::const_iterator const end = colors_.end(); diff --git a/src/frontends/qt4/QPrefsDialog.C b/src/frontends/qt4/QPrefsDialog.C index 5b6127dc5e..17dcf8d5c5 100644 --- a/src/frontends/qt4/QPrefsDialog.C +++ b/src/frontends/qt4/QPrefsDialog.C @@ -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(); diff --git a/src/insets/ExternalSupport.C b/src/insets/ExternalSupport.C index fd3727242e..d84baf7506 100644 --- a/src/insets/ExternalSupport.C +++ b/src/insets/ExternalSupport.C @@ -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. " diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 8f527bd701..56d990bda0 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -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 diff --git a/src/lyx_main.C b/src/lyx_main.C index 95b1a85772..f274ae189c 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -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(); diff --git a/src/lyx_main.h b/src/lyx_main.h index 78427b7573..a1887887cc 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -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 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 diff --git a/src/lyxrc.C b/src/lyxrc.C index 6c204543c1..96a82dc106 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -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; diff --git a/src/mover.C b/src/mover.C index 52c9d00648..f21d94fbc0 100644 --- a/src/mover.C +++ b/src/mover.C @@ -20,15 +20,10 @@ #include #include - -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; } diff --git a/src/mover.h b/src/mover.h index 1e4666ec53..79a6a01f99 100644 --- a/src/mover.h +++ b/src/mover.h @@ -104,6 +104,8 @@ class SpecialisedMover : public Mover public: SpecialisedMover() {} + virtual ~SpecialisedMover() {} + /** @c command should be of the form * * python $$s/scripts/fig_copy.py $$i $$o $$l @@ -162,9 +164,9 @@ private: typedef std::map 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 -- 2.39.5