integrate various minor c++ style and cast fixes into master from c++11 branch

This commit is contained in:
Dane Springmeyer 2013-09-15 23:08:04 -07:00
parent b6040ac324
commit d3ab601e30
19 changed files with 110 additions and 114 deletions

View file

@ -139,27 +139,27 @@ inline expr_node& operator- (expr_node& expr)
return expr = unary_node<tags::negate>(expr);
}
inline expr_node & operator += ( expr_node &left ,const expr_node &right)
inline expr_node & operator += ( expr_node &left, expr_node const& right)
{
return left = binary_node<tags::plus>(left,right);
}
inline expr_node & operator -= ( expr_node &left ,const expr_node &right)
inline expr_node & operator -= ( expr_node &left, expr_node const& right)
{
return left = binary_node<tags::minus>(left,right);
}
inline expr_node & operator *= ( expr_node &left ,const expr_node &right)
inline expr_node & operator *= ( expr_node &left , expr_node const& right)
{
return left = binary_node<tags::mult>(left,right);
}
inline expr_node & operator /= ( expr_node &left ,const expr_node &right)
inline expr_node & operator /= ( expr_node &left , expr_node const& right)
{
return left = binary_node<tags::div>(left,right);
}
inline expr_node & operator %= ( expr_node &left ,const expr_node &right)
inline expr_node & operator %= ( expr_node &left , expr_node const& right)
{
return left = binary_node<tags::mod>(left,right);
}

View file

@ -38,10 +38,10 @@ public:
font_set(std::string const& name);
font_set(font_set const& rhs);
font_set& operator=(font_set const& rhs);
unsigned size() const;
std::size_t size() const;
void set_name(std::string const& name);
std::string const& get_name() const;
void add_face_name(std::string);
void add_face_name(std::string const& face_name);
std::vector<std::string> const& get_face_names() const;
~font_set();
private:

View file

@ -351,19 +351,19 @@ public:
pal_remap_.resize(sorted_pal_.size());
palette.clear();
palette.reserve(sorted_pal_.size());
for (unsigned i=0; i<sorted_pal_.size(); i++)
for (unsigned i=0; i<sorted_pal_.size(); ++i)
{
if (sorted_pal_[i].a<255)
{
pal_remap_[i] = palette.size();
pal_remap_[i] = static_cast<unsigned>(palette.size());
palette.push_back(sorted_pal_[i]);
}
}
for (unsigned i=0; i<sorted_pal_.size(); i++)
for (unsigned i=0; i<sorted_pal_.size(); ++i)
{
if (sorted_pal_[i].a==255)
{
pal_remap_[i] = palette.size();
pal_remap_[i] = static_cast<unsigned>(palette.size());
palette.push_back(sorted_pal_[i]);
}
}

View file

@ -300,7 +300,7 @@ public:
palette.push_back(rgb(byte(itr->reds/float(count)),
byte(itr->greens/float(count)),
byte(itr->blues/float(count))));
itr->index = palette.size() - 1;
itr->index = static_cast<unsigned>(palette.size()) - 1;
}
for (unsigned i=0; i < 8 ;++i)
{

View file

@ -88,7 +88,6 @@ void save_as_png(T1 & file,
writer.toStream(file);
return;
}
png_voidp error_ptr=0;
png_structp png_ptr=png_create_write_struct(PNG_LIBPNG_VER_STRING,
error_ptr,0, 0);
@ -275,7 +274,6 @@ void save_as_png(T & file, std::vector<mapnik::rgb> const& palette,
writer.toStream(file);
return;
}
png_voidp error_ptr=0;
png_structp png_ptr=png_create_write_struct(PNG_LIBPNG_VER_STRING,
error_ptr,0, 0);
@ -316,7 +314,7 @@ void save_as_png(T & file, std::vector<mapnik::rgb> const& palette,
PNG_COMPRESSION_TYPE_DEFAULT,PNG_FILTER_TYPE_DEFAULT);
png_color* pal = const_cast<png_color*>(reinterpret_cast<const png_color*>(&palette[0]));
png_set_PLTE(png_ptr, info_ptr, pal, palette.size());
png_set_PLTE(png_ptr, info_ptr, pal, static_cast<unsigned>(palette.size()));
// make transparent lowest indexes, so tRNS is small
if (alpha.size()>0)
@ -531,15 +529,12 @@ void save_as_png8_oct(T1 & file,
leftovers = 0;
}
std::vector<rgb> pal;
trees[j].setOffset(palette.size());
trees[j].setOffset( static_cast<unsigned>(palette.size()));
trees[j].create_palette(pal);
assert(pal.size() <= max_colors);
leftovers = cols[j]-pal.size();
cols[j] = pal.size();
for(unsigned i=0; i<pal.size(); i++)
{
palette.push_back(pal[i]);
}
leftovers = cols[j] - static_cast<unsigned>(pal.size());
cols[j] = static_cast<unsigned>(pal.size());
palette.insert(palette.begin(), pal.begin(), pal.end());
assert(palette.size() <= 256);
}
}

