From cfe4cb8ebe50191a47f114af096b26c0295bf42f Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Sun, 15 Jul 2012 15:45:28 +0200 Subject: [PATCH] Changed the way OSM input/output is done. Before including you now need to define one or more of the following macros: #define OSMIUM_WITH_PBF_INPUT #define OSMIUM_WITH_XML_INPUT #define OSMIUM_WITH_PBF_OUTPUT #define OSMIUM_WITH_XML_OUTPUT which enable PBF and XML input and output, respectively. If you don't want any file input/output you don't need to include at all. Instead of writing infile.read(handler) you now write Osmium::Input::read(infile, handler) Instead of writing outfile.create_output_file() you now write Osmium::Output::open(outfile) The OSMIUM_WITH_OUTPUT_OSM_XML macros is gone. Sorry for the changes needed in user code, but this makes the library easier and more straightforward to use. You can now decide whether you need XML/PBF support for reading/writing. What you don't need is not included, so it compiles faster and you don't have to link with libraries you don't need. --- Doxyfile | 3 +- examples/Makefile | 34 ++++++------ examples/nodedensity.cpp | 5 +- examples/osmium_convert.cpp | 8 ++- examples/osmium_debug.cpp | 5 +- examples/osmium_find_bbox.cpp | 5 +- examples/osmium_progress.cpp | 5 +- examples/osmium_range_from_history.cpp | 9 +++- examples/osmium_sizeof.cpp | 11 ++-- examples/osmium_stats.cpp | 5 +- examples/osmium_store_and_debug.cpp | 7 ++- examples/osmium_time.cpp | 5 +- examples/osmium_toogr.cpp | 5 +- examples/osmium_toogr2.cpp | 8 +-- examples/osmium_toshape.cpp | 5 +- include/osmium.hpp | 73 +++++++++++++++++++++++++- include/osmium/input.hpp | 7 +-- include/osmium/input/pbf.hpp | 2 +- include/osmium/input/xml.hpp | 2 +- include/osmium/osmfile.hpp | 18 ++----- include/osmium/osmfile_impl.hpp | 56 -------------------- include/osmium/output.hpp | 7 +-- include/osmium/output/pbf.hpp | 2 +- include/osmium/output/xml.hpp | 2 +- osmjs/Makefile | 10 ++-- osmjs/osmjs.cpp | 12 +++-- 26 files changed, 173 insertions(+), 138 deletions(-) delete mode 100644 include/osmium/osmfile_impl.hpp diff --git a/Doxyfile b/Doxyfile index cab5ad7..87739f7 100644 --- a/Doxyfile +++ b/Doxyfile @@ -1244,7 +1244,8 @@ INCLUDE_FILE_PATTERNS = # undefined via #undef or recursively expanded use the := operator # instead of the = operator. -PREDEFINED = OSMIUM_WITH_GEOS OSMIUM_WITH_SHPLIB OSMIUM_WITH_OUTPUT_OSM_XML +PREDEFINED = OSMIUM_WITH_GEOS OSMIUM_WITH_SHPLIB OSMIUM_WITH_PBF_INPUT OSMIUM_WITH_PBF_OUTPUT OSMIUM_WITH_XML_INPUT OSMIUM_WITH_XML_OUTPUT + # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. diff --git a/examples/Makefile b/examples/Makefile index 0a77496..c2ea8a7 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -17,20 +17,20 @@ CXXFLAGS += -Wall -Wextra -Wredundant-decls -Wdisabled-optimization -pedantic -W #CXXFLAGS += -DOSMIUM_WITH_MULTIPOLYGON_PROFILING CXXFLAGS_GEOS = -DOSMIUM_WITH_GEOS $(shell geos-config --cflags) -CXXFLAGS_LIBXML2 = -DOSMIUM_WITH_OUTPUT_OSM_XML $(shell xml2-config --cflags) +CXXFLAGS_LIBXML2 = $(shell xml2-config --cflags) CXXFLAGS_OGR = $(shell gdal-config --cflags) CXXFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 CXXFLAGS += -I../include -LDFLAGS = -L/usr/local/lib -lexpat -lpthread +LDFLAGS = -L/usr/local/lib -lexpat LIB_GD = -lgd -lz -lm LIB_SQLITE = -lsqlite3 LIB_GEOS = $(shell geos-config --libs) LIB_SHAPE = -lshp $(LIB_GEOS) -LIB_PROTOBUF = -lz -lprotobuf-lite -losmpbf +LIB_PBF = -lz -lpthread -lprotobuf-lite -losmpbf LIB_XML2 = $(shell xml2-config --libs) LIB_OGR = $(shell gdal-config --libs) @@ -54,44 +54,44 @@ PROGRAMS = \ all: $(PROGRAMS) osmium_convert: osmium_convert.cpp - $(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_XML2) + $(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_XML2) osmium_store_and_debug: osmium_store_and_debug.cpp - $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) + $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF) osmium_debug: osmium_debug.cpp - $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) -# $(CXX) $(CXXFLAGS) -DOSMIUM_DEBUG_WITH_ENDTIME -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) + $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF) +# $(CXX) $(CXXFLAGS) -DOSMIUM_DEBUG_WITH_ENDTIME -o $@ $< $(LDFLAGS) $(LIB_PBF) osmium_find_bbox: osmium_find_bbox.cpp - $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) + $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF) osmium_progress: osmium_progress.cpp - $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) + $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF) osmium_range_from_history: osmium_range_from_history.cpp - $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) + $(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_XML2) osmium_sizeof: osmium_sizeof.cpp - $(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_XML2) + $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) osmium_stats: osmium_stats.cpp - $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_SQLITE) + $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_SQLITE) osmium_time: osmium_time.cpp - $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) + $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF) osmium_toogr: osmium_toogr.cpp - $(CXX) $(CXXFLAGS) $(CXXFLAGS_OGR) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_OGR) + $(CXX) $(CXXFLAGS) $(CXXFLAGS_OGR) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_OGR) osmium_toogr2: osmium_toogr2.cpp - $(CXX) $(CXXFLAGS) $(CXXFLAGS_OGR) $(CXXFLAGS_GEOS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_OGR) $(LIB_GEOS) + $(CXX) $(CXXFLAGS) $(CXXFLAGS_OGR) $(CXXFLAGS_GEOS) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_OGR) $(LIB_GEOS) osmium_toshape: osmium_toshape.cpp - $(CXX) $(CXXFLAGS) $(CXXFLAGS_GEOS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_SHAPE) + $(CXX) $(CXXFLAGS) $(CXXFLAGS_GEOS) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_SHAPE) nodedensity: nodedensity.cpp - $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_GD) + $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_GD) clean: rm -f *.o core $(PROGRAMS) diff --git a/examples/nodedensity.cpp b/examples/nodedensity.cpp index 1cfbac8..afaa8e8 100644 --- a/examples/nodedensity.cpp +++ b/examples/nodedensity.cpp @@ -24,6 +24,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see #include #include +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT + #include /* ================================================== */ @@ -119,6 +122,6 @@ int main(int argc, char *argv[]) { Osmium::OSMFile infile(argv[1]); NodeDensityHandler handler(size, min, max); - infile.read(handler); + Osmium::Input::read(infile, handler); } diff --git a/examples/osmium_convert.cpp b/examples/osmium_convert.cpp index a91fb5e..91a861a 100644 --- a/examples/osmium_convert.cpp +++ b/examples/osmium_convert.cpp @@ -28,6 +28,10 @@ You should have received a copy of the Licenses along with Osmium. If not, see #include #include +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT +#define OSMIUM_WITH_PBF_OUTPUT +#define OSMIUM_WITH_XML_OUTPUT #include #include @@ -50,7 +54,7 @@ class ConvertHandler : public Osmium::Handler::Base { } void init(Osmium::OSM::Meta& meta) { - output = m_outfile.create_output_file(); + output = Osmium::Output::open(m_outfile); output->debug_level(m_debug_level); output->init(meta); m_progress_handler.init(meta); @@ -181,6 +185,6 @@ int main(int argc, char *argv[]) { } ConvertHandler handler(outfile, debug ? 1 : 0); - infile.read(handler); + Osmium::Input::read(infile, handler); } diff --git a/examples/osmium_debug.cpp b/examples/osmium_debug.cpp index bac03db..da31ca3 100644 --- a/examples/osmium_debug.cpp +++ b/examples/osmium_debug.cpp @@ -28,6 +28,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see */ +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT + #include #include @@ -50,6 +53,6 @@ int main(int argc, char *argv[]) { #else Osmium::Handler::Debug handler; #endif // OSMIUM_DEBUG_WITH_ENDTIME - infile.read(handler); + Osmium::Input::read(infile, handler); } diff --git a/examples/osmium_find_bbox.cpp b/examples/osmium_find_bbox.cpp index ff33e1b..69261e6 100644 --- a/examples/osmium_find_bbox.cpp +++ b/examples/osmium_find_bbox.cpp @@ -27,6 +27,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see #include +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT + #include #include @@ -40,7 +43,7 @@ int main(int argc, char *argv[]) { Osmium::OSMFile infile(argv[1]); Osmium::Handler::FindBbox handler; - infile.read(handler); + Osmium::Input::read(infile, handler); Osmium::OSM::Bounds b = handler.bounds(); std::cout << "minlon=" << b.bl().lon() diff --git a/examples/osmium_progress.cpp b/examples/osmium_progress.cpp index 6c48d2e..9ad6d87 100644 --- a/examples/osmium_progress.cpp +++ b/examples/osmium_progress.cpp @@ -27,6 +27,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see #include +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT + #include #include @@ -40,6 +43,6 @@ int main(int argc, char *argv[]) { Osmium::OSMFile infile(argv[1]); Osmium::Handler::Progress handler; - infile.read(handler); + Osmium::Input::read(infile, handler); } diff --git a/examples/osmium_range_from_history.cpp b/examples/osmium_range_from_history.cpp index 5fce509..2278b87 100644 --- a/examples/osmium_range_from_history.cpp +++ b/examples/osmium_range_from_history.cpp @@ -25,6 +25,11 @@ You should have received a copy of the Licenses along with Osmium. If not, see */ +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT +#define OSMIUM_WITH_PBF_OUTPUT +#define OSMIUM_WITH_XML_OUTPUT + #include #include #include @@ -38,8 +43,8 @@ int main(int argc, char *argv[]) { Osmium::OSMFile infile(argv[1]); Osmium::OSMFile outfile(argv[2]); - Osmium::Handler::RangeFromHistory range_handler(outfile.create_output_file(), time(0), time(0)); + Osmium::Handler::RangeFromHistory range_handler(Osmium::Output::open(outfile), time(0), time(0)); Osmium::Handler::EndTime > handler(&range_handler); - infile.read(handler); + Osmium::Input::read(infile, handler); } diff --git a/examples/osmium_sizeof.cpp b/examples/osmium_sizeof.cpp index b7c6297..ea9c67d 100644 --- a/examples/osmium_sizeof.cpp +++ b/examples/osmium_sizeof.cpp @@ -27,9 +27,13 @@ You should have received a copy of the Licenses along with Osmium. If not, see */ #include +#include -#include -#include +#include +#include +#include +#include +#include int main() { std::cout << "sizeof(Osmium::OSM::Object)=" << sizeof(Osmium::OSM::Object) << "\n"; @@ -52,8 +56,5 @@ int main() { std::cout << "sizeof(OSMPBF::Relation)=" << sizeof(OSMPBF::Relation) << "\n"; std::cout << "sizeof(OSMPBF::DenseNodes)=" << sizeof(OSMPBF::DenseNodes) << "\n"; std::cout << "sizeof(OSMPBF::StringTable)=" << sizeof(OSMPBF::StringTable) << "\n"; - - std::cout << "sizeof(Osmium::Output::PBF)=" << sizeof(Osmium::Output::PBF) << "\n"; - std::cout << "sizeof(Osmium::Output::XML)=" << sizeof(Osmium::Output::XML) << "\n"; } diff --git a/examples/osmium_stats.cpp b/examples/osmium_stats.cpp index 4e4beb6..1276078 100644 --- a/examples/osmium_stats.cpp +++ b/examples/osmium_stats.cpp @@ -27,6 +27,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see #include +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT + #include #include @@ -40,6 +43,6 @@ int main(int argc, char *argv[]) { Osmium::OSMFile infile(argv[1]); Osmium::Handler::Statistics handler; - infile.read(handler); + Osmium::Input::read(infile, handler); } diff --git a/examples/osmium_store_and_debug.cpp b/examples/osmium_store_and_debug.cpp index 2999344..3bdf72b 100644 --- a/examples/osmium_store_and_debug.cpp +++ b/examples/osmium_store_and_debug.cpp @@ -26,6 +26,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see */ +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT + #include #include #include @@ -40,11 +43,11 @@ int main(int argc, char *argv[]) { Osmium::OSMFile infile2(argv[2]); Osmium::Storage::ObjectStore os; - infile1.read(os); + Osmium::Input::read(infile1, os); Osmium::Handler::Debug debug; Osmium::OSM::Meta meta; Osmium::Storage::ObjectStore::ApplyHandler ah(os, &debug, meta); - infile2.read(ah); + Osmium::Input::read(infile2, ah); } diff --git a/examples/osmium_time.cpp b/examples/osmium_time.cpp index 10c2ee6..b09b7ad 100644 --- a/examples/osmium_time.cpp +++ b/examples/osmium_time.cpp @@ -29,6 +29,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see #include #include +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT + #include class MyTimerHandler : public Osmium::Handler::Base { @@ -71,7 +74,7 @@ int main(int argc, char *argv[]) { Osmium::OSMFile infile(argv[1]); MyTimerHandler handler; - infile.read(handler); + Osmium::Input::read(infile, handler); struct tms tms; times(&tms); diff --git a/examples/osmium_toogr.cpp b/examples/osmium_toogr.cpp index e9bcf22..04b10cb 100644 --- a/examples/osmium_toogr.cpp +++ b/examples/osmium_toogr.cpp @@ -30,6 +30,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see #include +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT + #include #include #include @@ -201,6 +204,6 @@ int main(int argc, char *argv[]) { Osmium::OSMFile infile(argv[1]); MyOGRHandler handler; - infile.read(handler); + Osmium::Input::read(infile, handler); } diff --git a/examples/osmium_toogr2.cpp b/examples/osmium_toogr2.cpp index eff8c3d..e39b490 100644 --- a/examples/osmium_toogr2.cpp +++ b/examples/osmium_toogr2.cpp @@ -32,6 +32,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see #include +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT + #include #include #include @@ -193,12 +196,11 @@ int main(int argc, char *argv[]) { // first pass MyOGRHandlerPass1 handler_pass1(&handler_multipolygon); - infile.read(handler_pass1); + Osmium::Input::read(infile, handler_pass1); // second pass MyOGRHandlerPass2 handler_pass2(&handler_multipolygon); hpass2 = &handler_pass2; - - infile.read(handler_pass2); + Osmium::Input::read(infile, handler_pass2); } diff --git a/examples/osmium_toshape.cpp b/examples/osmium_toshape.cpp index 52514f8..b6786fa 100644 --- a/examples/osmium_toshape.cpp +++ b/examples/osmium_toshape.cpp @@ -27,6 +27,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see #include +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT + #include #include #include @@ -116,6 +119,6 @@ int main(int argc, char *argv[]) { Osmium::OSMFile infile(argv[1]); MyShapeHandler handler; - infile.read(handler); + Osmium::Input::read(infile, handler); } diff --git a/include/osmium.hpp b/include/osmium.hpp index e3f3a85..114cb94 100644 --- a/include/osmium.hpp +++ b/include/osmium.hpp @@ -22,6 +22,22 @@ You should have received a copy of the Licenses along with Osmium. If not, see */ +#ifdef OSMIUM_WITH_PBF_INPUT +# include +#endif + +#ifdef OSMIUM_WITH_XML_INPUT +# include +#endif + +#ifdef OSMIUM_WITH_PBF_OUTPUT +# include +#endif + +#ifdef OSMIUM_WITH_XML_OUTPUT +# include +#endif + /** * @mainpage * @@ -40,8 +56,61 @@ You should have received a copy of the Licenses along with Osmium. If not, see * @brief All %Osmium code is in this namespace. */ namespace Osmium { -} // namespace Osmium -#include +#if defined(OSMIUM_WITH_PBF_INPUT) || defined(OSMIUM_WITH_XML_INPUT) + namespace Input { + + template + inline void read(const Osmium::OSMFile& file, T& handler) { + Osmium::Input::Base* input = NULL; + + if (file.get_encoding()->is_pbf()) { +#ifdef OSMIUM_WITH_PBF_INPUT + input = static_cast*>(new Osmium::Input::PBF(file, handler)); +#else + throw Osmium::OSMFile::FileEncodingNotSupported(); +#endif // OSMIUM_WITH_PBF_INPUT + } else { +#ifdef OSMIUM_WITH_XML_INPUT + input = static_cast*>(new Osmium::Input::XML(file, handler)); +#else + throw Osmium::OSMFile::FileEncodingNotSupported(); +#endif // OSMIUM_WITH_XML_INPUT + } + + input->parse(); + delete input; + } + + } // namespace Input +#endif + +#if defined(OSMIUM_WITH_PBF_OUTPUT) || defined(OSMIUM_WITH_XML_OUTPUT) + namespace Output { + + inline Osmium::Output::Base* open(const Osmium::OSMFile& file) { + Osmium::Output::Base *output = NULL; + + if (file.get_encoding()->is_pbf()) { +#ifdef OSMIUM_WITH_PBF_OUTPUT + output = new Osmium::Output::PBF(file); +#else + throw Osmium::OSMFile::FileEncodingNotSupported(); +#endif // OSMIUM_WITH_PBF_OUTPUT + } else { +#ifdef OSMIUM_WITH_XML_OUTPUT + output = new Osmium::Output::XML(file); +#else + throw Osmium::OSMFile::FileEncodingNotSupported(); +#endif // OSMIUM_WITH_XML_OUTPUT + } + + return output; + } + + } // namespace Output +#endif + +} // namespace Osmium #endif // OSMIUM_OSMIUM_HPP diff --git a/include/osmium/input.hpp b/include/osmium/input.hpp index 79590bc..dc15230 100644 --- a/include/osmium/input.hpp +++ b/include/osmium/input.hpp @@ -32,8 +32,8 @@ using std::tr1::const_pointer_cast; using std::tr1::dynamic_pointer_cast; using boost::make_shared; -#include #include +#include namespace Osmium { @@ -97,7 +97,7 @@ namespace Osmium { protected: - Base(Osmium::OSMFile& file, + Base(const Osmium::OSMFile& file, THandler& handler) : m_last_object_type(UNKNOWN), m_file(file), @@ -246,7 +246,4 @@ namespace Osmium { } // namespace Osmium -#include -#include - #endif // OSMIUM_INPUT_HPP diff --git a/include/osmium/input/pbf.hpp b/include/osmium/input/pbf.hpp index 9421a6c..0104109 100644 --- a/include/osmium/input/pbf.hpp +++ b/include/osmium/input/pbf.hpp @@ -63,7 +63,7 @@ namespace Osmium { * @param file OSMFile instance. * @param handler Instance of THandler. */ - PBF(OSMFile& file, THandler& handler) : Base(file, handler) { + PBF(const OSMFile& file, THandler& handler) : Base(file, handler) { GOOGLE_PROTOBUF_VERIFY_VERSION; } diff --git a/include/osmium/input/xml.hpp b/include/osmium/input/xml.hpp index 97440f6..ee4aa2f 100644 --- a/include/osmium/input/xml.hpp +++ b/include/osmium/input/xml.hpp @@ -57,7 +57,7 @@ namespace Osmium { * @param file OSMFile instance. * @param handler Instance of THandler. */ - XML(Osmium::OSMFile& file, THandler& handler) : Base(file, handler), m_current_object(NULL), m_in_delete_section(false) { + XML(const Osmium::OSMFile& file, THandler& handler) : Base(file, handler), m_current_object(NULL), m_in_delete_section(false) { } void parse() { diff --git a/include/osmium/osmfile.hpp b/include/osmium/osmfile.hpp index 6813893..b11d4cc 100644 --- a/include/osmium/osmfile.hpp +++ b/include/osmium/osmfile.hpp @@ -32,11 +32,6 @@ You should have received a copy of the Licenses along with Osmium. If not, see namespace Osmium { - // forward declaration - namespace Output { - class Base; - } - /** * This class describes an %OSM file in one of several different formats. * It can be used as factory class for generating input and output OSM files. @@ -156,6 +151,9 @@ namespace Osmium { struct FileTypeHistoryExpected : public FileTypeError { }; + class FileEncodingNotSupported { + }; + /** * Instances of this class describe different file types. * @@ -652,16 +650,6 @@ namespace Osmium { m_fd = m_encoding->compress() == "" ? open_output_file() : execute(m_encoding->compress(), 1); } - /** - * Read OSM file and call methods on handler object. - */ - template void read(T& handler); - - /** - * Create output file from OSMFile. - */ - Osmium::Output::Base* create_output_file(); - }; } // namespace Osmium diff --git a/include/osmium/osmfile_impl.hpp b/include/osmium/osmfile_impl.hpp deleted file mode 100644 index a33093f..0000000 --- a/include/osmium/osmfile_impl.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef OSMIUM_OSMFILE_IMPL_HPP -#define OSMIUM_OSMFILE_IMPL_HPP - -/* - -Copyright 2012 Jochen Topf and others (see README). - -This file is part of Osmium (https://github.com/joto/osmium). - -Osmium is free software: you can redistribute it and/or modify it under the -terms of the GNU Lesser General Public License or (at your option) the GNU -General Public License as published by the Free Software Foundation, either -version 3 of the Licenses, or (at your option) any later version. - -Osmium is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -PARTICULAR PURPOSE. See the GNU Lesser General Public License and the GNU -General Public License for more details. - -You should have received a copy of the Licenses along with Osmium. If not, see -. - -*/ - -#include -#include -#include - -namespace Osmium { - - template - void OSMFile::read(T& handler) { - Osmium::Input::Base* input = m_encoding->is_pbf() - ? static_cast*>(new Osmium::Input::PBF(*this, handler)) - : static_cast*>(new Osmium::Input::XML(*this, handler)); - input->parse(); - delete input; - } - - Osmium::Output::Base *OSMFile::create_output_file() { - Osmium::Output::Base *output = NULL; - - if (m_encoding->is_pbf()) { - output = new Osmium::Output::PBF(*this); - } else { -#ifdef OSMIUM_WITH_OUTPUT_OSM_XML - output = new Osmium::Output::XML(*this); -#endif - } - - return output; - } - -} // namespace Osmium - -#endif // OSMIUM_OSMFILE_IMPL_HPP diff --git a/include/osmium/output.hpp b/include/osmium/output.hpp index 40d485e..471a19f 100644 --- a/include/osmium/output.hpp +++ b/include/osmium/output.hpp @@ -44,7 +44,7 @@ namespace Osmium { public: - Base(Osmium::OSMFile& file) : + Base(const Osmium::OSMFile& file) : Osmium::Handler::Base(), m_file(file) { m_file.open_for_output(); @@ -65,9 +65,4 @@ namespace Osmium { } // namespace Osmium -#include -#ifdef OSMIUM_WITH_OUTPUT_OSM_XML -# include -#endif - #endif // OSMIUM_OUTPUT_HPP diff --git a/include/osmium/output/pbf.hpp b/include/osmium/output/pbf.hpp index f1ec667..043d0df 100644 --- a/include/osmium/output/pbf.hpp +++ b/include/osmium/output/pbf.hpp @@ -743,7 +743,7 @@ namespace Osmium { /** * Create PBF output object from OSMFile. */ - PBF(Osmium::OSMFile& file) : Base(file), + PBF(const Osmium::OSMFile& file) : Base(file), pbf_blob(), pbf_blob_header(), pbf_header_block(), diff --git a/include/osmium/output/xml.hpp b/include/osmium/output/xml.hpp index 34f89a1..b0149b4 100644 --- a/include/osmium/output/xml.hpp +++ b/include/osmium/output/xml.hpp @@ -47,7 +47,7 @@ namespace Osmium { public: - XML(Osmium::OSMFile& file) : Base(file), m_last_op('\0') { + XML(const Osmium::OSMFile& file) : Base(file), m_last_op('\0') { xml_writer = xmlNewTextWriter(xmlOutputBufferCreateFd(this->get_fd(), NULL)); } diff --git a/osmjs/Makefile b/osmjs/Makefile index ea12f07..35fc542 100644 --- a/osmjs/Makefile +++ b/osmjs/Makefile @@ -25,19 +25,19 @@ CXXFLAGS += -DOSMIUM_WITH_SHPLIB CXXFLAGS += -I../include -LDFLAGS = -L/usr/local/lib -lexpat -lpthread +LDFLAGS = -L/usr/local/lib -lexpat LDFLAGS += $(shell geos-config --libs) -LIB_V8 = -lv8 -licuuc -LIB_SHAPE = -lshp -LIB_PROTOBUF = -lz -lprotobuf-lite -losmpbf +LIB_V8 = -lv8 -licuuc +LIB_SHAPE = -lshp +LIB_PBF = -lz -lpthread -lprotobuf-lite -losmpbf .PHONY: all clean install all: osmjs osmjs: osmjs.cpp - $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_V8) $(LIB_SHAPE) + $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_V8) $(LIB_SHAPE) install: install -m 755 -g root -o root -d $(DESTDIR)/usr/bin diff --git a/osmjs/osmjs.cpp b/osmjs/osmjs.cpp index da1e13d..b9ea523 100644 --- a/osmjs/osmjs.cpp +++ b/osmjs/osmjs.cpp @@ -23,8 +23,10 @@ You should have received a copy of the Licenses along with Osmium. If not, see #include #include -#include -#include +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT +#include + #include #include #include @@ -416,13 +418,13 @@ int main(int argc, char *argv[]) { handler_multipolygon = new Osmium::Handler::Multipolygon(attempt_repair, cbmp); } DualPass1 handler1(handler_cfw, handler_multipolygon, handler_javascript); - infile.read(handler1); + Osmium::Input::read(infile, handler1); DualPass2 handler2(handler_cfw, handler_multipolygon, handler_javascript); - infile.read(handler2); + Osmium::Input::read(infile, handler2); delete handler_multipolygon; } else { SinglePass handler(handler_cfw, handler_javascript); - infile.read(handler); + Osmium::Input::read(infile, handler); } delete handler_javascript;