fix mapnik-index build when memory mapping is disabled - closes #3135

This commit is contained in:
Dane Springmeyer 2015-10-20 12:17:32 -07:00
parent 001520aa95
commit d80179fca4
2 changed files with 40 additions and 1 deletions

View file

@ -23,7 +23,9 @@
#include "process_csv_file.hpp"
#include "../../plugins/input/csv/csv_utils.hpp"
#include <mapnik/geometry_envelope.hpp>
#include <mapnik/util/utf_conv_win.hpp>
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wsign-conversion"
@ -31,15 +33,19 @@
#include <boost/interprocess/streams/bufferstream.hpp>
#pragma GCC diagnostic pop
#include <mapnik/mapped_memory_cache.hpp>
#endif
#include <fstream>
namespace mapnik { namespace detail {
template <typename T>
std::pair<bool,box2d<double>> process_csv_file(T & boxes, std::string const& filename, std::string const& manual_headers, char separator, char quote)
{
mapnik::box2d<double> extent;
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
using file_source_type = boost::interprocess::ibufferstream;
file_source_type csv_file;
mapnik::box2d<double> extent;
mapnik::mapped_region_ptr mapped_region;
boost::optional<mapnik::mapped_region_ptr> memory =
mapnik::mapped_memory_cache::instance().find(filename, true);
@ -53,6 +59,18 @@ std::pair<bool,box2d<double>> process_csv_file(T & boxes, std::string const& fil
std::clog << "Error : cannot mmap " << filename << std::endl;
return std::make_pair(false, extent);
}
#else
#if defined(_WINDOWS)
std::ifstream csv_file(mapnik::utf8_to_utf16(filename),std::ios_base::in | std::ios_base::binary);
#else
std::ifstream csv_file(filename.c_str(),std::ios_base::in | std::ios_base::binary);
#endif
if (!csv_file.is_open())
{
std::clog << "Error : cannot open " << filename << std::endl;
return std::make_pair(false, extent);
}
#endif
auto file_length = ::detail::file_length(csv_file);
// set back to start
csv_file.seekg(0, std::ios::beg);

View file

@ -24,6 +24,10 @@
#include <mapnik/geometry.hpp>
#include <mapnik/geometry_envelope.hpp>
#include <mapnik/geometry_adapters.hpp>
#include <mapnik/util/file_io.hpp>
#include <mapnik/util/utf_conv_win.hpp>
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wsign-compare"
@ -33,6 +37,8 @@
#include <boost/spirit/include/qi.hpp>
#pragma GCC diagnostic pop
#include <mapnik/mapped_memory_cache.hpp>
#endif
#include <mapnik/json/positions_grammar.hpp>
#include <mapnik/json/extract_bounding_box_grammar_impl.hpp>
@ -47,6 +53,7 @@ template <typename T>
std::pair<bool,box2d<double>> process_geojson_file(T & boxes, std::string const& filename)
{
mapnik::box2d<double> extent;
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
mapnik::mapped_region_ptr mapped_region;
boost::optional<mapnik::mapped_region_ptr> memory =
mapnik::mapped_memory_cache::instance().find(filename, true);
@ -61,6 +68,20 @@ std::pair<bool,box2d<double>> process_geojson_file(T & boxes, std::string const&
}
char const* start = reinterpret_cast<char const*>(mapped_region->get_address());
char const* end = start + mapped_region->get_size();
#else
mapnik::util::file file(filename);
if (!file.open())
{
std::clog << "Error : cannot open " << filename << std::endl;
return std::make_pair(false, extent);
}
std::string file_buffer;
file_buffer.resize(file.size());
std::fread(&file_buffer[0], file.size(), 1, file.get());
char const* start = file_buffer.c_str();
char const* end = start + file_buffer.length();
#endif
boost::spirit::standard::space_type space;
try
{