View file

@ -52,7 +52,7 @@ public:
public:
processed_text(face_manager<freetype_engine> & font_manager, double scale_factor);
void push_back(char_properties const& properties, mapnik::value_unicode_string const& text);
unsigned size() const { return expr_list_.size(); }
std::size_t size() const { return expr_list_.size(); }
unsigned empty() const { return expr_list_.empty(); }
void clear();
typedef std::list<processed_expression> expression_list;

View file

@ -919,7 +919,7 @@ public:
return vertices_.size() ? vertices_[vertices_.size() - 1].y : 0.0;
}
unsigned total_vertices() const
std::size_t total_vertices() const
{
return vertices_.size();
}

View file

@ -72,7 +72,7 @@ public:
text_ += text;
}
unsigned num_characters() const
std::size_t num_characters() const
{
return characters_.size();
}
@ -87,12 +87,12 @@ public:
return is_rtl;
}
char_info const& at(unsigned i) const
char_info const& at(std::size_t i) const
{
return characters_[i];
}
char_info const& operator[](unsigned i) const
char_info const& operator[](std::size_t i) const
{
return at(i);
}
@ -183,7 +183,7 @@ public:
}
/** Number of nodes. */
int num_nodes() const
std::size_t num_nodes() const
{
return nodes_.size();
}

View file

@ -86,6 +86,7 @@ static toff_t tiff_seek_proc(thandle_t fd, toff_t off, int whence)
// grow std::stringstream buffer (re: libtiff/tif_stream.cxx)
std::ios::pos_type pos = out->tellp();
// second check needed for clang (libcxx doesn't set failbit when seeking beyond the current buffer size
if( out->fail() || static_cast<std::streamoff>(off) != pos)
{
std::ios::iostate old_state;
@ -143,7 +144,7 @@ static toff_t tiff_size_proc(thandle_t fd)
out->seekp(0, std::ios::end);
std::ios::pos_type len = out->tellp();
out->seekp(pos);
return (toff_t)len;
return static_cast<toff_t>(len);
}
static tsize_t tiff_dummy_read_proc(thandle_t , tdata_t , tsize_t)
@ -167,6 +168,7 @@ void save_as_tiff(T1 & file, T2 const& image)
const int height = image.height();
const int scanline_size = sizeof(unsigned char) * width * 3;
TIFF* output = RealTIFFOpen("mapnik_tiff_stream",
"wm",
(thandle_t)&file,
@ -264,5 +266,4 @@ void save_as_tiff(T1 & file, T2 const& image)
}
#endif // MAPNIK_TIFF_IO_HPP

View file

