]> git.lyx.org Git - features.git/commitdiff
* mover.h
authorAbdelrazak Younes <younes@lyx.org>
Thu, 18 Jan 2007 08:42:53 +0000 (08:42 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Thu, 18 Jan 2007 08:42:53 +0000 (08:42 +0000)
  - 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

12 files changed:
src/ConverterCache.C
src/converter.C
src/exporter.C
src/frontends/controllers/ControlPrefs.C
src/frontends/qt4/QPrefsDialog.C
src/insets/ExternalSupport.C
src/insets/insetgraphics.C
src/lyx_main.C
src/lyx_main.h
src/lyxrc.C
src/mover.C
src/mover.h

index b5e0c12d8cdc2323f81333bebac75b53e2292847..6441e651ebfc7b47bfc97a9c632c3bec6c66ed2e 100644 (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);
 }
 
index cfdf54ba016ed7ce8f37140195f0207ed20d885b..0cea5a852f7819faf05e088bafebad38f39494b1 100644 (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));
index 6121131b53959a44eaf3a40d0e6a97dac793d9ab..d5c0fe41f4bf126e87b3b3eb5cace6b32e7a549e 100644 (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."),
index bdfd0a1e50763000f0f8470796d1857ea485aa51..17a2538c0a960c7e0e0cf5797e35a1dc7d37e3e4 100644 (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();
index 5b6127dc5e58a1bcb6c2360d1e10a4144747e4ed..17dcf8d5c50e2fc1f7b6e4dc8b7beae8376198eb 100644 (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();
index fd3727242e8f8168c7d5f366a44d9a41121509f9..d84baf75069b5a48e9ec22d0d8544259387f86d4 100644 (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. "
index 8f527bd701870f33cd0c5037544108b40de3f658..56d990bda04622110fd3bbeac131ce8b7aee81cb 100644 (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
index 95b1a857723c7c8e979af4f2e652596d5f9a3e7e..f274ae189cbb1bd5d36ce05faead8b1c1f033913 100644 (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();
index 78427b757300e4be690209894fad001b8b242b9c..a1887887cc191d03778641cb920fc5002b00b957 100644 (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
index 6c204543c1aeaded36a6314d811cd9cc868904a6..96a82dc10627e1ffd2492f1411f08e12b217f577 100644 (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;
index 52c9d0064819656f46ed507296874de1a93b9f75..f21d94fbc067b8cb28536cf36f81b4e22bbff891 100644 (file)
 #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;
 }
 
 
index 1e4666ec5329ae9abcbe1b38c92c963967490031..79a6a01f998da0015b05a84287f4789999884862 100644 (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