From c4a1df6e914a1e30c0ff19b8010262953138361a Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 15 Aug 2017 11:13:11 +0100 Subject: [PATCH 1/2] simplify impl + const correctness + minor cleanup --- include/mapnik/quad_tree.hpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/include/mapnik/quad_tree.hpp b/include/mapnik/quad_tree.hpp index 9b2af5d5e..b6f2747bc 100644 --- a/include/mapnik/quad_tree.hpp +++ b/include/mapnik/quad_tree.hpp @@ -117,7 +117,7 @@ public: root_ = nodes_[0].get(); } - void insert(value_type data, bbox_type const& box) + void insert(value_type const& data, bbox_type const& box) { unsigned int depth = 0; do_insert_data(data, box, root_, depth); @@ -207,13 +207,9 @@ private: } } - void do_insert_data(value_type data, bbox_type const& box, node * n, unsigned int& depth) + void do_insert_data(value_type const& data, bbox_type const& box, node * n, unsigned int& depth) { - if (++depth >= max_depth_) - { - n->cont_.push_back(data); - } - else + if (++depth < max_depth_) { bbox_type const& node_extent = n->extent(); bbox_type ext[4]; @@ -225,17 +221,17 @@ private: if (!n->children_[i]) { nodes_.push_back(std::make_unique(ext[i])); - n->children_[i]=nodes_.back().get(); + n->children_[i] = nodes_.back().get(); } - do_insert_data(data,box,n->children_[i],depth); + do_insert_data(data, box, n->children_[i], depth); return; } } - n->cont_.push_back(data); } + n->cont_.push_back(data); } - void split_box(bbox_type const& node_extent,bbox_type * ext) + void split_box(bbox_type const& node_extent, bbox_type * ext) { typename bbox_type::value_type width = node_extent.width(); typename bbox_type::value_type height = node_extent.height(); From add410e6192b4f4cae671f0dd6bf7cc2c0561a72 Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 15 Aug 2017 11:14:11 +0100 Subject: [PATCH 2/2] use arch independent types for serialised values --- .../json/extract_bounding_boxes_x3_config.hpp | 4 ++-- plugins/input/csv/csv_datasource.cpp | 8 ++++---- plugins/input/csv/csv_datasource.hpp | 2 +- plugins/input/csv/csv_featureset.cpp | 4 ++-- plugins/input/csv/csv_index_featureset.hpp | 2 +- plugins/input/csv/csv_utils.cpp | 4 ++-- plugins/input/geojson/geojson_datasource.cpp | 14 +++++++------- plugins/input/geojson/geojson_datasource.hpp | 2 +- plugins/input/geojson/geojson_index_featureset.hpp | 2 +- utils/mapnik-index/mapnik-index.cpp | 4 ++-- utils/mapnik-index/process_csv_file.cpp | 2 +- utils/mapnik-index/process_geojson_file_x3.cpp | 2 +- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/mapnik/json/extract_bounding_boxes_x3_config.hpp b/include/mapnik/json/extract_bounding_boxes_x3_config.hpp index 81bbba0ff..8de409928 100644 --- a/include/mapnik/json/extract_bounding_boxes_x3_config.hpp +++ b/include/mapnik/json/extract_bounding_boxes_x3_config.hpp @@ -67,11 +67,11 @@ struct extract_positions }; using box_type = mapnik::box2d; -using boxes_type = std::vector>>; +using boxes_type = std::vector>>; using callback_type = extract_positions; using box_type_f = mapnik::box2d; -using boxes_type_f = std::vector>>; +using boxes_type_f = std::vector>>; using callback_type_f = extract_positions; diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index 557021142..e8d3eafa2 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -153,7 +153,7 @@ csv_datasource::csv_datasource(parameters const& params) if (has_disk_index_ && !extent_initialized_) { // read bounding box from *.index - using value_type = std::pair; + using value_type = std::pair; std::ifstream index(filename_ + ".index", std::ios::binary); if (!index) throw mapnik::datasource_exception("CSV Plugin: could not open: '" + filename_ + ".index'"); extent_ = mapnik::util::spatial_index record; record.resize(size); @@ -316,7 +316,7 @@ csv_datasource::get_geometry_type_impl(std::istream & stream) const else { // try reading *.index - using value_type = std::pair; + using value_type = std::pair; std::ifstream index(filename_ + ".index", std::ios::binary); if (!index) throw mapnik::datasource_exception("CSV Plugin: could not open: '" + filename_ + ".index'"); diff --git a/plugins/input/csv/csv_datasource.hpp b/plugins/input/csv/csv_datasource.hpp index 0c0442a82..a33716547 100644 --- a/plugins/input/csv/csv_datasource.hpp +++ b/plugins/input/csv/csv_datasource.hpp @@ -73,7 +73,7 @@ class csv_datasource : public mapnik::datasource, { public: using box_type = mapnik::box2d; - using item_type = std::pair>; + using item_type = std::pair>; using spatial_index_type = boost::geometry::index::rtree>; csv_datasource(mapnik::parameters const& params); diff --git a/plugins/input/csv/csv_featureset.cpp b/plugins/input/csv/csv_featureset.cpp index a20ca18d2..a3d971070 100644 --- a/plugins/input/csv/csv_featureset.cpp +++ b/plugins/input/csv/csv_featureset.cpp @@ -88,8 +88,8 @@ mapnik::feature_ptr csv_featureset::next() if (index_itr_ != index_end_) { csv_datasource::item_type const& item = *index_itr_++; - std::size_t file_offset = item.second.first; - std::size_t size = item.second.second; + std::uint64_t file_offset = item.second.first; + std::uint64_t size = item.second.second; #if defined(MAPNIK_MEMORY_MAPPED_FILE) char const* start = (char const*)mapped_region_->get_address() + file_offset; char const* end = start + size; diff --git a/plugins/input/csv/csv_index_featureset.hpp b/plugins/input/csv/csv_index_featureset.hpp index 65e815574..a35d7118b 100644 --- a/plugins/input/csv/csv_index_featureset.hpp +++ b/plugins/input/csv/csv_index_featureset.hpp @@ -40,7 +40,7 @@ class csv_index_featureset : public mapnik::Featureset { - using value_type = std::pair; + using value_type = std::pair; using locator_type = csv_utils::geometry_column_locator; public: diff --git a/plugins/input/csv/csv_utils.cpp b/plugins/input/csv/csv_utils.cpp index 2e6ca37d7..b48b184d5 100644 --- a/plugins/input/csv/csv_utils.cpp +++ b/plugins/input/csv/csv_utils.cpp @@ -505,8 +505,8 @@ mapnik::geometry::geometry extract_geometry(std::vector con return geom; } -template void csv_file_parser::parse_csv_and_boxes(std::istream & csv_file, std::vector, std::pair>> & boxes); +template void csv_file_parser::parse_csv_and_boxes(std::istream & csv_file, std::vector, std::pair>> & boxes); -template void csv_file_parser::parse_csv_and_boxes(std::istream & csv_file, std::vector, std::pair>> & boxes); +template void csv_file_parser::parse_csv_and_boxes(std::istream & csv_file, std::vector, std::pair>> & boxes); } // namespace csv_utils diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index ad2f3d9e4..7bbf54627 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -183,7 +183,7 @@ geojson_datasource::geojson_datasource(parameters const& params) namespace { using box_type = box2d; -using boxes_type = std::vector>>; +using boxes_type = std::vector>>; using base_iterator_type = char const*; const mapnik::transcoder geojson_datasource_static_tr("utf8"); @@ -206,7 +206,7 @@ void geojson_datasource::initialise_descriptor(mapnik::feature_ptr const& featur void geojson_datasource::initialise_disk_index(std::string const& filename) { // read extent - using value_type = std::pair; + using value_type = std::pair; std::ifstream index(filename_ + ".index", std::ios::binary); if (!index) throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + ".index'"); extent_ = mapnik::util::spatial_index>>; + using values_container = std::vector< std::pair>>; values_container values; values.reserve(features_.size()); @@ -394,7 +394,7 @@ void geojson_datasource::parse_geojson(Iterator start, Iterator end) features_.push_back(std::move(feature)); } - using values_container = std::vector< std::pair>>; + using values_container = std::vector< std::pair>>; values_container values; values.reserve(features_.size()); @@ -453,7 +453,7 @@ boost::optional geojson_datasource::get_geometry_ int multi_type = 0; if (has_disk_index_) { - using value_type = std::pair; + using value_type = std::pair; std::ifstream index(filename_ + ".index", std::ios::binary); if (!index) throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + ".index'"); mapnik::filter_in_box filter(extent_); @@ -527,8 +527,8 @@ boost::optional geojson_datasource::get_geometry_ for (std::size_t count = 0; itr !=end && count < num_features_to_query_; ++itr,++count) { geojson_datasource::item_type const& item = *itr; - std::size_t file_offset = item.second.first; - std::size_t size = item.second.second; + std::uint64_t file_offset = item.second.first; + std::uint64_t size = item.second.second; std::fseek(file.get(), file_offset, SEEK_SET); std::vector json; diff --git a/plugins/input/geojson/geojson_datasource.hpp b/plugins/input/geojson/geojson_datasource.hpp index 207884752..6b3e1bcbd 100644 --- a/plugins/input/geojson/geojson_datasource.hpp +++ b/plugins/input/geojson/geojson_datasource.hpp @@ -75,7 +75,7 @@ class geojson_datasource : public mapnik::datasource { public: using box_type = mapnik::box2d; - using item_type = std::pair >; + using item_type = std::pair >; using spatial_index_type = boost::geometry::index::rtree >; // constructor diff --git a/plugins/input/geojson/geojson_index_featureset.hpp b/plugins/input/geojson/geojson_index_featureset.hpp index 935a3802a..23e9023bb 100644 --- a/plugins/input/geojson/geojson_index_featureset.hpp +++ b/plugins/input/geojson/geojson_index_featureset.hpp @@ -41,7 +41,7 @@ class geojson_index_featureset : public mapnik::Featureset { - using value_type = std::pair; + using value_type = std::pair; public: geojson_index_featureset(std::string const& filename, mapnik::filter_in_box const& filter); virtual ~geojson_index_featureset(); diff --git a/utils/mapnik-index/mapnik-index.cpp b/utils/mapnik-index/mapnik-index.cpp index bd73d98c2..334641739 100644 --- a/utils/mapnik-index/mapnik-index.cpp +++ b/utils/mapnik-index/mapnik-index.cpp @@ -168,7 +168,7 @@ int main (int argc, char** argv) std::clog << "split ratio:" << ratio << std::endl; using box_type = mapnik::box2d; - using item_type = std::pair>; + using item_type = std::pair>; for (auto const& filename : files_to_process) { @@ -208,7 +208,7 @@ int main (int argc, char** argv) { std::clog << extent << std::endl; mapnik::box2d extent_d(extent.minx(), extent.miny(), extent.maxx(), extent.maxy()); - mapnik::quad_tree> tree(extent_d, depth, ratio); + mapnik::quad_tree> tree(extent_d, depth, ratio); for (auto const& item : boxes) { auto ext_f = std::get<0>(item); diff --git a/utils/mapnik-index/process_csv_file.cpp b/utils/mapnik-index/process_csv_file.cpp index 0895f9176..7ead26436 100644 --- a/utils/mapnik-index/process_csv_file.cpp +++ b/utils/mapnik-index/process_csv_file.cpp @@ -93,7 +93,7 @@ std::pair process_csv_file(T & boxes, s } using box_type = mapnik::box2d; -using item_type = std::pair>; +using item_type = std::pair>; using boxes_type = std::vector; template std::pair process_csv_file(boxes_type&, std::string const&, std::string const&, char, char); diff --git a/utils/mapnik-index/process_geojson_file_x3.cpp b/utils/mapnik-index/process_geojson_file_x3.cpp index ab3e1cfbb..afc8d55ed 100644 --- a/utils/mapnik-index/process_geojson_file_x3.cpp +++ b/utils/mapnik-index/process_geojson_file_x3.cpp @@ -213,7 +213,7 @@ bool validate_geojson_feature(mapnik::json::geojson_value & value, Keys const& k }; using box_type = mapnik::box2d; -using boxes_type = std::vector>>; +using boxes_type = std::vector>>; using base_iterator_type = char const*; auto const& geojson_value = mapnik::json::geojson_grammar();