Skip to content

Commit 61d415b

Browse files
committed
Avoid C-style casts
1 parent 4fa9208 commit 61d415b

24 files changed

+87
-87
lines changed

examples/osmium_tiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int main(int argc, char* argv[]) {
6868

6969
// Create a tile at this location. This will also internally use the
7070
// Mercator projection and then calculate the tile coordinates.
71-
const osmium::geom::Tile tile{uint32_t(zoom), location};
71+
const osmium::geom::Tile tile{static_cast<uint32_t>(zoom), location};
7272
std::cout << "Tile: zoom=" << tile.z << " x=" << tile.x << " y=" << tile.y << "\n";
7373
}
7474

include/osmium/area/detail/node_ref_segment.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ namespace osmium {
193193

194194
const char* role_name() const noexcept {
195195
static const std::array<const char*, 4> names = {{"unknown", "outer", "inner", "empty"}};
196-
return names[int(m_role)];
196+
return names[static_cast<int>(m_role)];
197197
}
198198

199199
const osmium::Way* way() const noexcept {
@@ -327,9 +327,9 @@ namespace osmium {
327327

328328
if ((d > 0 && na >= 0 && na <= d && nb >= 0 && nb <= d) ||
329329
(d < 0 && na <= 0 && na >= d && nb <= 0 && nb >= d)) {
330-
const double ua = double(na) / double(d);
330+
const double ua = static_cast<double>(na) / static_cast<double>(d);
331331
const vec i = p0 + ua * (p1 - p0);
332-
return osmium::Location{int32_t(i.x), int32_t(i.y)};
332+
return osmium::Location{static_cast<int32_t>(i.x), static_cast<int32_t>(i.y)};
333333
}
334334

335335
return osmium::Location{};

include/osmium/area/detail/vector.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ namespace osmium {
8989

9090
// scale vector
9191
constexpr inline vec operator*(double s, const vec& v) noexcept {
92-
return vec{int64_t(s * double(v.x)), int64_t(s * double(v.y))};
92+
return vec{static_cast<int64_t>(s * static_cast<double>(v.x)), static_cast<int64_t>(s * static_cast<double>(v.y))};
9393
}
9494

9595
// scale vector
9696
constexpr inline vec operator*(const vec& v, double s) noexcept {
97-
return vec{int64_t(s * double(v.x)), int64_t(s * double(v.y))};
97+
return vec{static_cast<int64_t>(s * static_cast<double>(v.x)), static_cast<int64_t>(s * static_cast<double>(v.y))};
9898
}
9999

100100
// equality

include/osmium/area/problem_reporter_ogr.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ namespace osmium {
7575
void set_object(gdalcpp::Feature& feature) {
7676
const char t[2] = {osmium::item_type_to_char(m_object_type), '\0'};
7777
feature.set_field("obj_type", t);
78-
feature.set_field("obj_id", int32_t(m_object_id));
79-
feature.set_field("nodes", int32_t(m_nodes));
78+
feature.set_field("obj_id", static_cast<int32_t>(m_object_id));
79+
feature.set_field("nodes", static_cast<int32_t>(m_nodes));
8080
}
8181

8282
void write_point(const char* problem_type, osmium::object_id_type id1, osmium::object_id_type id2, osmium::Location location) {
8383
gdalcpp::Feature feature{m_layer_perror, m_ogr_factory.create_point(location)};
8484
set_object(feature);
85-
feature.set_field("id1", double(id1));
86-
feature.set_field("id2", double(id2));
85+
feature.set_field("id1", static_cast<double>(id1));
86+
feature.set_field("id2", static_cast<double>(id2));
8787
feature.set_field("problem", problem_type);
8888
feature.add_to_layer();
8989
}
@@ -176,7 +176,7 @@ namespace osmium {
176176
try {
177177
gdalcpp::Feature feature{m_layer_lerror, m_ogr_factory.create_linestring(way)};
178178
set_object(feature);
179-
feature.set_field("id1", int32_t(way.id()));
179+
feature.set_field("id1", static_cast<int32_t>(way.id()));
180180
feature.set_field("id2", 0);
181181
feature.set_field("problem", "way_in_multiple_rings");
182182
feature.add_to_layer();
@@ -192,7 +192,7 @@ namespace osmium {
192192
try {
193193
gdalcpp::Feature feature{m_layer_lerror, m_ogr_factory.create_linestring(way)};
194194
set_object(feature);
195-
feature.set_field("id1", int32_t(way.id()));
195+
feature.set_field("id1", static_cast<int32_t>(way.id()));
196196
feature.set_field("id2", 0);
197197
feature.set_field("problem", "inner_with_same_tags");
198198
feature.add_to_layer();
@@ -208,7 +208,7 @@ namespace osmium {
208208
try {
209209
gdalcpp::Feature feature{m_layer_lerror, m_ogr_factory.create_linestring(way)};
210210
set_object(feature);
211-
feature.set_field("id1", int32_t(way.id()));
211+
feature.set_field("id1", static_cast<int32_t>(way.id()));
212212
feature.set_field("id2", 0);
213213
feature.set_field("problem", "duplicate_way");
214214
feature.add_to_layer();
@@ -229,7 +229,7 @@ namespace osmium {
229229
try {
230230
gdalcpp::Feature feature{m_layer_ways, m_ogr_factory.create_linestring(way)};
231231
set_object(feature);
232-
feature.set_field("way_id", int32_t(way.id()));
232+
feature.set_field("way_id", static_cast<int32_t>(way.id()));
233233
feature.add_to_layer();
234234
} catch (const osmium::geometry_error&) {
235235
// XXX

include/osmium/builder/osm_object_builder.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ namespace osmium {
125125
if (value_length > osmium::max_osm_string_length) {
126126
throw std::length_error{"OSM tag value is too long"};
127127
}
128-
add_size(append_with_zero(key, osmium::memory::item_size_type(key_length)));
129-
add_size(append_with_zero(value, osmium::memory::item_size_type(value_length)));
128+
add_size(append_with_zero(key, static_cast<osmium::memory::item_size_type>(key_length)));
129+
add_size(append_with_zero(value, static_cast<osmium::memory::item_size_type>(value_length)));
130130
}
131131

132132
/**
@@ -142,8 +142,8 @@ namespace osmium {
142142
if (value.size() > osmium::max_osm_string_length) {
143143
throw std::length_error{"OSM tag value is too long"};
144144
}
145-
add_size(append(key.data(), osmium::memory::item_size_type(key.size()) + 1));
146-
add_size(append(value.data(), osmium::memory::item_size_type(value.size()) + 1));
145+
add_size(append(key.data(), static_cast<osmium::memory::item_size_type>(key.size()) + 1));
146+
add_size(append(value.data(), static_cast<osmium::memory::item_size_type>(value.size()) + 1));
147147
}
148148

149149
/**
@@ -240,8 +240,8 @@ namespace osmium {
240240
if (length > osmium::max_osm_string_length) {
241241
throw std::length_error{"OSM relation member role is too long"};
242242
}
243-
member.set_role_size(osmium::string_size_type(length) + 1);
244-
add_size(append_with_zero(role, osmium::memory::item_size_type(length)));
243+
member.set_role_size(static_cast<osmium::string_size_type>(length) + 1);
244+
add_size(append_with_zero(role, static_cast<osmium::memory::item_size_type>(length)));
245245
add_padding(true);
246246
}
247247

@@ -330,16 +330,16 @@ namespace osmium {
330330
if (length > osmium::max_osm_string_length) {
331331
throw std::length_error{"OSM user name is too long"};
332332
}
333-
comment.set_user_size(osmium::string_size_type(length) + 1);
334-
add_size(append_with_zero(user, osmium::memory::item_size_type(length)));
333+
comment.set_user_size(static_cast<osmium::string_size_type>(length) + 1);
334+
add_size(append_with_zero(user, static_cast<osmium::memory::item_size_type>(length)));
335335
}
336336

337337
void add_text(osmium::ChangesetComment& comment, const char* text, const std::size_t length) {
338338
if (length > std::numeric_limits<osmium::changeset_comment_size_type>::max() - 1) {
339339
throw std::length_error{"OSM changeset comment is too long"};
340340
}
341-
comment.set_text_size(osmium::changeset_comment_size_type(length) + 1);
342-
add_size(append_with_zero(text, osmium::memory::item_size_type(length)));
341+
comment.set_text_size(static_cast<osmium::changeset_comment_size_type>(length) + 1);
342+
add_size(append_with_zero(text, static_cast<osmium::memory::item_size_type>(length)));
343343
add_padding(true);
344344
}
345345

include/osmium/io/compression.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ namespace osmium {
357357
osmium::io::detail::remove_buffered_pages(m_fd, m_offset);
358358
}
359359
const auto nread = detail::reliable_read(m_fd, &*buffer.begin(), osmium::io::Decompressor::input_buffer_size);
360-
buffer.resize(std::string::size_type(nread));
360+
buffer.resize(static_cast<std::string::size_type>(nread));
361361
}
362362

363363
m_offset += buffer.size();

include/osmium/io/detail/debug_output_format.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ namespace osmium {
392392
*m_out += " (open)\n";
393393
}
394394

395-
const int width = int(std::log10(way.nodes().size())) + 1;
395+
const int width = static_cast<int>(std::log10(way.nodes().size())) + 1;
396396
int n = 0;
397397
for (const auto& node_ref : way.nodes()) {
398398
write_diff();
@@ -427,7 +427,7 @@ namespace osmium {
427427
output_int(relation.members().size());
428428
*m_out += '\n';
429429

430-
const int width = int(std::log10(relation.members().size())) + 1;
430+
const int width = static_cast<int>(std::log10(relation.members().size())) + 1;
431431
int n = 0;
432432
for (const auto& member : relation.members()) {
433433
write_diff();
@@ -485,7 +485,7 @@ namespace osmium {
485485
output_int(changeset.num_comments());
486486
*m_out += '\n';
487487

488-
const int width = int(std::log10(changeset.num_comments())) + 1;
488+
const int width = static_cast<int>(std::log10(changeset.num_comments())) + 1;
489489
int n = 0;
490490
for (const auto& comment : changeset.discussion()) {
491491
write_counter(width, n++);

include/osmium/io/detail/opl_parser_functions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ namespace osmium {
243243
}
244244
}
245245

246-
return T(value);
246+
return static_cast<T>(value);
247247
}
248248

249249
inline osmium::object_id_type opl_parse_id(const char** s) {

include/osmium/io/detail/pbf_decoder.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ namespace osmium {
168168
const std::string start_of_string(str_view.data(), 20);
169169
throw osmium::pbf_error{"overlong string (" + start_of_string + "...) in string table"};
170170
}
171-
m_stringtable.emplace_back(str_view.data(), osmium::string_size_type(str_view.size()));
171+
m_stringtable.emplace_back(str_view.data(), static_cast<osmium::string_size_type>(str_view.size()));
172172
}
173173
}
174174

@@ -314,11 +314,11 @@ namespace osmium {
314314
}
315315

316316
int32_t convert_pbf_lon(const int64_t c) const noexcept {
317-
return int32_t((c * m_granularity + m_lon_offset) / resolution_convert);
317+
return static_cast<int32_t>((c * m_granularity + m_lon_offset) / resolution_convert);
318318
}
319319

320320
int32_t convert_pbf_lat(const int64_t c) const noexcept {
321-
return int32_t((c * m_granularity + m_lat_offset) / resolution_convert);
321+
return static_cast<int32_t>((c * m_granularity + m_lat_offset) / resolution_convert);
322322
}
323323

324324
void decode_node(const data_view& data) {
@@ -503,7 +503,7 @@ namespace osmium {
503503
throw osmium::pbf_error{"unknown relation member type"};
504504
}
505505
rml_builder.add_member(
506-
osmium::item_type(type + 1),
506+
static_cast<osmium::item_type>(type + 1),
507507
ref.update(refs.next_sint64()),
508508
r.first,
509509
r.second
@@ -788,7 +788,7 @@ namespace osmium {
788788
}
789789
case protozero::tag_and_type(FileFormat::Blob::optional_int32_raw_size, protozero::pbf_wire_type::varint):
790790
raw_size = pbf_blob.get_int32();
791-
if (raw_size <= 0 || uint32_t(raw_size) > max_uncompressed_blob_size) {
791+
if (raw_size <= 0 || static_cast<uint32_t>(raw_size) > max_uncompressed_blob_size) {
792792
throw osmium::pbf_error{"illegal blob size"};
793793
}
794794
break;

0 commit comments

Comments
 (0)