std::make_unique
This commit is contained in:
parent
ca9b0fccab
commit
cb3db66b82
6 changed files with 77 additions and 28 deletions
38
include/mapnik/std.hpp
Normal file
38
include/mapnik/std.hpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2014 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef MAPNIK_STD_HPP
|
||||
#define MAPNIK_STD_HPP
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace std {
|
||||
|
||||
// C++14 backfill from http://herbsutter.com/gotw/_102/
|
||||
template<typename T, typename ...Args>
|
||||
inline ::std::unique_ptr<T> make_unique(Args&& ...args) {
|
||||
return ::std::unique_ptr<T>(new T(::std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -21,6 +21,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/std.hpp>
|
||||
#include <mapnik/graphics.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/agg_renderer.hpp>
|
||||
|
@ -91,8 +92,8 @@ void agg_renderer<T>::process(building_symbolizer const& sym,
|
|||
geometry_type const& geom = feature.get_geometry(i);
|
||||
if (geom.size() > 2)
|
||||
{
|
||||
const std::unique_ptr<geometry_type> frame(new geometry_type(geometry_type::types::LineString));
|
||||
const std::unique_ptr<geometry_type> roof(new geometry_type(geometry_type::types::Polygon));
|
||||
const auto frame = std::make_unique<geometry_type>(geometry_type::types::LineString);
|
||||
const auto roof = std::make_unique<geometry_type>(geometry_type::types::Polygon);
|
||||
std::deque<segment_t> face_segments;
|
||||
double x0 = 0;
|
||||
double y0 = 0;
|
||||
|
@ -121,7 +122,7 @@ void agg_renderer<T>::process(building_symbolizer const& sym,
|
|||
std::sort(face_segments.begin(),face_segments.end(), y_order);
|
||||
for (auto const& seg : face_segments)
|
||||
{
|
||||
const std::unique_ptr<geometry_type> faces(new geometry_type(geometry_type::types::Polygon));
|
||||
const auto faces = std::make_unique<geometry_type>(geometry_type::types::Polygon);
|
||||
faces->move_to(std::get<0>(seg),std::get<1>(seg));
|
||||
faces->line_to(std::get<2>(seg),std::get<3>(seg));
|
||||
faces->line_to(std::get<2>(seg),std::get<3>(seg) + height);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#if defined(HAVE_CAIRO)
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/std.hpp>
|
||||
#include <mapnik/rule.hpp>
|
||||
#include <mapnik/debug.hpp>
|
||||
#include <mapnik/layer.hpp>
|
||||
|
@ -361,8 +362,8 @@ void cairo_renderer_base::process(building_symbolizer const& sym,
|
|||
|
||||
if (geom.size() > 2)
|
||||
{
|
||||
const std::unique_ptr<geometry_type> frame(new geometry_type(geometry_type::types::LineString));
|
||||
const std::unique_ptr<geometry_type> roof(new geometry_type(geometry_type::types::Polygon));
|
||||
const auto frame = std::make_unique<geometry_type>(geometry_type::types::LineString);
|
||||
const auto roof = std::make_unique<geometry_type>(geometry_type::types::Polygon);
|
||||
std::deque<segment_t> face_segments;
|
||||
double x0 = 0;
|
||||
double y0 = 0;
|
||||
|
@ -392,7 +393,7 @@ void cairo_renderer_base::process(building_symbolizer const& sym,
|
|||
|
||||
for (auto const& seg : face_segments)
|
||||
{
|
||||
const std::unique_ptr<geometry_type> faces(new geometry_type(geometry_type::types::Polygon));
|
||||
const auto faces = std::make_unique<geometry_type>(geometry_type::types::Polygon);
|
||||
faces->move_to(std::get<0>(seg), std::get<1>(seg));
|
||||
faces->line_to(std::get<2>(seg), std::get<3>(seg));
|
||||
faces->line_to(std::get<2>(seg), std::get<3>(seg) + height);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/std.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/grid/grid_rasterizer.hpp>
|
||||
#include <mapnik/grid/grid_renderer.hpp>
|
||||
|
@ -75,20 +76,19 @@ void grid_renderer<T>::process(building_symbolizer const& sym,
|
|||
|
||||
for (std::size_t i=0;i<feature.num_geometries();++i)
|
||||
{
|
||||
geometry_type & geom = feature.get_geometry(i);
|
||||
geometry_type const& geom = feature.get_geometry(i);
|
||||
if (geom.size() > 2)
|
||||
{
|
||||
const std::unique_ptr<geometry_type> frame(new geometry_type(geometry_type::types::LineString));
|
||||
const std::unique_ptr<geometry_type> roof(new geometry_type(geometry_type::types::Polygon));
|
||||
const auto frame = std::make_unique<geometry_type>(geometry_type::types::LineString);
|
||||
const auto roof = std::make_unique<geometry_type>(geometry_type::types::Polygon);
|
||||
std::deque<segment_t> face_segments;
|
||||
double x0(0);
|
||||
double y0(0);
|
||||
unsigned cm = geom.vertex(&x0,&y0);
|
||||
for (unsigned j=1;j<geom.size();++j)
|
||||
double x0 = 0;
|
||||
double y0 = 0;
|
||||
double x,y;
|
||||
geom.rewind(0);
|
||||
for (unsigned cm = geom.vertex(&x, &y); cm != SEG_END;
|
||||
cm = geom.vertex(&x, &y))
|
||||
{
|
||||
double x(0);
|
||||
double y(0);
|
||||
cm = geom.vertex(&x,&y);
|
||||
if (cm == SEG_MOVETO)
|
||||
{
|
||||
frame->move_to(x,y);
|
||||
|
@ -98,14 +98,17 @@ void grid_renderer<T>::process(building_symbolizer const& sym,
|
|||
frame->line_to(x,y);
|
||||
face_segments.push_back(segment_t(x0,y0,x,y));
|
||||
}
|
||||
|
||||
else if (cm == SEG_CLOSE)
|
||||
{
|
||||
frame->close_path();
|
||||
}
|
||||
x0 = x;
|
||||
y0 = y;
|
||||
}
|
||||
std::sort(face_segments.begin(),face_segments.end(), y_order);
|
||||
for ( auto const& seg : face_segments)
|
||||
{
|
||||
const std::unique_ptr<geometry_type> faces(new geometry_type(geometry_type::types::Polygon));
|
||||
const auto faces = std::make_unique<geometry_type>(geometry_type::types::Polygon);
|
||||
faces->move_to(std::get<0>(seg),std::get<1>(seg));
|
||||
faces->line_to(std::get<2>(seg),std::get<3>(seg));
|
||||
faces->line_to(std::get<2>(seg),std::get<3>(seg) + height);
|
||||
|
@ -122,10 +125,9 @@ void grid_renderer<T>::process(building_symbolizer const& sym,
|
|||
}
|
||||
|
||||
geom.rewind(0);
|
||||
for (unsigned j=0;j<geom.size();++j)
|
||||
for (unsigned cm = geom.vertex(&x, &y); cm != SEG_END;
|
||||
cm = geom.vertex(&x, &y))
|
||||
{
|
||||
double x,y;
|
||||
cm = geom.vertex(&x,&y);
|
||||
if (cm == SEG_MOVETO)
|
||||
{
|
||||
frame->move_to(x,y+height);
|
||||
|
@ -136,6 +138,11 @@ void grid_renderer<T>::process(building_symbolizer const& sym,
|
|||
frame->line_to(x,y+height);
|
||||
roof->line_to(x,y+height);
|
||||
}
|
||||
else if (cm == SEG_CLOSE)
|
||||
{
|
||||
frame->close_path();
|
||||
roof->close_path();
|
||||
}
|
||||
}
|
||||
path_type path(t_,*frame,prj_trans);
|
||||
agg::conv_stroke<path_type> stroke(path);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/std.hpp>
|
||||
#include <mapnik/debug.hpp>
|
||||
#include <mapnik/image_reader.hpp>
|
||||
|
||||
|
@ -165,7 +166,7 @@ webp_reader<T>::webp_reader(std::string const& filename)
|
|||
std::size_t file_size = end - beg;
|
||||
file.seekg (0, std::ios::beg);
|
||||
|
||||
std::unique_ptr<buffer_policy_type> buffer(new buffer_policy_type(file_size));
|
||||
auto buffer = std::make_unique<buffer_policy_type>(file_size);
|
||||
file.read(reinterpret_cast<char*>(buffer->data()), buffer->size());
|
||||
if (!file)
|
||||
{
|
||||
|
|
13
src/wkb.cpp
13
src/wkb.cpp
|
@ -21,6 +21,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/std.hpp>
|
||||
#include <mapnik/debug.hpp>
|
||||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
|
@ -250,7 +251,7 @@ private:
|
|||
{
|
||||
double x = read_double();
|
||||
double y = read_double();
|
||||
std::unique_ptr<geometry_type> pt(new geometry_type(geometry_type::types::Point));
|
||||
auto pt = std::make_unique<geometry_type>(geometry_type::types::Point);
|
||||
pt->move_to(x, y);
|
||||
paths.push_back(pt.release());
|
||||
}
|
||||
|
@ -269,7 +270,7 @@ private:
|
|||
{
|
||||
double x = read_double();
|
||||
double y = read_double();
|
||||
std::unique_ptr<geometry_type> pt(new geometry_type(geometry_type::types::Point));
|
||||
auto pt = std::make_unique<geometry_type>(geometry_type::types::Point);
|
||||
pos_ += 8; // double z = read_double();
|
||||
pt->move_to(x, y);
|
||||
paths.push_back(pt.release());
|
||||
|
@ -292,7 +293,7 @@ private:
|
|||
{
|
||||
CoordinateArray ar(num_points);
|
||||
read_coords(ar);
|
||||
std::unique_ptr<geometry_type> line(new geometry_type(geometry_type::types::LineString));
|
||||
auto line = std::make_unique<geometry_type>(geometry_type::types::LineString);
|
||||
line->move_to(ar[0].x, ar[0].y);
|
||||
for (int i = 1; i < num_points; ++i)
|
||||
{
|
||||
|
@ -319,7 +320,7 @@ private:
|
|||
{
|
||||
CoordinateArray ar(num_points);
|
||||
read_coords_xyz(ar);
|
||||
std::unique_ptr<geometry_type> line(new geometry_type(geometry_type::types::LineString));
|
||||
auto line = std::make_unique<geometry_type>(geometry_type::types::LineString);
|
||||
line->move_to(ar[0].x, ar[0].y);
|
||||
for (int i = 1; i < num_points; ++i)
|
||||
{
|
||||
|
@ -345,7 +346,7 @@ private:
|
|||
int num_rings = read_integer();
|
||||
if (num_rings > 0)
|
||||
{
|
||||
std::unique_ptr<geometry_type> poly(new geometry_type(geometry_type::types::Polygon));
|
||||
auto poly = std::make_unique<geometry_type>(geometry_type::types::Polygon);
|
||||
for (int i = 0; i < num_rings; ++i)
|
||||
{
|
||||
int num_points = read_integer();
|
||||
|
@ -381,7 +382,7 @@ private:
|
|||
int num_rings = read_integer();
|
||||
if (num_rings > 0)
|
||||
{
|
||||
std::unique_ptr<geometry_type> poly(new geometry_type(geometry_type::types::Polygon));
|
||||
auto poly = std::make_unique<geometry_type>(geometry_type::types::Polygon);
|
||||
for (int i = 0; i < num_rings; ++i)
|
||||
{
|
||||
int num_points = read_integer();
|
||||
|
|
Loading…
Reference in a new issue