Skip to content

Commit e01ff74

Browse files
committed
Move prepare_input_files() function into input.cpp
1 parent 2c4c422 commit e01ff74

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

src/input.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "format.hpp"
1111
#include "input.hpp"
12+
#include "logging.hpp"
1213
#include "osmdata.hpp"
1314
#include "progress-display.hpp"
1415

@@ -171,6 +172,38 @@ class queue_element_t
171172

172173
}; // class queue_element_t
173174

175+
std::vector<osmium::io::File>
176+
prepare_input_files(std::vector<std::string> const &input_files,
177+
std::string const &input_format, bool append)
178+
{
179+
std::vector<osmium::io::File> files;
180+
181+
for (auto const &filename : input_files) {
182+
osmium::io::File file{filename, input_format};
183+
184+
if (file.format() == osmium::io::file_format::unknown) {
185+
if (input_format.empty()) {
186+
throw std::runtime_error{
187+
"Cannot detect file format for '{}'. Try using -r."_format(
188+
filename)};
189+
}
190+
throw std::runtime_error{
191+
"Unknown file format '{}'."_format(input_format)};
192+
}
193+
194+
if (!append && file.has_multiple_object_versions()) {
195+
throw std::runtime_error{
196+
"Reading an OSM change file only works in append mode."};
197+
}
198+
199+
log_debug("Reading file: {}", filename);
200+
201+
files.emplace_back(file);
202+
}
203+
204+
return files;
205+
}
206+
174207
void process_file(osmium::io::File const &file, osmdata_t &osmdata,
175208
progress_display_t &progress, bool append)
176209
{

src/input.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ type_id_version check_input(type_id_version const &last, type_id_version curr);
3535
type_id_version check_input(type_id_version const &last,
3636
osmium::OSMObject const &object);
3737

38+
/**
39+
* Prepare input file(s). Does format checks as far as this is possible
40+
* without actually opening the files.
41+
*/
42+
std::vector<osmium::io::File>
43+
prepare_input_files(std::vector<std::string> const &input_files,
44+
std::string const &input_format, bool append);
45+
3846
/**
3947
* Process the specified OSM files (stage 1a).
4048
*/

src/osm2pgsql.cpp

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,41 +52,6 @@ static std::shared_ptr<middle_t> create_middle(options_t const &options)
5252
return std::make_shared<middle_ram_t>(&options);
5353
}
5454

55-
/**
56-
* Prepare input file(s). Does format checks as far as this is possible
57-
* without actually opening the files.
58-
*/
59-
static std::vector<osmium::io::File>
60-
prepare_input_files(options_t const &options)
61-
{
62-
std::vector<osmium::io::File> files;
63-
64-
for (auto const &filename : options.input_files) {
65-
osmium::io::File file{filename, options.input_format};
66-
67-
if (file.format() == osmium::io::file_format::unknown) {
68-
if (options.input_format.empty()) {
69-
throw std::runtime_error{
70-
"Cannot detect file format for '{}'. Try using -r."_format(
71-
filename)};
72-
}
73-
throw std::runtime_error{
74-
"Unknown file format '{}'."_format(options.input_format)};
75-
}
76-
77-
if (!options.append && file.has_multiple_object_versions()) {
78-
throw std::runtime_error{
79-
"Reading an OSM change file only works in append mode."};
80-
}
81-
82-
log_debug("Reading file: {}", filename);
83-
84-
files.emplace_back(file);
85-
}
86-
87-
return files;
88-
}
89-
9055
int main(int argc, char *argv[])
9156
{
9257
try {
@@ -99,7 +64,8 @@ int main(int argc, char *argv[])
9964

10065
check_db(options);
10166

102-
auto const files = prepare_input_files(options);
67+
auto const files = prepare_input_files(
68+
options.input_files, options.input_format, options.append);
10369

10470
auto middle = create_middle(options);
10571
middle->start();

0 commit comments

Comments
 (0)