Lars, I'm trying out boost::filesystem in the graphics cache code. See attached using_filesystem.diff, which modifies GraphicsCache.[Ch]. I plan to use filesystem throughout the graphics code.
Can I get you to add boost::filesystem to the boost directories. I attach boost_filesystem.tar.gz which contains the boost-1.30.2 version of filesystem. boost/boost/filesystem/ boost/boost/filesystem/convenience.hpp boost/boost/filesystem/exception.hpp boost/boost/filesystem/fstream.hpp boost/boost/filesystem/operations.hpp boost/boost/filesystem/path.hpp boost/libs/filesystem/ boost/libs/filesystem/src/ boost/libs/filesystem/src/convenience.cpp boost/libs/filesystem/src/exception.cpp boost/libs/filesystem/src/operations_posix_windows.cpp boost/libs/filesystem/src/path_posix_windows.cpp boost/libs/filesystem/src/Makefile.am boost/libs/filesystem/Makefile.am boost_filesystem.diff This last file contains the necessary changes to configure.ac, boost/Makefile.am and src/Makefile.am. Regards, -- Angus
boost_filesystem.tar.gz
Description: GNU Zip compressed data
Index: src/frontends/controllers/ControlExternal.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlExternal.C,v retrieving revision 1.54 diff -u -p -r1.54 ControlExternal.C --- src/frontends/controllers/ControlExternal.C 8 Jan 2004 10:59:49 -0000 1.54 +++ src/frontends/controllers/ControlExternal.C 8 Jan 2004 15:26:00 -0000 @@ -31,6 +31,9 @@ #include "support/globbing.h" #include "support/tostr.h" +#include <boost/filesystem/path.hpp> + +namespace fs = boost::filesystem; namespace external = lyx::external; using lyx::support::FileFilterList; @@ -176,9 +179,11 @@ string const ControlExternal::readBB(str int width = 0; int height = 0; + fs::path const filepath(abs_file, fs::native); + lyx::graphics::Cache & gc = lyx::graphics::Cache::get(); - if (gc.inCache(abs_file)) { - lyx::graphics::Image const * image = gc.item(abs_file)->image(); + if (gc.inCache(filepath)) { + lyx::graphics::Image const * image = gc.item(filepath)->image(); if (image) { width = image->getWidth(); Index: src/frontends/controllers/ControlGraphics.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlGraphics.C,v retrieving revision 1.82 diff -u -p -r1.82 ControlGraphics.C --- src/frontends/controllers/ControlGraphics.C 8 Jan 2004 10:59:49 -0000 1.82 +++ src/frontends/controllers/ControlGraphics.C 8 Jan 2004 15:26:00 -0000 @@ -32,6 +32,10 @@ #include "support/tostr.h" #include "support/types.h" +#include <boost/filesystem/path.hpp> + +namespace fs = boost::filesystem; + using lyx::support::AddName; using lyx::support::FileFilterList; using lyx::support::FileInfo; @@ -111,9 +115,11 @@ string const ControlGraphics::readBB(str int width = 0; int height = 0; + fs::path const filepath(abs_file, fs::native); + lyx::graphics::Cache & gc = lyx::graphics::Cache::get(); - if (gc.inCache(abs_file)) { - lyx::graphics::Image const * image = gc.item(abs_file)->image(); + if (gc.inCache(filepath)) { + lyx::graphics::Image const * image = gc.item(filepath)->image(); if (image) { width = image->getWidth(); Index: src/graphics/GraphicsCache.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsCache.C,v retrieving revision 1.42 diff -u -p -r1.42 GraphicsCache.C --- src/graphics/GraphicsCache.C 6 Oct 2003 15:42:58 -0000 1.42 +++ src/graphics/GraphicsCache.C 8 Jan 2004 15:26:05 -0000 @@ -17,9 +17,9 @@ #include "debug.h" -#include "support/filetools.h" +#include <boost/filesystem/path.hpp> -namespace support = lyx::support; +namespace fs = boost::filesystem; using std::string; @@ -29,18 +29,20 @@ namespace graphics { /** The cache contains one item per file, so use a map to find the * cache item quickly by filename. + * + * Note to self: we store the file as a string rather than as fs::path + * because fs::path has no operator<, needed to find the item in the + * map. */ typedef std::map<string, Cache::ItemPtr> CacheType; struct Cache::Impl { - /// CacheType cache; }; Cache & Cache::get() { - // Now return the cache static Cache singleton; return singleton; } @@ -61,10 +63,11 @@ std::vector<string> Cache::loadableForma } -void Cache::add(string const & file) const +void Cache::add(fs::path const & file) const { - if (!support::AbsolutePath(file)) { - lyxerr << "Cache::add(" << file << "):\n" + if (!file.has_root_path()) { + lyxerr << "Cache::add(" + << file.native_file_string() << "):\n" << "The file must be have an absolute path." << std::endl; return; @@ -72,41 +75,43 @@ void Cache::add(string const & file) con // Is the file in the cache already? if (inCache(file)) { - lyxerr[Debug::GRAPHICS] << "Cache::add(" << file << "):\n" - << "The file is already in the cache." - << std::endl; + lyxerr[Debug::GRAPHICS] + << "Cache::add(" + << file.native_file_string() << "):\n" + << "The file is already in the cache." + << std::endl; return; } - pimpl_->cache[file] = ItemPtr(new CacheItem(file)); + pimpl_->cache[file.string()] = + ItemPtr(new CacheItem(file.native_file_string())); } -void Cache::remove(string const & file) const +void Cache::remove(fs::path const & file) const { - CacheType::iterator it = pimpl_->cache.find(file); + CacheType::iterator it = pimpl_->cache.find(file.string()); if (it == pimpl_->cache.end()) return; ItemPtr & item = it->second; - - if (item.use_count() == 1) { - // The graphics file is in the cache, but nothing else + if (item.unique()) { + // The file is in the cache, but nothing else // references it. pimpl_->cache.erase(it); } } -bool Cache::inCache(string const & file) const +bool Cache::inCache(fs::path const & file) const { - return pimpl_->cache.find(file) != pimpl_->cache.end(); + return pimpl_->cache.find(file.string()) != pimpl_->cache.end(); } -Cache::ItemPtr const Cache::item(string const & file) const +Cache::ItemPtr const Cache::item(fs::path const & file) const { - CacheType::const_iterator it = pimpl_->cache.find(file); + CacheType::const_iterator it = pimpl_->cache.find(file.string()); if (it == pimpl_->cache.end()) return ItemPtr(); Index: src/graphics/GraphicsCache.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsCache.h,v retrieving revision 1.34 diff -u -p -r1.34 GraphicsCache.h --- src/graphics/GraphicsCache.h 7 Oct 2003 06:45:25 -0000 1.34 +++ src/graphics/GraphicsCache.h 8 Jan 2004 15:26:05 -0000 @@ -27,6 +27,14 @@ #include <vector> #include <string> +namespace boost { +namespace filesystem { + +class path; + +} // namespace boost +} // namespace filesystem + namespace lyx { namespace graphics { @@ -46,13 +54,13 @@ public: std::vector<std::string> loadableFormats() const; /// Add a graphics file to the cache. - void add(std::string const & file) const; + void add(boost::filesystem::path const & file) const; /// Remove a file from the cache. - void remove(std::string const & file) const; + void remove(boost::filesystem::path const & file) const; /// Returns \c true if the file is in the cache. - bool inCache(std::string const & file) const; + bool inCache(boost::filesystem::path const & file) const; /** Get the cache item associated with file. * Returns an empty container if there is no such item. @@ -66,7 +74,7 @@ public: */ typedef boost::shared_ptr<CacheItem> ItemPtr; /// - ItemPtr const item(std::string const & file) const; + ItemPtr const item(boost::filesystem::path const & file) const; private: /** Make the c-tor, d-tor private so we can control how many objects Index: src/graphics/GraphicsLoader.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsLoader.C,v retrieving revision 1.22 diff -u -p -r1.22 GraphicsLoader.C --- src/graphics/GraphicsLoader.C 6 Oct 2003 15:42:59 -0000 1.22 +++ src/graphics/GraphicsLoader.C 8 Jan 2004 15:26:05 -0000 @@ -18,7 +18,9 @@ #include "LoaderQueue.h" #include <boost/bind.hpp> +#include <boost/filesystem/path.hpp> +namespace fs = boost::filesystem; using std::string; @@ -206,6 +208,8 @@ Loader::Impl::~Impl() void Loader::Impl::resetFile(string const & file) { + fs::path const filepath(file, fs::native); + string const old_file = cached_item_.get() ? cached_item_->filename() : string(); @@ -219,7 +223,7 @@ void Loader::Impl::resetFile(string cons if (!old_file.empty()) { continue_monitoring = cached_item_->monitoring(); cached_item_.reset(); - Cache::get().remove(old_file); + Cache::get().remove(fs::path(old_file, fs::native)); } status_ = cached_item_.get() ? cached_item_->status() : WaitingToLoad; @@ -229,11 +233,11 @@ void Loader::Impl::resetFile(string cons return; Cache & gc = Cache::get(); - if (!gc.inCache(file)) - gc.add(file); + if (!gc.inCache(filepath)) + gc.add(filepath); // We /must/ make a local copy of this. - cached_item_ = gc.item(file); + cached_item_ = gc.item(filepath); status_ = cached_item_->status(); if (continue_monitoring && !cached_item_->monitoring())