2323#-----------------------------------------------------------------------------
2424*/
2525
26- #include " db-copy.hpp"
2726#include " format.hpp"
2827#include " middle-pgsql.hpp"
2928#include " middle-ram.hpp"
3029#include " options.hpp"
3130#include " osmdata.hpp"
32- #include " osmtypes.hpp"
3331#include " output.hpp"
3432#include " parse-osmium.hpp"
3533#include " reprojection.hpp"
3634#include " util.hpp"
3735#include " version.hpp"
3836
39- #include < cstdio>
40- #include < cstdlib>
41- #include < stdexcept>
42- #include < string>
43- #include < vector>
37+ #include < ctime>
38+ #include < exception>
39+ #include < memory>
4440
45- #include < libpq-fe.h>
41+ static std::shared_ptr<middle_t > create_middle (options_t const &options)
42+ {
43+ if (options.slim ) {
44+ return std::make_shared<middle_pgsql_t >(&options);
45+ }
46+
47+ return std::make_shared<middle_ram_t >(&options);
48+ }
4649
4750int main (int argc, char *argv[])
4851{
4952 fmt::print (stderr, " osm2pgsql version {}\n\n " , get_osm2pgsql_version ());
5053
5154 try {
52- // parse the args into the different options members
53- options_t const options = options_t (argc, argv);
55+ options_t const options{argc, argv};
5456 if (options.long_usage_bool ) {
5557 return 0 ;
5658 }
5759
58- // setup the middle and backend (output)
59- std::shared_ptr<middle_t > middle;
60-
61- if (options.slim ) {
62- // middle gets its own copy-in thread
63- middle = std::shared_ptr<middle_t >(new middle_pgsql_t {&options});
64- } else {
65- middle = std::shared_ptr<middle_t >(new middle_ram_t {&options});
66- }
67-
60+ auto middle = create_middle (options);
6861 middle->start ();
6962
7063 auto const outputs =
7164 output_t::create_outputs (middle->get_query_instance (), options);
72- // let osmdata orchestrate between the middle and the outs
65+
7366 osmdata_t osmdata{middle, outputs};
7467
7568 fmt::print (stderr, " Using projection SRS {} ({})\n " ,
7669 options.projection ->target_srs (),
7770 options.projection ->target_desc ());
7871
79- // start it up
8072 util::timer_t timer_overall;
8173 osmdata.start ();
8274
@@ -98,15 +90,15 @@ int main(int argc, char *argv[])
9890
9991 stats.print_summary ();
10092
101- // Process pending ways, relations, cluster, and create indexes
93+ // Process pending ways and relations. Cluster database tables and
94+ // create indexes.
10295 osmdata.stop ();
10396
10497 fmt::print (stderr, " \n Osm2pgsql took {}s overall\n " ,
10598 timer_overall.stop ());
106-
107- return 0 ;
108- } catch (std::runtime_error const &e) {
99+ } catch (std::exception const &e) {
109100 fmt::print (stderr, " Osm2pgsql failed due to ERROR: {}\n " , e.what ());
110- exit (EXIT_FAILURE) ;
101+ return 1 ;
111102 }
103+ return 0 ;
112104}
0 commit comments