From a4e08da00b173f4d7a393d7727b936e6f23e7fc1 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Tue, 6 Dec 2011 11:15:37 +0000 Subject: [PATCH] fix typedef names, expose value_type --- include/mapnik/vertex_vector.hpp | 36 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/include/mapnik/vertex_vector.hpp b/include/mapnik/vertex_vector.hpp index 197e1072d..95d742538 100644 --- a/include/mapnik/vertex_vector.hpp +++ b/include/mapnik/vertex_vector.hpp @@ -34,17 +34,15 @@ #include #include -// stl -#include -#include - namespace mapnik { + template class vertex_vector : private boost::noncopyable { - typedef typename T::type value_type; - typedef vertex vertex_type; + typedef T coord_type; + typedef vertex vertex_type; + enum block_e { block_shift = 8, block_size = 1< value_type; + vertex_vector() : num_blocks_(0), max_blocks_(0), @@ -71,7 +72,7 @@ public: { if ( num_blocks_ ) { - value_type** vertices=vertices_ + num_blocks_ - 1; + coord_type** vertices=vertices_ + num_blocks_ - 1; while ( num_blocks_-- ) { ::operator delete(*vertices); @@ -85,14 +86,14 @@ public: return pos_; } - void push_back (value_type x,value_type y,unsigned command) + void push_back (coord_type x,coord_type y,unsigned command) { unsigned block = pos_ >> block_shift; if (block >= num_blocks_) { allocate_block(block); } - value_type* vertex = vertices_[block] + ((pos_ & block_mask) << 1); + coord_type* vertex = vertices_[block] + ((pos_ & block_mask) << 1); unsigned char* cmd= commands_[block] + (pos_ & block_mask); *cmd = static_cast(command); @@ -100,11 +101,11 @@ public: *vertex = y; ++pos_; } - unsigned get_vertex(unsigned pos,value_type* x,value_type* y) const + unsigned get_vertex(unsigned pos,coord_type* x,coord_type* y) const { if (pos >= pos_) return SEG_END; unsigned block = pos >> block_shift; - const value_type* vertex = vertices_[block] + (( pos & block_mask) << 1); + const coord_type* vertex = vertices_[block] + (( pos & block_mask) << 1); *x = (*vertex++); *y = (*vertex); return commands_[block] [pos & block_mask]; @@ -120,12 +121,12 @@ private: { if (block >= max_blocks_) { - value_type** new_vertices = - static_cast(::operator new (sizeof(value_type*)*((max_blocks_ + grow_by) * 2))); + coord_type** new_vertices = + static_cast(::operator new (sizeof(coord_type*)*((max_blocks_ + grow_by) * 2))); unsigned char** new_commands = (unsigned char**)(new_vertices + max_blocks_ + grow_by); if (vertices_) { - std::memcpy(new_vertices,vertices_,max_blocks_ * sizeof(value_type*)); + std::memcpy(new_vertices,vertices_,max_blocks_ * sizeof(coord_type*)); std::memcpy(new_commands,commands_,max_blocks_ * sizeof(unsigned char*)); ::operator delete(vertices_); } @@ -133,7 +134,8 @@ private: commands_ = new_commands; max_blocks_ += grow_by; } - vertices_[block] = static_cast(::operator new(sizeof(value_type)*(block_size * 2 + block_size / (sizeof(value_type))))); + vertices_[block] = static_cast + (::operator new(sizeof(coord_type)*(block_size * 2 + block_size / (sizeof(coord_type))))); commands_[block] = (unsigned char*)(vertices_[block] + block_size*2); ++num_blocks_;