finish centralizing boost::filesystem usage to single cpp file - refs #1177

This commit is contained in:
Dane Springmeyer 2015-01-06 00:33:33 -08:00
parent b396db54dd
commit 2a33ead4cc
4 changed files with 37 additions and 28 deletions

View file

@ -28,6 +28,7 @@
// stl // stl
#include <string> #include <string>
#include <vector>
namespace mapnik { namespace util { namespace mapnik { namespace util {
@ -39,6 +40,8 @@ MAPNIK_DECL bool is_relative(std::string const& value);
MAPNIK_DECL std::string make_relative(std::string const& filepath, std::string const& base); MAPNIK_DECL std::string make_relative(std::string const& filepath, std::string const& base);
MAPNIK_DECL std::string make_absolute(std::string const& filepath, std::string const& base); MAPNIK_DECL std::string make_absolute(std::string const& filepath, std::string const& base);
MAPNIK_DECL std::string dirname(std::string const& value); MAPNIK_DECL std::string dirname(std::string const& value);
MAPNIK_DECL std::string basename(std::string const& value);
MAPNIK_DECL std::vector<std::string> list_directory(std::string const& value);
}} }}

View file

@ -34,7 +34,6 @@
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedef" #pragma GCC diagnostic ignored "-Wunused-local-typedef"
#include <boost/filesystem/operations.hpp>
#include <boost/algorithm/string/join.hpp> #include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
@ -171,18 +170,9 @@ bool datasource_cache::register_datasources(std::string const& dir, bool recurse
bool success = false; bool success = false;
try try
{ {
boost::filesystem::directory_iterator end_itr; for (std::string const& file_name : mapnik::util::list_directory(dir))
#ifdef _WINDOWS
std::wstring wide_dir(mapnik::utf8_to_utf16(dir));
for (boost::filesystem::directory_iterator itr(wide_dir); itr != end_itr; ++itr)
{ {
std::string file_name = mapnik::utf16_to_utf8(itr->path().wstring()); if (mapnik::util::is_directory(file_name) && recurse)
#else
for (boost::filesystem::directory_iterator itr(dir); itr != end_itr; ++itr)
{
std::string file_name = itr->path().string();
#endif
if (boost::filesystem::is_directory(*itr) && recurse)
{ {
if (register_datasources(file_name, true)) if (register_datasources(file_name, true))
{ {
@ -191,7 +181,7 @@ bool datasource_cache::register_datasources(std::string const& dir, bool recurse
} }
else else
{ {
std::string base_name = itr->path().filename().string(); std::string base_name = mapnik::util::basename(file_name);
if (!boost::algorithm::starts_with(base_name,".") && if (!boost::algorithm::starts_with(base_name,".") &&
mapnik::util::is_regular_file(file_name) && mapnik::util::is_regular_file(file_name) &&
is_input_plugin(file_name)) is_input_plugin(file_name))

View file

@ -35,7 +35,6 @@
#pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedef" #pragma GCC diagnostic ignored "-Wunused-local-typedef"
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
@ -189,18 +188,9 @@ bool freetype_engine::register_fonts_impl(std::string const& dir,
bool success = false; bool success = false;
try try
{ {
boost::filesystem::directory_iterator end_itr; for (std::string const& file_name : mapnik::util::list_directory(dir))
#ifdef _WINDOWS
std::wstring wide_dir(mapnik::utf8_to_utf16(dir));
for (boost::filesystem::directory_iterator itr(wide_dir); itr != end_itr; ++itr)
{ {
std::string file_name = mapnik::utf16_to_utf8(itr->path().wstring()); if (mapnik::util::is_directory(file_name) && recurse)
#else
for (boost::filesystem::directory_iterator itr(dir); itr != end_itr; ++itr)
{
std::string file_name = itr->path().string();
#endif
if (boost::filesystem::is_directory(*itr) && recurse)
{ {
if (register_fonts_impl(file_name, library, font_file_mapping, true)) if (register_fonts_impl(file_name, library, font_file_mapping, true))
{ {
@ -209,7 +199,7 @@ bool freetype_engine::register_fonts_impl(std::string const& dir,
} }
else else
{ {
std::string base_name = itr->path().filename().string(); std::string base_name = mapnik::util::basename(file_name);
if (!boost::algorithm::starts_with(base_name,".") && if (!boost::algorithm::starts_with(base_name,".") &&
mapnik::util::is_regular_file(file_name) && mapnik::util::is_regular_file(file_name) &&
is_font_file(file_name)) is_font_file(file_name))

View file

@ -25,7 +25,8 @@
#include <mapnik/util/fs.hpp> #include <mapnik/util/fs.hpp>
// boost // boost
#include <boost/filesystem/convenience.hpp> #include <boost/filesystem/operations.hpp> // for absolute, exists, etc
#include <boost/filesystem/path.hpp> // for path, operator/
// stl // stl
#include <stdexcept> #include <stdexcept>
@ -81,7 +82,6 @@ namespace util {
return (! child_path.has_root_directory() && ! child_path.has_root_name()); return (! child_path.has_root_directory() && ! child_path.has_root_name());
} }
std::string make_relative(std::string const& filepath, std::string const& base) std::string make_relative(std::string const& filepath, std::string const& base)
{ {
#ifdef _WINDOWS #ifdef _WINDOWS
@ -109,6 +109,32 @@ namespace util {
return bp.parent_path().string(); return bp.parent_path().string();
} }
std::string basename(std::string const& value)
{
boost::filesystem::path bp(value);
return bp.filename().string();
}
std::vector<std::string> list_directory(std::string const& dir)
{
std::vector<std::string> listing;
boost::filesystem::directory_iterator end_itr;
#ifdef _WINDOWS
std::wstring wide_dir(mapnik::utf8_to_utf16(dir));
for (boost::filesystem::directory_iterator itr(wide_dir); itr != end_itr; ++itr)
{
listing.emplace_back(mapnik::utf16_to_utf8(itr->path().wstring()));
}
#else
for (boost::filesystem::directory_iterator itr(dir); itr != end_itr; ++itr)
{
listing.emplace_back(itr->path().string());
}
#endif
return listing;
}
} // end namespace util } // end namespace util
} // end namespace mapnik } // end namespace mapnik