@ -44,10 +44,10 @@ bool parse_dasharray(Iterator first, Iterator last, std::vector<double>& dasharr
using qi::lexeme;
#endif
using phoenix::push_back;
// SVG
// SVG
// dasharray ::= (length | percentage) (comma-wsp dasharray)?
// no support for 'percentage' as viewport is unknown at load_map
//
//
bool r = phrase_parse(first, last,
(double_[push_back(phoenix::ref(dasharray), _1)] %
#if BOOST_VERSION > 104200
@ -57,10 +57,10 @@ bool parse_dasharray(Iterator first, Iterator last, std::vector<double>& dasharr
#endif
| lit("none")),
qi::ascii::space);
if (first != last)
if (first != last)
{
return false;
}
return r;
}

View file

@ -42,11 +42,11 @@
#include <boost/fusion/include/boost_tuple.hpp>
#include <boost/type_traits/remove_pointer.hpp>
/*!
* adapted to conform to the concepts
* required by Karma to be recognized as a container of
* attributes for output generation.
*/
// adapted to conform to the concepts
// required by Karma to be recognized as a container of
// attributes for output generation.
namespace boost { namespace spirit { namespace traits {
// TODO - this needs to be made generic to any path type

View file

@ -44,7 +44,6 @@
#include <boost/fusion/include/at_c.hpp>
#include <boost/fusion/include/make_vector.hpp>
#include <boost/foreach.hpp>
#include <boost/array.hpp>
// mapnik

View file

@ -47,9 +47,11 @@ int webp_stream_write(const uint8_t* data, size_t data_size, const WebPPicture*
return true;
}
std::string webp_encoding_error(WebPEncodingError error) {
std::string webp_encoding_error(WebPEncodingError error)
{
std::string os;
switch (error) {
switch (error)
{
case VP8_ENC_ERROR_OUT_OF_MEMORY: os = "memory error allocating objects"; break;
case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY: os = "memory error while flushing bits"; break;
case VP8_ENC_ERROR_NULL_PARAMETER: os = "a pointer parameter is NULL"; break;
@ -83,19 +85,20 @@ void save_as_webp(T1& file,
// Add additional tuning
if (method >= 0) config.method = method;
#if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
#if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
config.lossless = !!lossless;
config.image_hint = static_cast<WebPImageHint>(image_hint);
#else
#ifdef _MSC_VER
#pragma NOTE(compiling against webp that does not support lossless flag)
#else
#ifdef _MSC_VER
#pragma NOTE(compiling against webp that does not support lossless flag)
#else
#warning "compiling against webp that does not support lossless flag"
#endif
#warning "compiling against webp that does not support lossless flag"
#endif
#endif
bool valid = WebPValidateConfig(&config);
if (!valid) {
if (!valid)
{
throw std::runtime_error("Invalid configuration");
}
@ -106,9 +109,9 @@ void save_as_webp(T1& file,
}
pic.width = image.width();
pic.height = image.height();
#if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
#if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
pic.use_argb = !!lossless;
#endif
#endif
int ok = 0;
if (alpha)
{
@ -120,11 +123,11 @@ void save_as_webp(T1& file,
{
int stride = sizeof(typename T2::pixel_type) * image.width();
uint8_t const* bytes = reinterpret_cast<uint8_t const*>(image.getBytes());
#if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
#if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
ok = WebPPictureImportRGBX(&pic, bytes, stride);
#else
#else
ok = WebPPictureImportRGBA(&pic, bytes, stride);
#endif
#endif
}
if (!ok)

View file

@ -48,12 +48,12 @@ font_set& font_set::operator=(font_set const& other)
font_set::~font_set() {}
unsigned font_set::size() const
std::size_t font_set::size() const
{
return face_names_.size();
}
void font_set::add_face_name(std::string face_name)
void font_set::add_face_name(std::string const& face_name)
{
face_names_.push_back(face_name);
}

View file

@ -162,8 +162,7 @@ void jpeg_reader<T>::skip(j_decompress_ptr cinfo, long count)
if (count <= 0) return; //A zero or negative skip count should be treated as a no-op.
jpeg_stream_wrapper* wrap = reinterpret_cast<jpeg_stream_wrapper*>(cinfo->src);
if (wrap->manager.bytes_in_buffer > 0u
&& static_cast<unsigned long>(count) < wrap->manager.bytes_in_buffer)
if (wrap->manager.bytes_in_buffer > 0 && count < wrap->manager.bytes_in_buffer)
{
wrap->manager.bytes_in_buffer -= count;
wrap->manager.next_input_byte = &wrap->buffer[BUF_SIZE - wrap->manager.bytes_in_buffer];
@ -191,7 +190,7 @@ void jpeg_reader<T>::attach_stream (j_decompress_ptr cinfo, input_stream* in)
cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(jpeg_stream_wrapper));
}
typename jpeg_reader::jpeg_stream_wrapper * src = reinterpret_cast<typename jpeg_reader::jpeg_stream_wrapper*> (cinfo->src);
jpeg_reader::jpeg_stream_wrapper * src = reinterpret_cast<jpeg_reader::jpeg_stream_wrapper*> (cinfo->src);
src->manager.init_source = init_source;
src->manager.fill_input_buffer = fill_input_buffer;
src->manager.skip_input_data = skip;

View file

@ -26,6 +26,7 @@
// stl
#include <sstream>
#include <iomanip>
#include <iterator>
namespace mapnik
{
@ -81,8 +82,8 @@ bool rgba_palette::valid() const
std::string rgba_palette::to_string() const
{
unsigned length = rgb_pal_.size();
unsigned alphaLength = alpha_pal_.size();
size_t length = rgb_pal_.size();
size_t alphaLength = alpha_pal_.size();
std::ostringstream str("");
str << "[Palette " << length;
if (length == 1)
@ -125,7 +126,7 @@ unsigned char rgba_palette::quantize(unsigned val) const
// find closest match based on mean of r,g,b,a
std::vector<rgba>::const_iterator pit =
std::lower_bound(sorted_pal_.begin(), sorted_pal_.end(), c, rgba::mean_sort_cmp());
index = pit - sorted_pal_.begin();
index = std::distance(sorted_pal_.begin(),pit);
if (index == sorted_pal_.size()) index--;
dr = sorted_pal_[index].r - c.r;

View file

@ -36,6 +36,7 @@
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/fusion/include/std_pair.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <string>
@ -160,7 +161,7 @@ bool parse_reader(svg_parser & parser, xmlTextReaderPtr reader)
catch (std::exception const& ex)
{
xmlFreeTextReader(reader);
throw;
throw ex;
}
xmlFreeTextReader(reader);
if (ret != 0)
@ -216,7 +217,7 @@ void start_element(svg_parser & parser, xmlTextReaderPtr reader)
if (xmlStrEqual(name, BAD_CAST "path"))
{
parse_path(parser,reader);
}
}
else if (xmlStrEqual(name, BAD_CAST "polygon") )
{
parse_polygon(parser,reader);
@ -230,7 +231,7 @@ void start_element(svg_parser & parser, xmlTextReaderPtr reader)
parse_line(parser,reader);
}
else if (xmlStrEqual(name, BAD_CAST "rect"))
{
{
parse_rect(parser,reader);
}
else if (xmlStrEqual(name, BAD_CAST "circle"))
@ -419,7 +420,7 @@ void parse_attr(svg_parser & parser, const xmlChar * name, const xmlChar * value
void parse_attr(svg_parser & parser, xmlTextReaderPtr reader)
{
const xmlChar *name, *value;
if (xmlTextReaderMoveToFirstAttribute(reader) == 1)
{
do
@ -553,33 +554,33 @@ void parse_line(svg_parser & parser, xmlTextReaderPtr reader)
double y2 = 0.0;
value = xmlTextReaderGetAttribute(reader, BAD_CAST "x1");
if (value)
if (value)
{
x1 = parse_double((const char*)value);
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "y1");
if (value)
if (value)
{
y1 = parse_double((const char*)value);
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "x2");
if (value)
if (value)
{
x2 = parse_double((const char*)value);
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "y2");
if (value)
if (value)
{
y2 = parse_double((const char*)value);
xmlFree(value);
}
parser.path_.begin_path();
parser.path_.move_to(x1, y1);
parser.path_.line_to(x2, y2);
@ -594,26 +595,26 @@ void parse_circle(svg_parser & parser, xmlTextReaderPtr reader)
double cy = 0.0;
double r = 0.0;
value = xmlTextReaderGetAttribute(reader, BAD_CAST "cx");
if (value)
if (value)
{
cx = parse_double((const char*)value);
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "cy");
if (value)
if (value)
{
cy = parse_double((const char*)value);
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "r");
if (value)
if (value)
{
r = parse_double((const char*)value);
xmlFree(value);
}
parser.path_.begin_path();
if(r != 0.0)
@ -635,33 +636,33 @@ void parse_ellipse(svg_parser & parser, xmlTextReaderPtr reader)
double ry = 0.0;
value = xmlTextReaderGetAttribute(reader, BAD_CAST "cx");
if (value)
if (value)
{
cx = parse_double((const char*)value);
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "cy");
if (value)
if (value)
{
cy = parse_double((const char*)value);
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "rx");
if (value)
if (value)
{
rx = parse_double((const char*)value);
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "ry");
if (value)
if (value)
{
ry = parse_double((const char*)value);
xmlFree(value);
}
parser.path_.begin_path();
if(rx != 0.0 && ry != 0.0)
@ -745,7 +746,7 @@ void parse_rect(svg_parser & parser, xmlTextReaderPtr reader)
if(rx < 0.0) throw std::runtime_error("parse_rect: Invalid rx");
if(ry < 0.0) throw std::runtime_error("parse_rect: Invalid ry");
parser.path_.begin_path();
if(rounded)
{
agg::rounded_rect r;
@ -781,7 +782,7 @@ void parse_gradient_stop(svg_parser & parser, xmlTextReaderPtr reader)
double opacity = 1.0;
value = xmlTextReaderGetAttribute(reader, BAD_CAST "offset");
if (value)
if (value)
{
offset = parse_double((const char*)value);
xmlFree(value);
@ -838,8 +839,7 @@ void parse_gradient_stop(svg_parser & parser, xmlTextReaderPtr reader)
}
stop_color.set_alpha(opacity*255);
stop_color.set_alpha(static_cast<uint8_t>(opacity * 255));
parser.temporary_gradient_.second.add_stop(offset, stop_color);
/*
@ -873,7 +873,7 @@ bool parse_common_gradient(svg_parser & parser, xmlTextReaderPtr reader)
// check if we should inherit from another tag
value = xmlTextReaderGetAttribute(reader, BAD_CAST "xlink:href");
if (value)
if (value)
{
if (value[0] == '#')
{
@ -889,7 +889,7 @@ bool parse_common_gradient(svg_parser & parser, xmlTextReaderPtr reader)
}
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "gradientUnits");
if (value)
{
@ -903,7 +903,7 @@ bool parse_common_gradient(svg_parser & parser, xmlTextReaderPtr reader)
}
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "gradientTransform");
if (value)
{
@ -942,14 +942,14 @@ void parse_radial_gradient(svg_parser & parser, xmlTextReaderPtr reader)
bool has_percent=true;
value = xmlTextReaderGetAttribute(reader, BAD_CAST "cx");
if (value)
if (value)
{
cx = parse_double_optional_percent((const char*)value, has_percent);
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "cy");
if (value)
if (value)
{
cy = parse_double_optional_percent((const char*)value, has_percent);
xmlFree(value);
@ -1006,28 +1006,28 @@ void parse_linear_gradient(svg_parser & parser, xmlTextReaderPtr reader)
bool has_percent=true;
value = xmlTextReaderGetAttribute(reader, BAD_CAST "x1");
if (value)
if (value)
{
x1 = parse_double_optional_percent((const char*)value, has_percent);
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "x2");
if (value)
if (value)
{
x2 = parse_double_optional_percent((const char*)value, has_percent);
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "y1");
if (value)
if (value)
{
y1 = parse_double_optional_percent((const char*)value, has_percent);
xmlFree(value);
}
value = xmlTextReaderGetAttribute(reader, BAD_CAST "y2");
if (value)
if (value)
{
y2 = parse_double_optional_percent((const char*)value, has_percent);
xmlFree(value);

View file

@ -212,7 +212,8 @@ void text_symbolizer_helper<FaceManagerT, DetectorT>::initialize_geometries()
{
bool largest_box_only = false;
std::size_t num_geom = feature_.num_geometries();
for (std::size_t i=0; i<num_geom; ++i)
for (std::size_t i = 0; i < num_geom; ++i)
{
geometry_type const& geom = feature_.get_geometry(i);

View file

@ -37,10 +37,7 @@ extern "C"
#include <tiffio.h>
}
namespace mapnik
{
namespace impl {
namespace mapnik { namespace impl {
static toff_t tiff_seek_proc(thandle_t fd, toff_t off, int whence)
{
@ -61,7 +58,7 @@ static toff_t tiff_seek_proc(thandle_t fd, toff_t off, int whence)
return static_cast<toff_t>(in->tellg());
}
static int tiff_close_proc(thandle_t /*fd*/)
static int tiff_close_proc(thandle_t)
{
return 0;
}
@ -86,16 +83,16 @@ static tsize_t tiff_read_proc(thandle_t fd, tdata_t buf, tsize_t size)
return static_cast<tsize_t>(in->gcount());
}
static tsize_t tiff_write_proc(thandle_t /*fd*/, tdata_t /*buf*/, tsize_t /*size*/)
static tsize_t tiff_write_proc(thandle_t , tdata_t , tsize_t)
{
return 0;
}
static void tiff_unmap_proc(thandle_t /*fd*/, tdata_t /*base*/, toff_t /*size*/)
static void tiff_unmap_proc(thandle_t, tdata_t, toff_t)
{
}
static int tiff_map_proc(thandle_t /*fd*/, tdata_t* /*pbase*/, toff_t* /*psize*/)
static int tiff_map_proc(thandle_t, tdata_t* , toff_t*)
{
return 0;
}
@ -152,7 +149,7 @@ private:
void read_stripped(unsigned x,unsigned y,image_data_32& image);
void read_tiled(unsigned x,unsigned y,image_data_32& image);
TIFF* open(std::istream & input);
static void on_error(const char* /*module*/, const char* fmt, va_list argptr);
static void on_error(const char* , const char* fmt, va_list argptr);
};
namespace
@ -207,7 +204,7 @@ tiff_reader<T>::tiff_reader(char const* data, std::size_t size)
}
template <typename T>
void tiff_reader<T>::on_error(const char* /*module*/, const char* fmt, va_list argptr)
void tiff_reader<T>::on_error(const char* , const char* fmt, va_list argptr)
{
char msg[10240];
vsprintf(msg, fmt, argptr);
@ -303,7 +300,7 @@ void tiff_reader<T>::read(unsigned x,unsigned y,image_data_32& image)
}
template <typename T>
void tiff_reader<T>::read_generic(unsigned /*x*/,unsigned /*y*/,image_data_32& /*image*/)
void tiff_reader<T>::read_generic(unsigned, unsigned, image_data_32&)
{
TIFF* tif = open(stream_);
if (tif)