fix typedef names, expose value_type
This commit is contained in:
parent
2d95518b22
commit
a4e08da00b
1 changed files with 19 additions and 17 deletions
|
@ -34,17 +34,15 @@
|
|||
#include <boost/utility.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
// stl
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
class vertex_vector : private boost::noncopyable
|
||||
{
|
||||
typedef typename T::type value_type;
|
||||
typedef vertex<value_type,2> vertex_type;
|
||||
typedef T coord_type;
|
||||
typedef vertex<coord_type,2> vertex_type;
|
||||
|
||||
enum block_e {
|
||||
block_shift = 8,
|
||||
block_size = 1<<block_shift,
|
||||
|
@ -55,11 +53,14 @@ class vertex_vector : private boost::noncopyable
|
|||
private:
|
||||
unsigned num_blocks_;
|
||||
unsigned max_blocks_;
|
||||
value_type** vertices_;
|
||||
coord_type** vertices_;
|
||||
unsigned char** commands_;
|
||||
unsigned pos_;
|
||||
|
||||
public:
|
||||
|
||||
// required for iterators support
|
||||
typedef typename boost::tuple<unsigned,coord_type,coord_type> 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<unsigned char>(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<value_type**>(::operator new (sizeof(value_type*)*((max_blocks_ + grow_by) * 2)));
|
||||
coord_type** new_vertices =
|
||||
static_cast<coord_type**>(::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<value_type*>(::operator new(sizeof(value_type)*(block_size * 2 + block_size / (sizeof(value_type)))));
|
||||
vertices_[block] = static_cast<coord_type*>
|
||||
(::operator new(sizeof(coord_type)*(block_size * 2 + block_size / (sizeof(coord_type)))));
|
||||
|
||||
commands_[block] = (unsigned char*)(vertices_[block] + block_size*2);
|
||||
++num_blocks_;
|
||||
|
|
Loading…
Add table
Reference in a new issue