From 2d4ea205607fbdffef330e18b7da524de0b838ed Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Sun, 5 Feb 2006 12:31:24 +0000 Subject: [PATCH] added set_capacity method to geometry classes. (now we can use std::vector > as an alternative vertex storage). --- include/geometry.hpp | 15 +++++++++++++-- include/vertex_vector.hpp | 23 ++++++++++++++--------- plugins/input/shape/shape_io.cpp | 13 +++++++------ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/include/geometry.hpp b/include/geometry.hpp index cbce21d78..429d8a200 100644 --- a/include/geometry.hpp +++ b/include/geometry.hpp @@ -62,6 +62,7 @@ namespace mapnik virtual unsigned num_points() const = 0; virtual unsigned vertex(double* x, double* y)=0; virtual void rewind(unsigned )=0; + virtual void set_capacity(size_t size)=0; virtual ~geometry() {} }; @@ -120,6 +121,7 @@ namespace mapnik { return false; } + void set_capacity(size_t) {} virtual ~point() {} }; @@ -216,6 +218,10 @@ namespace mapnik { return false; } + void set_capacity(size_t size) + { + cont_.set_capacity(size); + } virtual ~polygon() {} }; @@ -332,12 +338,17 @@ namespace mapnik { return false; } + + void set_capacity(size_t size) + { + cont_.set_capacity(size); + } virtual ~line_string() {} }; typedef point point_impl; - typedef line_string line_string_impl; - typedef polygon polygon_impl; + typedef line_string line_string_impl; + typedef polygon polygon_impl; typedef geometry geometry_type; typedef boost::shared_ptr geometry_ptr; diff --git a/include/vertex_vector.hpp b/include/vertex_vector.hpp index 6944d8458..700b5ba98 100644 --- a/include/vertex_vector.hpp +++ b/include/vertex_vector.hpp @@ -115,7 +115,10 @@ namespace mapnik ++vertex; t.forward_y(vertex); } - + void set_capacity(size_t) + { + //do nothing + } private: void allocate_block(unsigned block) { @@ -143,9 +146,8 @@ namespace mapnik struct vertex_vector2 : boost::noncopyable { typedef typename T::type value_type; - typedef boost::tuple coord; + typedef boost::tuple vertex_type; vertex_vector2() {} - unsigned size() const { return cont_.size(); @@ -153,27 +155,30 @@ namespace mapnik void push_back (value_type x,value_type y,unsigned command) { - cont_.push_back(coord(x,y,command)); + cont_.push_back(vertex_type(x,y,command)); } unsigned get_vertex(unsigned pos,value_type* x,value_type* y) const { if (pos >= cont_.size()) return SEG_END; - coord const& c = cont_[pos]; + vertex_type const& c = cont_[pos]; *x = boost::get<0>(c); *y = boost::get<1>(c); return boost::get<2>(c); } - + void transform_at(unsigned pos,const CoordTransform& t) { if (pos >= cont_.size()) return; - coord & c = cont_[pos]; + vertex_type & c = cont_[pos]; t.forward_x(&boost::get<0>(c)); t.forward_y(&boost::get<1>(c)); } - + void set_capacity(size_t size) + { + cont_.reserve(size); + } private: - std::vector cont_; + std::vector cont_; }; } diff --git a/plugins/input/shape/shape_io.cpp b/plugins/input/shape/shape_io.cpp index 55961c42d..269b24a4d 100644 --- a/plugins/input/shape/shape_io.cpp +++ b/plugins/input/shape/shape_io.cpp @@ -92,9 +92,10 @@ geometry_ptr shape_io::read_polyline() int num_parts=record.read_ndr_integer(); int num_points=record.read_ndr_integer(); geometry_ptr line(new line_string_impl(-1)); - + line->set_capacity(num_points + num_parts); if (num_parts == 1) { + line->set_capacity(num_points + 1); record.skip(4); double x=record.read_double(); double y=record.read_double(); @@ -145,7 +146,7 @@ geometry_ptr shape_io::read_polylinem() int num_parts=record.read_ndr_integer(); int num_points=record.read_ndr_integer(); geometry_ptr line(new line_string_impl(-1)); - + line->set_capacity(num_points + num_parts); if (num_parts == 1) { record.skip(4); @@ -207,7 +208,7 @@ geometry_ptr shape_io::read_polylinez() int num_parts=record.read_ndr_integer(); int num_points=record.read_ndr_integer(); geometry_ptr line(new line_string_impl(-1)); - + line->set_capacity(num_points + num_parts); if (num_parts == 1) { record.skip(4); @@ -277,7 +278,7 @@ geometry_ptr shape_io::read_polygon() int num_points=record.read_ndr_integer(); std::vector parts(num_parts); geometry_ptr poly(new polygon_impl(-1)); - + poly->set_capacity(num_points + num_parts); for (int i=0;i parts(num_parts); geometry_ptr poly(new polygon_impl(-1)); - + poly->set_capacity(num_points + num_parts); for (int i=0;i parts(num_parts); geometry_ptr poly(new polygon_impl(-1)); - + poly->set_capacity(num_points + num_parts); for (int i=0;i