From 616896c6eed5ac8603b8b780211a9d95bfbca125 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 26 Aug 2014 16:22:12 -0700 Subject: [PATCH 1/3] remove spirit::multi_pass - refs #2397 --- plugins/input/geojson/geojson_datasource.cpp | 36 +++++++++----------- plugins/input/geojson/geojson_datasource.hpp | 2 +- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index 9b267ef2f..34aeb01ca 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -29,7 +29,6 @@ // boost #include -#include // mapnik #include @@ -49,7 +48,6 @@ #include #include -#include using mapnik::datasource; using mapnik::parameters; @@ -127,43 +125,41 @@ geojson_datasource::geojson_datasource(parameters const& params) } if (!inline_string_.empty()) { - std::istringstream in(inline_string_); - parse_geojson(in); + parse_geojson(inline_string_); } else { -#if defined (_WINDOWS) - std::ifstream in(mapnik::utf8_to_utf16(filename_),std::ios_base::in | std::ios_base::binary); +#ifdef _WINDOWS + std::unique_ptr file(_wfopen(mapnik::utf8_to_utf16(filename_).c_str(), L"rb"), fclose); #else - std::ifstream in(filename_.c_str(),std::ios_base::in | std::ios_base::binary); + std::unique_ptr file(std::fopen(filename_.c_str(),"rb"), std::fclose); #endif - if (!in.is_open()) + if (file == nullptr) { throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + "'"); } - parse_geojson(in); - in.close(); + std::fseek(file.get(), 0, SEEK_END); + std::size_t file_size = std::ftell(file.get()); + std::fseek(file.get(), 0, SEEK_SET); + std::string file_buffer; + file_buffer.resize(file_size); + std::fread(&file_buffer[0], file_size, 1, file.get()); + parse_geojson(file_buffer); } } namespace { -using base_iterator_type = std::istreambuf_iterator; +using base_iterator_type = std::string::const_iterator; const mapnik::transcoder tr("utf8"); -const mapnik::json::feature_collection_grammar,mapnik::feature_impl> fc_grammar(tr); +const mapnik::json::feature_collection_grammar fc_grammar(tr); } template -void geojson_datasource::parse_geojson(T & stream) +void geojson_datasource::parse_geojson(T const& buffer) { - boost::spirit::multi_pass begin = - boost::spirit::make_default_multi_pass(base_iterator_type(stream)); - - boost::spirit::multi_pass end = - boost::spirit::make_default_multi_pass(base_iterator_type()); - boost::spirit::standard_wide::space_type space; mapnik::context_ptr ctx = std::make_shared(); - bool result = boost::spirit::qi::phrase_parse(begin, end, (fc_grammar)(boost::phoenix::ref(ctx)), space, features_); + bool result = boost::spirit::qi::phrase_parse(buffer.begin(), buffer.end(), (fc_grammar)(boost::phoenix::ref(ctx)), space, features_); if (!result) { if (!inline_string_.empty()) throw mapnik::datasource_exception("geojson_datasource: Failed parse GeoJSON file from in-memory string"); diff --git a/plugins/input/geojson/geojson_datasource.hpp b/plugins/input/geojson/geojson_datasource.hpp index 5121cf19f..9d2087374 100644 --- a/plugins/input/geojson/geojson_datasource.hpp +++ b/plugins/input/geojson/geojson_datasource.hpp @@ -82,7 +82,7 @@ public: mapnik::layer_descriptor get_descriptor() const; boost::optional get_geometry_type() const; template - void parse_geojson(T & stream); + void parse_geojson(T const& buffer); private: mapnik::datasource::datasource_t type_; std::map statistics_; From a5925c1f15cced4615d2da6ac71e85e4a8c6a9f6 Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 29 Aug 2014 18:06:08 +0100 Subject: [PATCH 2/3] remove redundant private copy assignment op --- include/mapnik/image_data.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/mapnik/image_data.hpp b/include/mapnik/image_data.hpp index 599387e04..8d90d21ff 100644 --- a/include/mapnik/image_data.hpp +++ b/include/mapnik/image_data.hpp @@ -190,7 +190,6 @@ private: unsigned height_; bool owns_data_; T *pData_; - ImageData& operator=(ImageData const&); }; using image_data_32 = ImageData; From 21dcb2e2c4226ad50dd6bbd4c6fbbe10db9916bd Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Thu, 28 Aug 2014 20:00:25 +0000 Subject: [PATCH 3/3] fix compiler warning --- .../markers_placements/vertext_last.hpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/include/mapnik/markers_placements/vertext_last.hpp b/include/mapnik/markers_placements/vertext_last.hpp index faad98a5e..883e5b6b8 100644 --- a/include/mapnik/markers_placements/vertext_last.hpp +++ b/include/mapnik/markers_placements/vertext_last.hpp @@ -43,10 +43,18 @@ public: return false; } - double next_x, next_y; double x0, y0; - double x1, y1; - unsigned command0, command1 = agg::path_cmd_stop; + unsigned command0 = this->locator_.vertex(&x0, &y0); + + if (agg::is_stop(command0)) + { + this->done_ = true; + return false; + } + + double next_x, next_y; + double x1 = x0, y1 = y0; + unsigned command1 = command0; while (!agg::is_stop(command0 = this->locator_.vertex(&next_x, &next_y))) { @@ -57,13 +65,6 @@ public: y0 = next_y; } - // If path stopped on the very firts vertex. - if (agg::is_stop(command1)) - { - this->done_ = true; - return false; - } - x = x0; y = y0;