Skip to content

Commit 3dc2233

Browse files
committed
Add lots of const's
1 parent 7b9b686 commit 3dc2233

File tree

70 files changed

+320
-320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+320
-320
lines changed

benchmarks/osmium_benchmark_static_vs_dynamic_index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int main(int argc, char* argv[]) {
4747
try {
4848
const std::string input_filename{argv[1]};
4949

50-
osmium::memory::Buffer buffer{osmium::io::read_file(input_filename)};
50+
const osmium::memory::Buffer buffer{osmium::io::read_file(input_filename)};
5151

5252
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
5353

benchmarks/osmium_benchmark_write_pbf.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ int main(int argc, char* argv[]) {
1818
}
1919

2020
try {
21-
std::string input_filename{argv[1]};
22-
std::string output_filename{argv[2]};
21+
const std::string input_filename{argv[1]};
22+
const std::string output_filename{argv[2]};
2323

2424
osmium::io::Reader reader{input_filename};
25-
osmium::io::File output_file{output_filename, "pbf"};
26-
osmium::io::Header header;
25+
const osmium::io::File output_file{output_filename, "pbf"};
26+
const osmium::io::Header header;
2727
osmium::io::Writer writer{output_file, header, osmium::io::overwrite::allow};
2828

2929
while (osmium::memory::Buffer buffer = reader.read()) { // NOLINT(bugprone-use-after-move) Bug in clang-tidy https://bugs.llvm.org/show_bug.cgi?id=36516

examples/osmium_area_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ int main(int argc, char* argv[]) {
122122
return 1;
123123
}
124124

125-
osmium::io::File input_file{argv[2]};
125+
const osmium::io::File input_file{argv[2]};
126126

127127
// Configuration for the multipolygon assembler. Here the default settings
128128
// are used, but you could change multiple settings.
129-
osmium::area::Assembler::config_type assembler_config;
129+
const osmium::area::Assembler::config_type assembler_config;
130130

131131
// Set up a filter matching only forests. This will be used to only build
132132
// areas with matching tags.

examples/osmium_change_tags.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ int main(int argc, char* argv[]) {
153153
}
154154

155155
// Get input and output file names from command line.
156-
std::string input_file_name{argv[1]};
157-
std::string output_file_name{argv[2]};
156+
const std::string input_file_name{argv[1]};
157+
const std::string output_file_name{argv[2]};
158158

159159
try {
160160
// Initialize Reader

examples/osmium_count.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int main(int argc, char* argv[]) {
6868
try {
6969
// The Reader is initialized here with an osmium::io::File, but could
7070
// also be directly initialized with a file name.
71-
osmium::io::File input_file{argv[1]};
71+
const osmium::io::File input_file{argv[1]};
7272
osmium::io::Reader reader{input_file};
7373

7474
// Create an instance of our own CountHandler and push the data from the
@@ -88,7 +88,7 @@ int main(int argc, char* argv[]) {
8888
// (though not this one) can use huge amounts of data. So checking actual
8989
// memore usage is often useful and can be done easily with this class.
9090
// (Currently only works on Linux, not macOS and Windows.)
91-
osmium::MemoryUsage memory;
91+
const osmium::MemoryUsage memory;
9292

9393
std::cout << "\nMemory used: " << memory.peak() << " MBytes\n";
9494
} catch (const std::exception& e) {

examples/osmium_create_pois.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ int main(int argc, char* argv[]) {
4040
}
4141

4242
// Get output file name from command line.
43-
std::string output_file_name{argv[1]};
43+
const std::string output_file_name{argv[1]};
4444

4545
// If output file name is "-", this means STDOUT. Set the OPL file type
4646
// in this case. Otherwise take the file type from the file name suffix.
47-
osmium::io::File output_file{output_file_name, output_file_name == "-" ? ".opl" : ""};
47+
const osmium::io::File output_file{output_file_name, output_file_name == "-" ? ".opl" : ""};
4848

4949
try {
5050
// Create a buffer where all objects will live. Use a sensible initial

examples/osmium_debug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int main(int argc, char* argv[]) {
4343
// Get entity types from command line if there is a 2nd argument.
4444
if (argc == 3) {
4545
read_types = osmium::osm_entity_bits::nothing;
46-
std::string types = argv[2];
46+
const std::string types = argv[2];
4747
if (types.find('n') != std::string::npos) {
4848
read_types |= osmium::osm_entity_bits::node;
4949
}

examples/osmium_dump_internal.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,31 +165,31 @@ int main(int argc, char* argv[]) {
165165
reader.close();
166166

167167
// Write out node, way, and relation offset indexes to disk.
168-
IndexFile nodes_idx{output_dir + "/nodes.idx"};
168+
const IndexFile nodes_idx{output_dir + "/nodes.idx"};
169169
node_index.dump_as_list(nodes_idx.fd());
170170

171-
IndexFile ways_idx{output_dir + "/ways.idx"};
171+
const IndexFile ways_idx{output_dir + "/ways.idx"};
172172
way_index.dump_as_list(ways_idx.fd());
173173

174-
IndexFile relations_idx{output_dir + "/relations.idx"};
174+
const IndexFile relations_idx{output_dir + "/relations.idx"};
175175
relation_index.dump_as_list(relations_idx.fd());
176176

177177
// Sort the maps (so later binary search will work on them) and write
178178
// them to disk.
179179
map_node2way.sort();
180-
IndexFile node2way_idx{output_dir + "/node2way.map"};
180+
const IndexFile node2way_idx{output_dir + "/node2way.map"};
181181
map_node2way.dump_as_list(node2way_idx.fd());
182182

183183
map_node2relation.sort();
184-
IndexFile node2relation_idx{output_dir + "/node2rel.map"};
184+
const IndexFile node2relation_idx{output_dir + "/node2rel.map"};
185185
map_node2relation.dump_as_list(node2relation_idx.fd());
186186

187187
map_way2relation.sort();
188-
IndexFile way2relation_idx{output_dir + "/way2rel.map"};
188+
const IndexFile way2relation_idx{output_dir + "/way2rel.map"};
189189
map_way2relation.dump_as_list(way2relation_idx.fd());
190190

191191
map_relation2relation.sort();
192-
IndexFile relation2relation_idx{output_dir + "/rel2rel.map"};
192+
const IndexFile relation2relation_idx{output_dir + "/rel2rel.map"};
193193
map_relation2relation.dump_as_list(relation2relation_idx.fd());
194194
} catch (const std::exception& e) {
195195
// All exceptions used by the Osmium library derive from std::exception.

examples/osmium_filter_discussions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ int main(int argc, char* argv[]) {
4747

4848
try {
4949
// The input file, deduce file format from file suffix.
50-
osmium::io::File input_file{argv[1]};
50+
const osmium::io::File input_file{argv[1]};
5151

5252
// The output file, force XML OSM file format.
53-
osmium::io::File output_file{argv[2], "osm"};
53+
const osmium::io::File output_file{argv[2], "osm"};
5454

5555
// Initialize Reader for the input file.
5656
// Read only changesets (will ignore nodes, ways, and

examples/osmium_index_lookup.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class IndexAccessDense : public IndexAccess<TValue> {
106106
~IndexAccessDense() noexcept override = default;
107107

108108
void dump() const override {
109-
index_type index{this->fd()};
109+
const index_type index{this->fd()};
110110

111111
for (std::size_t i = 0; i < index.size(); ++i) {
112112
if (index.get(i) != TValue{}) {
@@ -116,7 +116,7 @@ class IndexAccessDense : public IndexAccess<TValue> {
116116
}
117117

118118
bool search(const osmium::unsigned_object_id_type& key) const override {
119-
index_type index{this->fd()};
119+
const index_type index{this->fd()};
120120

121121
try {
122122
TValue value = index.get(key);
@@ -153,7 +153,7 @@ class IndexAccessSparse : public IndexAccess<TValue> {
153153
~IndexAccessSparse() noexcept override = default;
154154

155155
void dump() const override {
156-
index_type index{this->fd()};
156+
const index_type index{this->fd()};
157157

158158
for (const auto& element : index) {
159159
std::cout << element.first << " " << element.second << "\n";
@@ -164,7 +164,7 @@ class IndexAccessSparse : public IndexAccess<TValue> {
164164
using element_type = typename index_type::element_type;
165165
index_type index{this->fd()};
166166

167-
element_type elem{key, TValue{}};
167+
const element_type elem{key, TValue{}};
168168
const auto positions = std::equal_range(index.begin(),
169169
index.end(),
170170
elem,
@@ -347,7 +347,7 @@ int run(const IndexAccess<TValue>& index, const Options& options) {
347347

348348
int main(int argc, char* argv[]) {
349349
// Parse command line options.
350-
Options options{argc, argv};
350+
const Options options{argc, argv};
351351

352352
// Open the index file.
353353
const int fd = ::open(options.filename(), O_RDWR);

examples/osmium_read.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ int main(int argc, char* argv[]) {
2727
try {
2828
// The Reader is initialized here with an osmium::io::File, but could
2929
// also be directly initialized with a file name.
30-
osmium::io::File input_file{argv[1]};
30+
const osmium::io::File input_file{argv[1]};
3131
osmium::io::Reader reader{input_file};
3232

3333
// OSM data comes in buffers, read until there are no more.
34-
while (osmium::memory::Buffer buffer = reader.read()) {
34+
while (const osmium::memory::Buffer buffer = reader.read()) {
3535
// do nothing
3636
}
3737

examples/osmium_read_with_progress.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ int main(int argc, char* argv[]) {
3434
try {
3535
// The Reader is initialized here with an osmium::io::File, but could
3636
// also be directly initialized with a file name.
37-
osmium::io::File input_file{argv[1]};
37+
const osmium::io::File input_file{argv[1]};
3838
osmium::io::Reader reader{input_file};
3939

4040
// Initialize progress bar, enable it only if STDERR is a TTY.
4141
osmium::ProgressBar progress{reader.file_size(), osmium::isatty(2)};
4242

4343
// OSM data comes in buffers, read until there are no more.
44-
while (osmium::memory::Buffer buffer = reader.read()) {
44+
while (const osmium::memory::Buffer buffer = reader.read()) {
4545
// Update progress bar for each buffer.
4646
progress.update(reader.offset());
4747
}

include/osmium/area/assembler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ namespace osmium {
213213

214214
// Now create the Area object and add the attributes and tags
215215
// from the relation.
216-
bool okay = create_area(out_buffer, relation, members);
216+
const bool okay = create_area(out_buffer, relation, members);
217217
if (okay) {
218218
out_buffer.commit();
219219
} else {

include/osmium/area/assembler_legacy.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,10 @@ namespace osmium {
332332
if (!way.nodes().empty() && way.is_closed() && !way.tags().empty()) {
333333
const auto d = std::count_if(way.tags().cbegin(), way.tags().cend(), std::cref(filter()));
334334
if (d > 0) {
335-
osmium::tags::KeyFilter::iterator way_fi_begin(std::cref(filter()), way.tags().cbegin(), way.tags().cend());
336-
osmium::tags::KeyFilter::iterator way_fi_end(std::cref(filter()), way.tags().cend(), way.tags().cend());
337-
osmium::tags::KeyFilter::iterator area_fi_begin(std::cref(filter()), area_tags.cbegin(), area_tags.cend());
338-
osmium::tags::KeyFilter::iterator area_fi_end(std::cref(filter()), area_tags.cend(), area_tags.cend());
335+
const osmium::tags::KeyFilter::iterator way_fi_begin(std::cref(filter()), way.tags().cbegin(), way.tags().cend());
336+
const osmium::tags::KeyFilter::iterator way_fi_end(std::cref(filter()), way.tags().cend(), way.tags().cend());
337+
const osmium::tags::KeyFilter::iterator area_fi_begin(std::cref(filter()), area_tags.cbegin(), area_tags.cend());
338+
const osmium::tags::KeyFilter::iterator area_fi_end(std::cref(filter()), area_tags.cend(), area_tags.cend());
339339
#ifdef __cpp_lib_robust_nonmodifying_seq_ops
340340
if (!std::equal(way_fi_begin, way_fi_end, area_fi_begin, area_fi_end)) {
341341
#else

include/osmium/area/detail/basic_assembler.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ namespace osmium {
608608

609609
void create_rings_simple_case() {
610610
auto count_remaining = m_segment_list.size();
611-
for (slocation& sl : m_locations) {
611+
for (const slocation& sl : m_locations) {
612612
const NodeRefSegment& segment = m_segment_list[sl.item];
613613
if (!segment.is_done()) {
614614
count_remaining -= add_new_ring(sl);
@@ -671,7 +671,7 @@ namespace osmium {
671671
std::cerr << " Trying to merge " << open_ring_its.size() << " open rings (try_to_merge)\n";
672672
}
673673

674-
std::vector<location_to_ring_map> xrings = create_location_to_ring_map(open_ring_its);
674+
const auto xrings = create_location_to_ring_map(open_ring_its);
675675

676676
auto it = xrings.cbegin();
677677
while (it != xrings.cend()) {
@@ -825,7 +825,7 @@ namespace osmium {
825825

826826
find_inner_outer_complex();
827827
ProtoRing* outer_ring = find_enclosing_ring(ring_min->ring().min_segment());
828-
bool ring_min_is_outer = !outer_ring;
828+
const bool ring_min_is_outer = !outer_ring;
829829
if (debug()) {
830830
std::cerr << " Open ring is " << (ring_min_is_outer ? "outer" : "inner") << " ring\n";
831831
}
@@ -924,7 +924,7 @@ namespace osmium {
924924

925925
// Now find all the rest of the rings (ie not starting at split locations)
926926
if (count_remaining > 0) {
927-
for (slocation& sl : m_locations) {
927+
for (const slocation& sl : m_locations) {
928928
const NodeRefSegment& segment = m_segment_list[sl.item];
929929
if (!segment.is_done()) {
930930
count_remaining -= add_new_ring_complex(sl);

include/osmium/area/detail/segment_list.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ namespace osmium {
333333
}
334334

335335
if (y_range_overlap(s1, s2)) {
336-
osmium::Location intersection{calculate_intersection(s1, s2)};
336+
const osmium::Location intersection{calculate_intersection(s1, s2)};
337337
if (intersection) {
338338
++found_intersections;
339339
if (m_debug) {

include/osmium/geom/wkb.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace osmium {
6868
std::string out;
6969
out.reserve(str.size() * 2);
7070

71-
for (char c : str) {
71+
for (const char c : str) {
7272
out += lookup_hex[(static_cast<unsigned int>(c) >> 4U) & 0xfU];
7373
out += lookup_hex[ static_cast<unsigned int>(c) & 0xfU];
7474
}

include/osmium/index/detail/vector_map.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ namespace osmium {
241241
void dump_as_array(const int fd) final {
242242
constexpr const size_t value_size = sizeof(TValue);
243243
constexpr const size_t buffer_size = (10L * 1024L * 1024L) / value_size;
244-
std::unique_ptr<TValue[]> output_buffer{new TValue[buffer_size]};
244+
const std::unique_ptr<TValue[]> output_buffer{new TValue[buffer_size]};
245245

246246
size_t buffer_start_id = 0;
247247
for (auto it = cbegin(); it != cend();) {

include/osmium/io/compression.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ namespace osmium {
199199
const create_decompressor_type_fd& create_decompressor_fd,
200200
const create_decompressor_type_buffer& create_decompressor_buffer) {
201201

202-
compression_map_type::value_type cc{compression,
203-
std::make_tuple(create_compressor,
204-
create_decompressor_fd,
205-
create_decompressor_buffer)};
202+
const compression_map_type::value_type cc{compression,
203+
std::make_tuple(create_compressor,
204+
create_decompressor_fd,
205+
create_decompressor_buffer)};
206206

207207
return m_callbacks.insert(cc).second;
208208
}

include/osmium/io/detail/opl_parser_functions.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ namespace osmium {
592592
osmium::builder::RelationMemberListBuilder builder{buffer, parent_builder};
593593

594594
while (s < e) {
595-
osmium::item_type type = osmium::char_to_item_type(*s);
595+
const osmium::item_type type = osmium::char_to_item_type(*s);
596596
if (type != osmium::item_type::node &&
597597
type != osmium::item_type::way &&
598598
type != osmium::item_type::relation) {
@@ -603,7 +603,7 @@ namespace osmium {
603603
if (s == e) {
604604
throw opl_error{"expected integer", s};
605605
}
606-
osmium::object_id_type ref = opl_parse_id(&s);
606+
const osmium::object_id_type ref = opl_parse_id(&s);
607607
opl_parse_char(&s, '@');
608608
if (s == e) {
609609
builder.add_member(type, ref, "");

include/osmium/io/detail/pbf_input_format.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ namespace osmium {
245245
// Parse the header in the PBF OSMHeader blob.
246246
void parse_header_blob() {
247247
const auto size = check_type_and_get_blob_size("OSMHeader");
248-
osmium::io::Header header{decode_header(read_from_input_queue_with_check(size))};
248+
const osmium::io::Header header{decode_header(read_from_input_queue_with_check(size))};
249249
set_header_value(header);
250250
}
251251

include/osmium/io/detail/pbf_output_format.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ namespace osmium {
645645

646646
const std::string osmosis_replication_timestamp{header.get("osmosis_replication_timestamp")};
647647
if (!osmosis_replication_timestamp.empty()) {
648-
osmium::Timestamp ts{osmosis_replication_timestamp.c_str()};
648+
const osmium::Timestamp ts{osmosis_replication_timestamp.c_str()};
649649
pbf_header_block.add_int64(OSMFormat::HeaderBlock::optional_int64_osmosis_replication_timestamp, uint32_t(ts));
650650
}
651651

include/osmium/io/detail/string_util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ namespace osmium {
259259

260260
while (data != end_ptr) {
261261
const char* prev = data;
262-
uint32_t c = next_utf8_codepoint(&data, end_ptr);
262+
const uint32_t c = next_utf8_codepoint(&data, end_ptr);
263263

264264
// This is a list of Unicode code points that we let
265265
// through instead of escaping them. It is incomplete

include/osmium/io/file.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ namespace osmium {
163163
if (pos == std::string::npos) {
164164
set(option, true);
165165
} else {
166-
std::string value{option.substr(pos + 1)};
166+
const std::string value{option.substr(pos + 1)};
167167
option.erase(pos);
168168
set(option, value);
169169
}

include/osmium/io/gzip_compression.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ namespace osmium {
230230
#endif
231231
std::string buffer(osmium::io::Decompressor::input_buffer_size, '\0');
232232
assert(buffer.size() < std::numeric_limits<unsigned int>::max());
233-
int nread = ::gzread(m_gzfile, &*buffer.begin(), static_cast<unsigned int>(buffer.size()));
233+
const int nread = ::gzread(m_gzfile, &*buffer.begin(), static_cast<unsigned int>(buffer.size()));
234234
if (nread < 0) {
235235
detail::throw_gzip_error(m_gzfile, "read failed");
236236
}

include/osmium/osm/area.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ namespace osmium {
223223
* all inner rings.
224224
*/
225225
osmium::memory::ItemIteratorRange<const osmium::InnerRing> inner_rings(const osmium::OuterRing& outer) const {
226-
osmium::memory::ItemIteratorRange<const osmium::OuterRing> outer_range{outer.data(), next()};
226+
const osmium::memory::ItemIteratorRange<const osmium::OuterRing> outer_range{outer.data(), next()};
227227
return osmium::memory::ItemIteratorRange<const osmium::InnerRing>{outer_range.cbegin().data(), std::next(outer_range.cbegin()).data()};
228228
}
229229

0 commit comments

Comments
 (0)