pull in latest osmcode/libosmium changes

This commit is contained in:
Dennis Luxen 2015-04-13 15:44:38 +02:00
commit 9cc68b26e2
69 changed files with 1906 additions and 1528 deletions

View File

@ -1,4 +1,2 @@
core
*.swp *.swp
build*
.ycm_extra_conf.pyc .ycm_extra_conf.pyc

View File

@ -6,6 +6,10 @@
# #
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
from os.path import realpath, dirname
basedir = dirname(realpath(__file__))
# some default flags # some default flags
# for more information install clang-3.2-doc package and # for more information install clang-3.2-doc package and
# check UsersManual.html # check UsersManual.html
@ -26,9 +30,9 @@ flags = [
'c++', 'c++',
# libosmium include dirs # libosmium include dirs
'-Iinclude', '-I%s/include' % basedir,
'-Itest/include', '-I%s/test/include' % basedir,
'-Itest/data-test/include', '-I%s/test/data-test/include' % basedir,
# include third party libraries # include third party libraries
'-I/usr/include/gdal', '-I/usr/include/gdal',

31
third_party/libosmium/CHANGELOG.md vendored Normal file
View File

@ -0,0 +1,31 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## [unreleased] -
## [2.1.0] - 2015-03-31
### Added
- When writing PBF files, sorting the PBF stringtables is now optional.
- More tests and documentation.
### Changed
- Some functions are now declared `noexcept`.
- XML parser fails now if the top-level element is not `osm` or `osmChange`.
### Fixed
- Race condition in PBF reader.
- Multipolygon collector was accessing non-existent NodeRef.
- Doxygen documentation wan't showing all classes/functions due to a bug in
Doxygen (up to version 1.8.8). This version contains a workaround to fix
this.
[unreleased]: https://github.com/osmcode/libosmium/compare/v2.1.0...HEAD
[2.1.0]: https://github.com/osmcode/libosmium/compare/v2.0.0...v2.1.0

View File

@ -9,6 +9,8 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR) cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# #
@ -23,9 +25,9 @@ set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;MinSizeRel;Dev"
project(libosmium) project(libosmium)
set(LIBOSMIUM_VERSION_MAJOR 0) set(LIBOSMIUM_VERSION_MAJOR 2)
set(LIBOSMIUM_VERSION_MINOR 0) set(LIBOSMIUM_VERSION_MINOR 1)
set(LIBOSMIUM_VERSION_PATCH 1) set(LIBOSMIUM_VERSION_PATCH 0)
set(LIBOSMIUM_VERSION set(LIBOSMIUM_VERSION
${LIBOSMIUM_VERSION_MAJOR}.${LIBOSMIUM_VERSION_MINOR}.${LIBOSMIUM_VERSION_PATCH}) ${LIBOSMIUM_VERSION_MAJOR}.${LIBOSMIUM_VERSION_MINOR}.${LIBOSMIUM_VERSION_PATCH})

View File

@ -66,11 +66,12 @@ build_script:
- mkdir build - mkdir build
- cd build - cd build
- echo %config% - echo %config%
- cmake .. -LA -G "Visual Studio 14 Win64" -DOsmium_DEBUG=TRUE -DCMAKE_BUILD_TYPE=%config% -DBOOST_ROOT=%LODEPSDIR%\boost -DBoost_PROGRAM_OPTIONS_LIBRARY=%LODEPSDIR%\boost\lib\libboost_program_options-vc140-mt-1_57.lib -DOSMPBF_LIBRARY=%LODEPSDIR%\osmpbf\lib\osmpbf.lib -DOSMPBF_INCLUDE_DIR=%LODEPSDIR%\osmpbf\include -DPROTOBUF_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf.lib -DPROTOBUF_LITE_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf-lite.lib -DPROTOBUF_INCLUDE_DIR=%LODEPSDIR%\protobuf\include -DZLIB_LIBRARY=%LODEPSDIR%\zlib\lib\zlibwapi.lib -DZLIB_INCLUDE_DIR=%LODEPSDIR%\zlib\include -DEXPAT_LIBRARY=%LODEPSDIR%\expat\lib\libexpat.lib -DEXPAT_INCLUDE_DIR=%LODEPSDIR%\expat\include -DBZIP2_LIBRARIES=%LIBBZIP2% -DBZIP2_INCLUDE_DIR=%LODEPSDIR%\bzip2\include -DGDAL_LIBRARY=%LODEPSDIR%\gdal\lib\gdal_i.lib -DGDAL_INCLUDE_DIR=%LODEPSDIR%\gdal\include -DGEOS_LIBRARY=%LODEPSDIR%\geos\lib\geos.lib -DGEOS_INCLUDE_DIR=%LODEPSDIR%\geos\include -DPROJ_LIBRARY=%LODEPSDIR%\proj\lib\proj.lib -DPROJ_INCLUDE_DIR=%LODEPSDIR%\proj\include -DSPARSEHASH_INCLUDE_DIR=%LODEPSDIR%\sparsehash\include -DGETOPT_LIBRARY=%LODEPSDIR%\wingetopt\lib\wingetopt.lib -DGETOPT_INCLUDE_DIR=%LODEPSDIR%\wingetopt\include - cmake .. -LA -G "Visual Studio 14 Win64" -DOsmium_DEBUG=TRUE -DCMAKE_BUILD_TYPE=%config% -DBUILD_BENCHMARKS=OFF -DBOOST_ROOT=%LODEPSDIR%\boost -DBoost_PROGRAM_OPTIONS_LIBRARY=%LODEPSDIR%\boost\lib\libboost_program_options-vc140-mt-1_57.lib -DOSMPBF_LIBRARY=%LODEPSDIR%\osmpbf\lib\osmpbf.lib -DOSMPBF_INCLUDE_DIR=%LODEPSDIR%\osmpbf\include -DPROTOBUF_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf.lib -DPROTOBUF_LITE_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf-lite.lib -DPROTOBUF_INCLUDE_DIR=%LODEPSDIR%\protobuf\include -DZLIB_LIBRARY=%LODEPSDIR%\zlib\lib\zlibwapi.lib -DZLIB_INCLUDE_DIR=%LODEPSDIR%\zlib\include -DEXPAT_LIBRARY=%LODEPSDIR%\expat\lib\libexpat.lib -DEXPAT_INCLUDE_DIR=%LODEPSDIR%\expat\include -DBZIP2_LIBRARIES=%LIBBZIP2% -DBZIP2_INCLUDE_DIR=%LODEPSDIR%\bzip2\include -DGDAL_LIBRARY=%LODEPSDIR%\gdal\lib\gdal_i.lib -DGDAL_INCLUDE_DIR=%LODEPSDIR%\gdal\include -DGEOS_LIBRARY=%LODEPSDIR%\geos\lib\geos.lib -DGEOS_INCLUDE_DIR=%LODEPSDIR%\geos\include -DPROJ_LIBRARY=%LODEPSDIR%\proj\lib\proj.lib -DPROJ_INCLUDE_DIR=%LODEPSDIR%\proj\include -DSPARSEHASH_INCLUDE_DIR=%LODEPSDIR%\sparsehash\include -DGETOPT_LIBRARY=%LODEPSDIR%\wingetopt\lib\wingetopt.lib -DGETOPT_INCLUDE_DIR=%LODEPSDIR%\wingetopt\include
- msbuild libosmium.sln /p:Configuration=%config% /toolsversion:14.0 /p:Platform=x64 /p:PlatformToolset=v140 - msbuild libosmium.sln /p:Configuration=%config% /toolsversion:14.0 /p:Platform=x64 /p:PlatformToolset=v140
#- cmake .. -LA -G "NMake Makefiles" -DOsmium_DEBUG=TRUE -DCMAKE_BUILD_TYPE=%config% -DBOOST_ROOT=%LODEPSDIR%\boost -DBoost_PROGRAM_OPTIONS_LIBRARY=%LODEPSDIR%\boost\lib\libboost_program_options-vc140-mt-1_57.lib -DOSMPBF_LIBRARY=%LODEPSDIR%\osmpbf\lib\osmpbf.lib -DOSMPBF_INCLUDE_DIR=%LODEPSDIR%\osmpbf\include -DPROTOBUF_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf.lib -DPROTOBUF_LITE_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf-lite.lib -DPROTOBUF_INCLUDE_DIR=%LODEPSDIR%\protobuf\include -DZLIB_LIBRARY=%LODEPSDIR%\zlib\lib\zlibwapi.lib -DZLIB_INCLUDE_DIR=%LODEPSDIR%\zlib\include -DEXPAT_LIBRARY=%LODEPSDIR%\expat\lib\libexpat.lib -DEXPAT_INCLUDE_DIR=%LODEPSDIR%\expat\include -DBZIP2_LIBRARIES=%LIBBZIP2% -DBZIP2_INCLUDE_DIR=%LODEPSDIR%\bzip2\include -DGDAL_LIBRARY=%LODEPSDIR%\gdal\lib\gdal_i.lib -DGDAL_INCLUDE_DIR=%LODEPSDIR%\gdal\include -DGEOS_LIBRARY=%LODEPSDIR%\geos\lib\geos.lib -DGEOS_INCLUDE_DIR=%LODEPSDIR%\geos\include -DPROJ_LIBRARY=%LODEPSDIR%\proj\lib\proj.lib -DPROJ_INCLUDE_DIR=%LODEPSDIR%\proj\include -DSPARSEHASH_INCLUDE_DIR=%LODEPSDIR%\sparsehash\include -DGETOPT_LIBRARY=%LODEPSDIR%\wingetopt\lib\wingetopt.lib -DGETOPT_INCLUDE_DIR=%LODEPSDIR%\wingetopt\include #- cmake .. -LA -G "NMake Makefiles" -DOsmium_DEBUG=TRUE -DCMAKE_BUILD_TYPE=%config% -DBOOST_ROOT=%LODEPSDIR%\boost -DBoost_PROGRAM_OPTIONS_LIBRARY=%LODEPSDIR%\boost\lib\libboost_program_options-vc140-mt-1_57.lib -DOSMPBF_LIBRARY=%LODEPSDIR%\osmpbf\lib\osmpbf.lib -DOSMPBF_INCLUDE_DIR=%LODEPSDIR%\osmpbf\include -DPROTOBUF_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf.lib -DPROTOBUF_LITE_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf-lite.lib -DPROTOBUF_INCLUDE_DIR=%LODEPSDIR%\protobuf\include -DZLIB_LIBRARY=%LODEPSDIR%\zlib\lib\zlibwapi.lib -DZLIB_INCLUDE_DIR=%LODEPSDIR%\zlib\include -DEXPAT_LIBRARY=%LODEPSDIR%\expat\lib\libexpat.lib -DEXPAT_INCLUDE_DIR=%LODEPSDIR%\expat\include -DBZIP2_LIBRARIES=%LIBBZIP2% -DBZIP2_INCLUDE_DIR=%LODEPSDIR%\bzip2\include -DGDAL_LIBRARY=%LODEPSDIR%\gdal\lib\gdal_i.lib -DGDAL_INCLUDE_DIR=%LODEPSDIR%\gdal\include -DGEOS_LIBRARY=%LODEPSDIR%\geos\lib\geos.lib -DGEOS_INCLUDE_DIR=%LODEPSDIR%\geos\include -DPROJ_LIBRARY=%LODEPSDIR%\proj\lib\proj.lib -DPROJ_INCLUDE_DIR=%LODEPSDIR%\proj\include -DSPARSEHASH_INCLUDE_DIR=%LODEPSDIR%\sparsehash\include -DGETOPT_LIBRARY=%LODEPSDIR%\wingetopt\lib\wingetopt.lib -DGETOPT_INCLUDE_DIR=%LODEPSDIR%\wingetopt\include
#- nmake #- nmake
test_script: test_script:
- ctest --output-on-failure -C %config% # -LE fails_on_windows exempts tests we know will fail
- ctest --output-on-failure -C %config% -LE fails_on_windows

View File

@ -226,7 +226,6 @@ if(Osmium_USE_SPARSEHASH)
if(SPARSEHASH_INCLUDE_DIR) if(SPARSEHASH_INCLUDE_DIR)
# Find size of sparsetable::size_type. This does not work on older # Find size of sparsetable::size_type. This does not work on older
# CMake versions because they can do this check only in C, not in C++. # CMake versions because they can do this check only in C, not in C++.
# Until we find a better way, we'll live with that.
include(CheckTypeSize) include(CheckTypeSize)
set(CMAKE_REQUIRED_INCLUDES ${SPARSEHASH_INCLUDE_DIR}) set(CMAKE_REQUIRED_INCLUDES ${SPARSEHASH_INCLUDE_DIR})
set(CMAKE_EXTRA_INCLUDE_FILES "google/sparsetable") set(CMAKE_EXTRA_INCLUDE_FILES "google/sparsetable")
@ -234,14 +233,19 @@ if(Osmium_USE_SPARSEHASH)
set(CMAKE_EXTRA_INCLUDE_FILES) set(CMAKE_EXTRA_INCLUDE_FILES)
set(CMAKE_REQUIRED_INCLUDES) set(CMAKE_REQUIRED_INCLUDES)
# Falling back to checking size_t if google::sparsetable<int>::size_type
# could not be checked.
if(SPARSETABLE_SIZE_TYPE STREQUAL "")
check_type_size("void*" VOID_PTR_SIZE)
set(SPARSETABLE_SIZE_TYPE ${VOID_PTR_SIZE})
endif()
# Sparsetable::size_type must be at least 8 bytes (64bit), otherwise # Sparsetable::size_type must be at least 8 bytes (64bit), otherwise
# OSM object IDs will not fit. # OSM object IDs will not fit.
if(SPARSETABLE_SIZE_TYPE GREATER 7) if(SPARSETABLE_SIZE_TYPE GREATER 7)
set(SPARSEHASH_FOUND 1) set(SPARSEHASH_FOUND 1)
add_definitions(-DOSMIUM_WITH_SPARSEHASH=${SPARSEHASH_FOUND}) add_definitions(-DOSMIUM_WITH_SPARSEHASH=${SPARSEHASH_FOUND})
list(APPEND OSMIUM_INCLUDE_DIRS ${SPARSEHASH_INCLUDE_DIR}) list(APPEND OSMIUM_INCLUDE_DIRS ${SPARSEHASH_INCLUDE_DIR})
elseif(SPARSETABLE_SIZE_TYPE STREQUAL "")
message(WARNING "Osmium: Disabled Google SparseHash library because we can't detect whether we are on a 64bit system.")
else() else()
message(WARNING "Osmium: Disabled Google SparseHash library on 32bit system (size_type=${SPARSETABLE_SIZE_TYPE}).") message(WARNING "Osmium: Disabled Google SparseHash library on 32bit system (size_type=${SPARSETABLE_SIZE_TYPE}).")
endif() endif()

View File

@ -694,7 +694,7 @@ CITE_BIB_FILES =
# messages are off. # messages are off.
# The default value is: NO. # The default value is: NO.
QUIET = NO QUIET = YES
# The WARNINGS tag can be used to turn on/off the warning messages that are # The WARNINGS tag can be used to turn on/off the warning messages that are
# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES # generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES
@ -860,7 +860,7 @@ IMAGE_PATH =
# code is scanned, but not when the output code is generated. If lines are added # code is scanned, but not when the output code is generated. If lines are added
# or removed, the anchors will not be placed correctly. # or removed, the anchors will not be placed correctly.
INPUT_FILTER = INPUT_FILTER = "grep -v static_assert"
# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
# basis. Doxygen will compare the file name with each pattern and apply the # basis. Doxygen will compare the file name with each pattern and apply the
@ -876,7 +876,7 @@ FILTER_PATTERNS =
# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). # producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).
# The default value is: NO. # The default value is: NO.
FILTER_SOURCE_FILES = NO FILTER_SOURCE_FILES = YES
# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file # The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and # pattern. A pattern will override the setting for FILTER_PATTERN (if any) and
@ -1080,7 +1080,7 @@ HTML_STYLESHEET =
# see the documentation. # see the documentation.
# This tag requires that the tag GENERATE_HTML is set to YES. # This tag requires that the tag GENERATE_HTML is set to YES.
HTML_EXTRA_STYLESHEET = doc/osmium.css HTML_EXTRA_STYLESHEET = "@PROJECT_SOURCE_DIR@/doc/osmium.css"
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
# other source files which should be copied to the HTML output directory. Note # other source files which should be copied to the HTML output directory. Note

View File

@ -65,7 +65,7 @@ namespace osmium {
// Enables debug output to stderr // Enables debug output to stderr
bool debug; bool debug;
explicit AssemblerConfig(osmium::area::ProblemReporter* pr = nullptr, bool d=false) : explicit AssemblerConfig(osmium::area::ProblemReporter* pr = nullptr, bool d = false) :
problem_reporter(pr), problem_reporter(pr),
debug(d) { debug(d) {
} }
@ -74,7 +74,7 @@ namespace osmium {
* Enable or disable debug output to stderr. This is for Osmium * Enable or disable debug output to stderr. This is for Osmium
* developers only. * developers only.
*/ */
void enable_debug_output(bool d=true) { void enable_debug_output(bool d = true) {
debug = d; debug = d;
} }
@ -445,7 +445,7 @@ namespace osmium {
} }
bool add_to_existing_ring(osmium::area::detail::NodeRefSegment segment) { bool add_to_existing_ring(osmium::area::detail::NodeRefSegment segment) {
int n=0; int n = 0;
for (auto& ring : m_rings) { for (auto& ring : m_rings) {
if (debug()) { if (debug()) {
std::cerr << " check against ring " << n << " " << ring; std::cerr << " check against ring " << n << " " << ring;

View File

@ -99,7 +99,7 @@ namespace osmium {
* Enable or disable debug output to stderr. This is for Osmium * Enable or disable debug output to stderr. This is for Osmium
* developers only. * developers only.
*/ */
void enable_debug_output(bool debug=true) noexcept { void enable_debug_output(bool debug = true) noexcept {
m_debug = debug; m_debug = debug;
} }

View File

@ -142,7 +142,7 @@ namespace osmium {
* Overwritten from the base class. * Overwritten from the base class.
*/ */
void way_not_in_any_relation(const osmium::Way& way) { void way_not_in_any_relation(const osmium::Way& way) {
if (way.ends_have_same_location() && way.nodes().size() > 3) { if (way.nodes().size() > 3 && way.ends_have_same_location()) {
// way is closed and has enough nodes, build simple multipolygon // way is closed and has enough nodes, build simple multipolygon
try { try {
TAssembler assembler(m_assembler_config); TAssembler assembler(m_assembler_config);

View File

@ -100,7 +100,7 @@ namespace osmium {
* parent item (if any). * parent item (if any).
* *
*/ */
void add_padding(bool self=false) { void add_padding(bool self = false) {
auto padding = osmium::memory::align_bytes - (size() % osmium::memory::align_bytes); auto padding = osmium::memory::align_bytes - (size() % osmium::memory::align_bytes);
if (padding != osmium::memory::align_bytes) { if (padding != osmium::memory::align_bytes) {
std::fill_n(m_buffer.reserve_space(padding), padding, 0); std::fill_n(m_buffer.reserve_space(padding), padding, 0);
@ -171,12 +171,11 @@ namespace osmium {
template <class TItem> template <class TItem>
class ObjectBuilder : public Builder { class ObjectBuilder : public Builder {
static_assert(std::is_base_of<osmium::memory::Item, TItem>::value, static_assert(std::is_base_of<osmium::memory::Item, TItem>::value, "ObjectBuilder can only build objects derived from osmium::memory::Item");
"ObjectBuilder can only build objects derived from osmium::memory::Item");
public: public:
explicit ObjectBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : explicit ObjectBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) :
Builder(buffer, parent, sizeof(TItem)) { Builder(buffer, parent, sizeof(TItem)) {
new (&item()) TItem(); new (&item()) TItem();
} }

View File

@ -61,7 +61,7 @@ namespace osmium {
public: public:
explicit TagListBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : explicit TagListBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) :
ObjectBuilder<TagList>(buffer, parent) { ObjectBuilder<TagList>(buffer, parent) {
} }
@ -97,7 +97,7 @@ namespace osmium {
public: public:
explicit NodeRefListBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : explicit NodeRefListBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) :
ObjectBuilder<T>(buffer, parent) { ObjectBuilder<T>(buffer, parent) {
} }
@ -110,7 +110,7 @@ namespace osmium {
static_cast<Builder*>(this)->add_size(sizeof(osmium::NodeRef)); static_cast<Builder*>(this)->add_size(sizeof(osmium::NodeRef));
} }
void add_node_ref(const object_id_type ref, const osmium::Location location=Location()) { void add_node_ref(const object_id_type ref, const osmium::Location location = Location()) {
add_node_ref(NodeRef(ref, location)); add_node_ref(NodeRef(ref, location));
} }
@ -160,7 +160,7 @@ namespace osmium {
public: public:
explicit RelationMemberListBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : explicit RelationMemberListBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) :
ObjectBuilder<RelationMemberList>(buffer, parent) { ObjectBuilder<RelationMemberList>(buffer, parent) {
} }
@ -215,7 +215,7 @@ namespace osmium {
public: public:
explicit OSMObjectBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : explicit OSMObjectBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) :
ObjectBuilder<T>(buffer, parent) { ObjectBuilder<T>(buffer, parent) {
static_cast<Builder*>(this)->reserve_space_for<string_size_type>(); static_cast<Builder*>(this)->reserve_space_for<string_size_type>();
static_cast<Builder*>(this)->add_size(sizeof(string_size_type)); static_cast<Builder*>(this)->add_size(sizeof(string_size_type));
@ -237,7 +237,7 @@ namespace osmium {
public: public:
explicit WayBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : explicit WayBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) :
OSMObjectBuilder<osmium::Way>(buffer, parent) { OSMObjectBuilder<osmium::Way>(buffer, parent) {
} }
@ -254,7 +254,7 @@ namespace osmium {
public: public:
explicit AreaBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : explicit AreaBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) :
OSMObjectBuilder<osmium::Area>(buffer, parent) { OSMObjectBuilder<osmium::Area>(buffer, parent) {
} }

View File

@ -214,7 +214,7 @@ namespace osmium {
return m_impl.linestring_finish(num_points); return m_impl.linestring_finish(num_points);
} }
linestring_type create_linestring(const osmium::WayNodeList& wnl, use_nodes un=use_nodes::unique, direction dir=direction::forward) { linestring_type create_linestring(const osmium::WayNodeList& wnl, use_nodes un = use_nodes::unique, direction dir = direction::forward) {
linestring_start(); linestring_start();
size_t num_points = 0; size_t num_points = 0;

View File

@ -74,7 +74,7 @@ namespace osmium {
* Calculate length of way. * Calculate length of way.
*/ */
inline double distance(const osmium::WayNodeList& wnl) { inline double distance(const osmium::WayNodeList& wnl) {
double sum_length=0; double sum_length = 0;
for (auto it = wnl.begin(); it != wnl.end(); ++it) { for (auto it = wnl.begin(); it != wnl.end(); ++it) {
if (std::next(it) != wnl.end()) { if (std::next(it) != wnl.end()) {

View File

@ -161,7 +161,7 @@ namespace osmium {
typedef std::string multipolygon_type; typedef std::string multipolygon_type;
typedef std::string ring_type; typedef std::string ring_type;
explicit WKBFactoryImpl(wkb_type wtype=wkb_type::wkb, out_type otype=out_type::binary) : explicit WKBFactoryImpl(wkb_type wtype = wkb_type::wkb, out_type otype = out_type::binary) :
m_wkb_type(wtype), m_wkb_type(wtype),
m_out_type(otype) { m_out_type(otype) {
} }

View File

@ -136,7 +136,7 @@ namespace osmium {
public: public:
explicit Dump(std::ostream& out, bool with_size=true, const std::string& prefix="") : explicit Dump(std::ostream& out, bool with_size = true, const std::string& prefix = "") :
m_out(&out), m_out(&out),
m_with_size(with_size), m_with_size(with_size),
m_prefix(prefix) { m_prefix(prefix) {

View File

@ -63,11 +63,9 @@ namespace osmium {
template <class TStoragePosIDs, class TStorageNegIDs = dummy_type> template <class TStoragePosIDs, class TStorageNegIDs = dummy_type>
class NodeLocationsForWays : public osmium::handler::Handler { class NodeLocationsForWays : public osmium::handler::Handler {
static_assert(std::is_base_of<osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>, TStoragePosIDs>::value, static_assert(std::is_base_of<osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>, TStoragePosIDs>::value, "Index class must be derived from osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>");
"Index class must be derived from osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>");
static_assert(std::is_base_of<osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>, TStorageNegIDs>::value, static_assert(std::is_base_of<osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>, TStorageNegIDs>::value, "Index class must be derived from osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>");
"Index class must be derived from osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>");
public: public:

View File

@ -84,8 +84,7 @@ namespace osmium {
template <typename TId, typename TValue> template <typename TId, typename TValue>
class Map { class Map {
static_assert(std::is_integral<TId>::value && std::is_unsigned<TId>::value, static_assert(std::is_integral<TId>::value && std::is_unsigned<TId>::value, "TId template parameter for class Map must be unsigned integral type");
"TId template parameter for class Map must be unsigned integral type");
Map(const Map&) = delete; Map(const Map&) = delete;
Map& operator=(const Map&) = delete; Map& operator=(const Map&) = delete;

View File

@ -83,7 +83,7 @@ namespace osmium {
* The storage will grow by at least this size * The storage will grow by at least this size
* every time it runs out of space. * every time it runs out of space.
*/ */
explicit SparseMemTable(const TId grow_size=10000) : explicit SparseMemTable(const TId grow_size = 10000) :
m_grow_size(grow_size), m_grow_size(grow_size),
m_elements(grow_size) { m_elements(grow_size) {
} }
@ -123,7 +123,7 @@ namespace osmium {
void dump_as_list(const int fd) override final { void dump_as_list(const int fd) override final {
std::vector<std::pair<TId, TValue>> v; std::vector<std::pair<TId, TValue>> v;
int n=0; int n = 0;
for (const TValue value : m_elements) { for (const TValue value : m_elements) {
if (value != osmium::index::empty_value<TValue>()) { if (value != osmium::index::empty_value<TValue>()) {
v.emplace_back(n, value); v.emplace_back(n, value);

View File

@ -50,8 +50,7 @@ namespace osmium {
template <typename TId, typename TValue> template <typename TId, typename TValue>
class Multimap { class Multimap {
static_assert(std::is_integral<TId>::value && std::is_unsigned<TId>::value, static_assert(std::is_integral<TId>::value && std::is_unsigned<TId>::value, "TId template parameter for class Multimap must be unsigned integral type");
"TId template parameter for class Multimap must be unsigned integral type");
typedef typename std::pair<TId, TValue> element_type; typedef typename std::pair<TId, TValue> element_type;

View File

@ -82,7 +82,7 @@ namespace osmium {
namespace detail { namespace detail {
OSMIUM_NORETURN inline void throw_bzip2_error(BZFILE* bzfile, const char* msg, int bzlib_error=0) { OSMIUM_NORETURN inline void throw_bzip2_error(BZFILE* bzfile, const char* msg, int bzlib_error = 0) {
std::string error("bzip2 error: "); std::string error("bzip2 error: ");
error += msg; error += msg;
error += ": "; error += ": ";

View File

@ -84,8 +84,9 @@ namespace osmium {
class PBFInputFormat : public osmium::io::detail::InputFormat { class PBFInputFormat : public osmium::io::detail::InputFormat {
bool m_use_thread_pool; bool m_use_thread_pool;
bool m_eof { false };
queue_type m_queue; queue_type m_queue;
std::atomic<bool> m_done; std::atomic<bool> m_quit_input_thread;
std::thread m_reader; std::thread m_reader;
osmium::thread::Queue<std::string>& m_input_queue; osmium::thread::Queue<std::string>& m_input_queue;
std::string m_input_buffer; std::string m_input_buffer;
@ -151,7 +152,7 @@ namespace osmium {
void parse_osm_data(osmium::osm_entity_bits::type read_types) { void parse_osm_data(osmium::osm_entity_bits::type read_types) {
osmium::thread::set_thread_name("_osmium_pbf_in"); osmium::thread::set_thread_name("_osmium_pbf_in");
int n=0; int n = 0;
while (auto size = read_blob_header("OSMData")) { while (auto size = read_blob_header("OSMData")) {
if (m_use_thread_pool) { if (m_use_thread_pool) {
@ -164,11 +165,20 @@ namespace osmium {
} }
++n; ++n;
if (m_done) { if (m_quit_input_thread) {
return; return;
} }
} }
m_done = true;
// Send an empty buffer to signal the reader that we are
// done.
std::promise<osmium::memory::Buffer> promise;
m_queue.push(promise.get_future());
promise.set_value(osmium::memory::Buffer{});
}
void signal_input_thread_to_quit() {
m_quit_input_thread = true;
} }
public: public:
@ -184,7 +194,7 @@ namespace osmium {
osmium::io::detail::InputFormat(file, read_which_entities), osmium::io::detail::InputFormat(file, read_which_entities),
m_use_thread_pool(osmium::config::use_pool_threads_for_pbf_parsing()), m_use_thread_pool(osmium::config::use_pool_threads_for_pbf_parsing()),
m_queue(20, "pbf_parser_results"), // XXX m_queue(20, "pbf_parser_results"), // XXX
m_done(false), m_quit_input_thread(false),
m_input_queue(input_queue), m_input_queue(input_queue),
m_input_buffer() { m_input_buffer() {
GOOGLE_PROTOBUF_VERIFY_VERSION; GOOGLE_PROTOBUF_VERIFY_VERSION;
@ -199,30 +209,37 @@ namespace osmium {
} }
~PBFInputFormat() { ~PBFInputFormat() {
m_done = true; signal_input_thread_to_quit();
if (m_reader.joinable()) { if (m_reader.joinable()) {
m_reader.join(); m_reader.join();
} }
} }
/** /**
* Returns the next buffer with OSM data read from the PBF file. * Returns the next buffer with OSM data read from the PBF
* Blocks if data is not available yet. * file. Blocks if data is not available yet.
* Returns an empty buffer at end of input. * Returns an empty buffer at end of input.
*/ */
osmium::memory::Buffer read() override { osmium::memory::Buffer read() override {
if (!m_done || !m_queue.empty()) { osmium::memory::Buffer buffer;
std::future<osmium::memory::Buffer> buffer_future; if (m_eof) {
m_queue.wait_and_pop(buffer_future); return buffer;
try {
return buffer_future.get();
} catch (...) {
m_done = true;
throw;
}
} }
return osmium::memory::Buffer(); std::future<osmium::memory::Buffer> buffer_future;
m_queue.wait_and_pop(buffer_future);
try {
buffer = std::move(buffer_future.get());
if (!buffer) {
m_eof = true;
}
return buffer;
} catch (...) {
m_eof = true;
signal_input_thread_to_quit();
throw;
}
} }
}; // class PBFInputFormat }; // class PBFInputFormat

View File

@ -294,6 +294,14 @@ namespace osmium {
*/ */
bool m_use_compression {true}; bool m_use_compression {true};
/**
* Should the string tables in the data blocks be sorted?
*
* Not sorting the string tables makes writing PBF files
* slightly faster.
*/
bool m_sort_stringtables { true };
/** /**
* While the .osm.pbf-format is able to carry all meta information, it is * While the .osm.pbf-format is able to carry all meta information, it is
* also able to omit this information to reduce size. * also able to omit this information to reduce size.
@ -340,6 +348,21 @@ namespace osmium {
///// Blob writing ///// ///// Blob writing /////
void delta_encode_string_ids() {
if (pbf_nodes && pbf_nodes->has_dense()) {
OSMPBF::DenseNodes* dense = pbf_nodes->mutable_dense();
if (dense->has_denseinfo()) {
OSMPBF::DenseInfo* denseinfo = dense->mutable_denseinfo();
for (int i = 0, l=denseinfo->user_sid_size(); i<l; ++i) {
auto user_sid = denseinfo->user_sid(i);
denseinfo->set_user_sid(i, m_delta_user_sid.update(user_sid));
}
}
}
}
/** /**
* Before a PrimitiveBlock gets serialized, all interim StringTable-ids needs to be * Before a PrimitiveBlock gets serialized, all interim StringTable-ids needs to be
* mapped to the associated real StringTable ids. This is done in this function. * mapped to the associated real StringTable ids. This is done in this function.
@ -351,7 +374,7 @@ namespace osmium {
// test, if the node-block has been allocated // test, if the node-block has been allocated
if (pbf_nodes) { if (pbf_nodes) {
// iterate over all nodes, passing them to the map_common_string_ids function // iterate over all nodes, passing them to the map_common_string_ids function
for (int i=0, l=pbf_nodes->nodes_size(); i<l; ++i) { for (int i = 0, l=pbf_nodes->nodes_size(); i<l; ++i) {
map_common_string_ids(pbf_nodes->mutable_nodes(i)); map_common_string_ids(pbf_nodes->mutable_nodes(i));
} }
@ -363,7 +386,7 @@ namespace osmium {
// in the densenodes structure keys and vals are encoded in an intermixed // in the densenodes structure keys and vals are encoded in an intermixed
// array, individual nodes are seperated by a value of 0 (0 in the StringTable // array, individual nodes are seperated by a value of 0 (0 in the StringTable
// is always unused). String-ids of 0 are thus kept alone. // is always unused). String-ids of 0 are thus kept alone.
for (int i=0, l=dense->keys_vals_size(); i<l; ++i) { for (int i = 0, l=dense->keys_vals_size(); i<l; ++i) {
// map interim string-ids > 0 to real string ids // map interim string-ids > 0 to real string ids
auto sid = dense->keys_vals(i); auto sid = dense->keys_vals(i);
if (sid > 0) { if (sid > 0) {
@ -377,7 +400,7 @@ namespace osmium {
OSMPBF::DenseInfo* denseinfo = dense->mutable_denseinfo(); OSMPBF::DenseInfo* denseinfo = dense->mutable_denseinfo();
// iterate over all username string-ids // iterate over all username string-ids
for (int i=0, l=denseinfo->user_sid_size(); i<l; ++i) { for (int i = 0, l=denseinfo->user_sid_size(); i<l; ++i) {
// map interim string-ids > 0 to real string ids // map interim string-ids > 0 to real string ids
auto user_sid = string_table.map_string_id(denseinfo->user_sid(i)); auto user_sid = string_table.map_string_id(denseinfo->user_sid(i));
@ -391,7 +414,7 @@ namespace osmium {
// test, if the ways-block has been allocated // test, if the ways-block has been allocated
if (pbf_ways) { if (pbf_ways) {
// iterate over all ways, passing them to the map_common_string_ids function // iterate over all ways, passing them to the map_common_string_ids function
for (int i=0, l=pbf_ways->ways_size(); i<l; ++i) { for (int i = 0, l=pbf_ways->ways_size(); i<l; ++i) {
map_common_string_ids(pbf_ways->mutable_ways(i)); map_common_string_ids(pbf_ways->mutable_ways(i));
} }
} }
@ -399,7 +422,7 @@ namespace osmium {
// test, if the relations-block has been allocated // test, if the relations-block has been allocated
if (pbf_relations) { if (pbf_relations) {
// iterate over all relations // iterate over all relations
for (int i=0, l=pbf_relations->relations_size(); i<l; ++i) { for (int i = 0, l=pbf_relations->relations_size(); i<l; ++i) {
// get a pointer to the relation // get a pointer to the relation
OSMPBF::Relation* relation = pbf_relations->mutable_relations(i); OSMPBF::Relation* relation = pbf_relations->mutable_relations(i);
@ -408,7 +431,7 @@ namespace osmium {
// iterate over all relation members, mapping the interim string-ids // iterate over all relation members, mapping the interim string-ids
// of the role to real string ids // of the role to real string ids
for (int mi=0; mi < relation->roles_sid_size(); ++mi) { for (int mi = 0; mi < relation->roles_sid_size(); ++mi) {
relation->set_roles_sid(mi, string_table.map_string_id(relation->roles_sid(mi))); relation->set_roles_sid(mi, string_table.map_string_id(relation->roles_sid(mi)));
} }
} }
@ -431,7 +454,7 @@ namespace osmium {
} }
// iterate over all tags and map the interim-ids of the key and the value to real ids // iterate over all tags and map the interim-ids of the key and the value to real ids
for (int i=0, l=in->keys_size(); i<l; ++i) { for (int i = 0, l=in->keys_size(); i<l; ++i) {
in->set_keys(i, string_table.map_string_id(in->keys(i))); in->set_keys(i, string_table.map_string_id(in->keys(i)));
in->set_vals(i, string_table.map_string_id(in->vals(i))); in->set_vals(i, string_table.map_string_id(in->vals(i)));
} }
@ -518,11 +541,13 @@ namespace osmium {
pbf_primitive_block.set_granularity(location_granularity()); pbf_primitive_block.set_granularity(location_granularity());
pbf_primitive_block.set_date_granularity(date_granularity()); pbf_primitive_block.set_date_granularity(date_granularity());
// store the interim StringTable into the protobuf object string_table.store_stringtable(pbf_primitive_block.mutable_stringtable(), m_sort_stringtables);
string_table.store_stringtable(pbf_primitive_block.mutable_stringtable());
// map all interim string ids to real ids if (m_sort_stringtables) {
map_string_ids(); map_string_ids();
} else {
delta_encode_string_ids();
}
std::promise<std::string> promise; std::promise<std::string> promise;
m_output_queue.push(promise.get_future()); m_output_queue.push(promise.get_future());
@ -743,6 +768,9 @@ namespace osmium {
if (file.get("pbf_compression") == "none" || file.get("pbf_compression") == "false") { if (file.get("pbf_compression") == "none" || file.get("pbf_compression") == "false") {
m_use_compression = false; m_use_compression = false;
} }
if (file.get("pbf_sort_stringtables") == "false") {
m_sort_stringtables = false;
}
if (file.get("pbf_add_metadata") == "false") { if (file.get("pbf_add_metadata") == "false") {
m_should_add_metadata = false; m_should_add_metadata = false;
} }

View File

@ -106,7 +106,7 @@ namespace osmium {
m_date_factor = pbf_primitive_block.date_granularity() / 1000; m_date_factor = pbf_primitive_block.date_granularity() / 1000;
m_granularity = pbf_primitive_block.granularity(); m_granularity = pbf_primitive_block.granularity();
for (int i=0; i < pbf_primitive_block.primitivegroup_size(); ++i) { for (int i = 0; i < pbf_primitive_block.primitivegroup_size(); ++i) {
const OSMPBF::PrimitiveGroup& group = pbf_primitive_block.primitivegroup(i); const OSMPBF::PrimitiveGroup& group = pbf_primitive_block.primitivegroup(i);
if (group.has_dense()) { if (group.has_dense()) {
@ -148,7 +148,7 @@ namespace osmium {
} }
void parse_node_group(const OSMPBF::PrimitiveGroup& group) { void parse_node_group(const OSMPBF::PrimitiveGroup& group) {
for (int i=0; i < group.nodes_size(); ++i) { for (int i = 0; i < group.nodes_size(); ++i) {
osmium::builder::NodeBuilder builder(m_buffer); osmium::builder::NodeBuilder builder(m_buffer);
const OSMPBF::Node& pbf_node = group.nodes(i); const OSMPBF::Node& pbf_node = group.nodes(i);
parse_attributes(builder, pbf_node); parse_attributes(builder, pbf_node);
@ -161,7 +161,7 @@ namespace osmium {
if (pbf_node.keys_size() > 0) { if (pbf_node.keys_size() > 0) {
osmium::builder::TagListBuilder tl_builder(m_buffer, &builder); osmium::builder::TagListBuilder tl_builder(m_buffer, &builder);
for (int tag=0; tag < pbf_node.keys_size(); ++tag) { for (int tag = 0; tag < pbf_node.keys_size(); ++tag) {
tl_builder.add_tag(m_stringtable->s(static_cast<int>(pbf_node.keys(tag))), tl_builder.add_tag(m_stringtable->s(static_cast<int>(pbf_node.keys(tag))),
m_stringtable->s(static_cast<int>(pbf_node.vals(tag)))); m_stringtable->s(static_cast<int>(pbf_node.vals(tag))));
} }
@ -172,7 +172,7 @@ namespace osmium {
} }
void parse_way_group(const OSMPBF::PrimitiveGroup& group) { void parse_way_group(const OSMPBF::PrimitiveGroup& group) {
for (int i=0; i < group.ways_size(); ++i) { for (int i = 0; i < group.ways_size(); ++i) {
osmium::builder::WayBuilder builder(m_buffer); osmium::builder::WayBuilder builder(m_buffer);
const OSMPBF::Way& pbf_way = group.ways(i); const OSMPBF::Way& pbf_way = group.ways(i);
parse_attributes(builder, pbf_way); parse_attributes(builder, pbf_way);
@ -180,7 +180,7 @@ namespace osmium {
if (pbf_way.refs_size() > 0) { if (pbf_way.refs_size() > 0) {
osmium::builder::WayNodeListBuilder wnl_builder(m_buffer, &builder); osmium::builder::WayNodeListBuilder wnl_builder(m_buffer, &builder);
int64_t ref = 0; int64_t ref = 0;
for (int n=0; n < pbf_way.refs_size(); ++n) { for (int n = 0; n < pbf_way.refs_size(); ++n) {
ref += pbf_way.refs(n); ref += pbf_way.refs(n);
wnl_builder.add_node_ref(ref); wnl_builder.add_node_ref(ref);
} }
@ -188,7 +188,7 @@ namespace osmium {
if (pbf_way.keys_size() > 0) { if (pbf_way.keys_size() > 0) {
osmium::builder::TagListBuilder tl_builder(m_buffer, &builder); osmium::builder::TagListBuilder tl_builder(m_buffer, &builder);
for (int tag=0; tag < pbf_way.keys_size(); ++tag) { for (int tag = 0; tag < pbf_way.keys_size(); ++tag) {
tl_builder.add_tag(m_stringtable->s(static_cast<int>(pbf_way.keys(tag))), tl_builder.add_tag(m_stringtable->s(static_cast<int>(pbf_way.keys(tag))),
m_stringtable->s(static_cast<int>(pbf_way.vals(tag)))); m_stringtable->s(static_cast<int>(pbf_way.vals(tag))));
} }
@ -199,7 +199,7 @@ namespace osmium {
} }
void parse_relation_group(const OSMPBF::PrimitiveGroup& group) { void parse_relation_group(const OSMPBF::PrimitiveGroup& group) {
for (int i=0; i < group.relations_size(); ++i) { for (int i = 0; i < group.relations_size(); ++i) {
osmium::builder::RelationBuilder builder(m_buffer); osmium::builder::RelationBuilder builder(m_buffer);
const OSMPBF::Relation& pbf_relation = group.relations(i); const OSMPBF::Relation& pbf_relation = group.relations(i);
parse_attributes(builder, pbf_relation); parse_attributes(builder, pbf_relation);
@ -207,7 +207,7 @@ namespace osmium {
if (pbf_relation.types_size() > 0) { if (pbf_relation.types_size() > 0) {
osmium::builder::RelationMemberListBuilder rml_builder(m_buffer, &builder); osmium::builder::RelationMemberListBuilder rml_builder(m_buffer, &builder);
int64_t ref = 0; int64_t ref = 0;
for (int n=0; n < pbf_relation.types_size(); ++n) { for (int n = 0; n < pbf_relation.types_size(); ++n) {
ref += pbf_relation.memids(n); ref += pbf_relation.memids(n);
rml_builder.add_member(osmpbf_membertype_to_item_type(pbf_relation.types(n)), ref, m_stringtable->s(pbf_relation.roles_sid(n))); rml_builder.add_member(osmpbf_membertype_to_item_type(pbf_relation.types(n)), ref, m_stringtable->s(pbf_relation.roles_sid(n)));
} }
@ -215,7 +215,7 @@ namespace osmium {
if (pbf_relation.keys_size() > 0) { if (pbf_relation.keys_size() > 0) {
osmium::builder::TagListBuilder tl_builder(m_buffer, &builder); osmium::builder::TagListBuilder tl_builder(m_buffer, &builder);
for (int tag=0; tag < pbf_relation.keys_size(); ++tag) { for (int tag = 0; tag < pbf_relation.keys_size(); ++tag) {
tl_builder.add_tag(m_stringtable->s(static_cast<int>(pbf_relation.keys(tag))), tl_builder.add_tag(m_stringtable->s(static_cast<int>(pbf_relation.keys(tag))),
m_stringtable->s(static_cast<int>(pbf_relation.vals(tag)))); m_stringtable->s(static_cast<int>(pbf_relation.vals(tag))));
} }
@ -264,7 +264,7 @@ namespace osmium {
const OSMPBF::DenseNodes& dense = group.dense(); const OSMPBF::DenseNodes& dense = group.dense();
for (int i=0; i < dense.id_size(); ++i) { for (int i = 0; i < dense.id_size(); ++i) {
bool visible = true; bool visible = true;
last_dense_id += dense.id(i); last_dense_id += dense.id(i);
@ -361,7 +361,7 @@ namespace osmium {
} }
osmium::io::Header header; osmium::io::Header header;
for (int i=0; i < pbf_header_block.required_features_size(); ++i) { for (int i = 0; i < pbf_header_block.required_features_size(); ++i) {
const std::string& feature = pbf_header_block.required_features(i); const std::string& feature = pbf_header_block.required_features(i);
if (feature == "OsmSchema-V0.6") continue; if (feature == "OsmSchema-V0.6") continue;
@ -377,7 +377,7 @@ namespace osmium {
throw osmium::pbf_error(std::string("required feature not supported: ") + feature); throw osmium::pbf_error(std::string("required feature not supported: ") + feature);
} }
for (int i=0; i < pbf_header_block.optional_features_size(); ++i) { for (int i = 0; i < pbf_header_block.optional_features_size(); ++i) {
const std::string& feature = pbf_header_block.optional_features(i); const std::string& feature = pbf_header_block.optional_features(i);
header.set("pbf_optional_feature_" + std::to_string(i), feature); header.set("pbf_optional_feature_" + std::to_string(i), feature);
} }

View File

@ -145,30 +145,44 @@ namespace osmium {
* implementation) is that the string table is sorted first by reverse count (ie descending) * implementation) is that the string table is sorted first by reverse count (ie descending)
* and then by reverse lexicographic order. * and then by reverse lexicographic order.
*/ */
void store_stringtable(OSMPBF::StringTable* st) { void store_stringtable(OSMPBF::StringTable* st, bool sort) {
// add empty StringTable entry at index 0 // add empty StringTable entry at index 0
// StringTable index 0 is reserved as delimiter in the densenodes key/value list // StringTable index 0 is reserved as delimiter in the densenodes key/value list
// this line also ensures that there's always a valid StringTable // this line also ensures that there's always a valid StringTable
st->add_s(""); st->add_s("");
std::multimap<string_info, std::string> sortedbycount; if (sort) {
std::multimap<string_info, std::string> sortedbycount;
m_id2id_map.resize(m_size+1); m_id2id_map.resize(m_size+1);
std::transform(m_strings.begin(), m_strings.end(), std::transform(m_strings.begin(), m_strings.end(),
std::inserter(sortedbycount, sortedbycount.begin()), std::inserter(sortedbycount, sortedbycount.begin()),
[](const std::pair<std::string, string_info>& p) { [](const std::pair<std::string, string_info>& p) {
return std::pair<string_info, std::string>(p.second, p.first); return std::pair<string_info, std::string>(p.second, p.first);
}); });
string_id_type n=0; string_id_type n = 0;
for (const auto& mapping : sortedbycount) { for (const auto& mapping : sortedbycount) {
// add the string of the current item to the pbf StringTable // add the string of the current item to the pbf StringTable
st->add_s(mapping.second); st->add_s(mapping.second);
// store the mapping from the interim-id to the real id // store the mapping from the interim-id to the real id
m_id2id_map[mapping.first.interim_id] = ++n; m_id2id_map[mapping.first.interim_id] = ++n;
}
} else {
std::vector<std::pair<string_id_type, const char*>> sortedbyid;
sortedbyid.reserve(m_strings.size());
for (const auto& p : m_strings) {
sortedbyid.emplace_back(p.second.interim_id, p.first.c_str());
}
std::sort(sortedbyid.begin(), sortedbyid.end());
for (const auto& mapping : sortedbyid) {
st->add_s(mapping.second);
}
} }
} }

View File

@ -74,8 +74,8 @@ namespace osmium {
/** /**
* Exception thrown when the XML parser failed. The exception contains * Exception thrown when the XML parser failed. The exception contains
* information about the place where the error happened and the type of * (if available) information about the place where the error happened
* error. * and the type of error.
*/ */
struct xml_error : public io_error { struct xml_error : public io_error {
@ -84,7 +84,7 @@ namespace osmium {
XML_Error error_code; XML_Error error_code;
std::string error_string; std::string error_string;
xml_error(XML_Parser parser) : explicit xml_error(XML_Parser parser) :
io_error(std::string("XML parsing error at line ") io_error(std::string("XML parsing error at line ")
+ std::to_string(XML_GetCurrentLineNumber(parser)) + std::to_string(XML_GetCurrentLineNumber(parser))
+ ", column " + ", column "
@ -97,8 +97,20 @@ namespace osmium {
error_string(XML_ErrorString(error_code)) { error_string(XML_ErrorString(error_code)) {
} }
explicit xml_error(const std::string& message) :
io_error(message),
line(0),
column(0),
error_code(),
error_string(message) {
}
}; // struct xml_error }; // struct xml_error
/**
* Exception thrown when an OSM XML files contains no version attribute
* on the 'osm' element or if the version is unknown.
*/
struct format_version_error : public io_error { struct format_version_error : public io_error {
std::string version; std::string version;
@ -434,6 +446,8 @@ namespace osmium {
if (m_header.get("version") == "") { if (m_header.get("version") == "") {
throw osmium::format_version_error(); throw osmium::format_version_error();
} }
} else {
throw osmium::xml_error(std::string("Unknown top-level element: ") + element);
} }
m_context = context::top; m_context = context::top;
break; break;

View File

@ -130,7 +130,7 @@ namespace osmium {
const bool m_write_change_ops; const bool m_write_change_ops;
void write_spaces(int num) { void write_spaces(int num) {
for (; num!=0; --num) { for (; num != 0; --num) {
*m_out += ' '; *m_out += ' ';
} }
} }

View File

@ -76,7 +76,7 @@ namespace osmium {
namespace detail { namespace detail {
OSMIUM_NORETURN inline void throw_gzip_error(gzFile gzfile, const char* msg, int zlib_error=0) { OSMIUM_NORETURN inline void throw_gzip_error(gzFile gzfile, const char* msg, int zlib_error = 0) {
std::string error("gzip error: "); std::string error("gzip error: ");
error += msg; error += msg;
error += ": "; error += ": ";

View File

@ -109,7 +109,7 @@ namespace osmium {
} }
if (pid == 0) { // child if (pid == 0) { // child
// close all file descriptors except one end of the pipe // close all file descriptors except one end of the pipe
for (int i=0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
if (i != pipefd[1]) { if (i != pipefd[1]) {
::close(i); ::close(i);
} }
@ -260,7 +260,7 @@ namespace osmium {
// m_input->read() can return an invalid buffer to signal EOF, // m_input->read() can return an invalid buffer to signal EOF,
// or a valid buffer with or without data. A valid buffer // or a valid buffer with or without data. A valid buffer
// without data is not an error, it just means we have to get // without data is not an error, it just means we have to
// keep getting the next buffer until there is one with data. // keep getting the next buffer until there is one with data.
while (true) { while (true) {
osmium::memory::Buffer buffer = m_input->read(); osmium::memory::Buffer buffer = m_input->read();

View File

@ -55,8 +55,7 @@ namespace osmium {
template <typename T> template <typename T>
inline T padded_length(T length) noexcept { inline T padded_length(T length) noexcept {
static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value, static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value, "Template parameter must be unsigned integral type");
"Template parameter must be unsigned integral type");
return (length + align_bytes - 1) & ~(align_bytes - 1); return (length + align_bytes - 1) & ~(align_bytes - 1);
} }
@ -119,7 +118,7 @@ namespace osmium {
protected: protected:
explicit Item(item_size_type size=0, item_type type=item_type()) noexcept : explicit Item(item_size_type size = 0, item_type type = item_type()) noexcept :
m_size(size), m_size(size),
m_type(type), m_type(type),
m_removed(false), m_removed(false),

View File

@ -53,12 +53,14 @@ namespace osmium {
/** /**
* An outer ring of an Area. * An outer ring of an Area.
*/ */
class OuterRing : public NodeRefList<osmium::item_type::outer_ring> { class OuterRing : public NodeRefList {
public: public:
static constexpr osmium::item_type itemtype = osmium::item_type::outer_ring;
OuterRing(): OuterRing():
NodeRefList<osmium::item_type::outer_ring>() { NodeRefList(itemtype) {
} }
}; // class OuterRing }; // class OuterRing
@ -68,12 +70,14 @@ namespace osmium {
/** /**
* An inner ring of an Area. * An inner ring of an Area.
*/ */
class InnerRing : public NodeRefList<osmium::item_type::inner_ring> { class InnerRing : public NodeRefList {
public: public:
static constexpr osmium::item_type itemtype = osmium::item_type::inner_ring;
InnerRing(): InnerRing():
NodeRefList<osmium::item_type::inner_ring>() { NodeRefList(itemtype) {
} }
}; // class InnerRing }; // class InnerRing
@ -87,7 +91,7 @@ namespace osmium {
* @param type Type of object (way or relation) * @param type Type of object (way or relation)
* @returns Area id * @returns Area id
*/ */
inline osmium::object_id_type object_id_to_area_id(osmium::object_id_type id, osmium::item_type type) { inline osmium::object_id_type object_id_to_area_id(osmium::object_id_type id, osmium::item_type type) noexcept {
osmium::object_id_type area_id = std::abs(id) * 2; osmium::object_id_type area_id = std::abs(id) * 2;
if (type == osmium::item_type::relation) { if (type == osmium::item_type::relation) {
++area_id; ++area_id;
@ -101,7 +105,7 @@ namespace osmium {
* @param id Area id * @param id Area id
* @returns Way or Relation id. * @returns Way or Relation id.
*/ */
inline osmium::object_id_type area_id_to_object_id(osmium::object_id_type id) { inline osmium::object_id_type area_id_to_object_id(osmium::object_id_type id) noexcept {
return id / 2; return id / 2;
} }
@ -131,15 +135,17 @@ namespace osmium {
/** /**
* Return the Id of the way or relation this area was created from. * Return the Id of the way or relation this area was created from.
*/ */
osmium::object_id_type orig_id() const { osmium::object_id_type orig_id() const noexcept {
return osmium::area_id_to_object_id(id()); return osmium::area_id_to_object_id(id());
} }
/** /**
* Count the number of outer and inner rings of this area. * Count the number of outer and inner rings of this area.
*
* @returns Pair (number outer rings, number inner rings)
*/ */
std::pair<int, int> num_rings() const { std::pair<int, int> num_rings() const {
std::pair<int, int> counter; std::pair<int, int> counter { 0, 0 };
for (auto it = cbegin(); it != cend(); ++it) { for (auto it = cbegin(); it != cend(); ++it) {
switch (it->type()) { switch (it->type()) {
@ -170,16 +176,31 @@ namespace osmium {
} }
/** /**
* Is this area a multipolygon, ie. has it more than one outer ring? * Check whether this area is a multipolygon, ie. whether it has more
* than one outer ring?
*/ */
bool is_multipolygon() const { bool is_multipolygon() const {
return num_rings().first > 1; return num_rings().first > 1;
} }
/**
* Get iterator for iterating over all inner rings in a specified outer
* ring.
*
* @param it Iterator specifying outer ring.
* @returns Iterator to first inner ring in specified outer ring.
*/
osmium::memory::ItemIterator<const osmium::InnerRing> inner_ring_cbegin(const osmium::memory::ItemIterator<const osmium::OuterRing>& it) const { osmium::memory::ItemIterator<const osmium::InnerRing> inner_ring_cbegin(const osmium::memory::ItemIterator<const osmium::OuterRing>& it) const {
return it.cast<const osmium::InnerRing>(); return it.cast<const osmium::InnerRing>();
} }
/**
* Get iterator for iterating over all inner rings in a specified outer
* ring.
*
* @param it Iterator specifying outer ring.
* @returns Iterator one past last inner ring in specified outer ring.
*/
osmium::memory::ItemIterator<const osmium::InnerRing> inner_ring_cend(const osmium::memory::ItemIterator<const osmium::OuterRing>& it) const { osmium::memory::ItemIterator<const osmium::InnerRing> inner_ring_cend(const osmium::memory::ItemIterator<const osmium::OuterRing>& it) const {
return std::next(it).cast<const osmium::InnerRing>(); return std::next(it).cast<const osmium::InnerRing>();
} }

View File

@ -33,6 +33,7 @@ DEALINGS IN THE SOFTWARE.
*/ */
#include <cassert>
#include <iosfwd> #include <iosfwd>
#include <osmium/util/compatibility.hpp> #include <osmium/util/compatibility.hpp>
@ -41,7 +42,10 @@ DEALINGS IN THE SOFTWARE.
namespace osmium { namespace osmium {
/** /**
* Bounding box. * Bounding box. A box is defined by two locations (bottom left location
* and top right location) or, alternatively by four coordinates (minx,
* miny, maxx, and maxy). If both locations are undefined, the box is
* undefined, too.
*/ */
class Box { class Box {
@ -59,14 +63,33 @@ namespace osmium {
m_top_right() { m_top_right() {
} }
/**
* Create box from minimum and maximum coordinates.
*
* @pre @code minx <= maxx && miny <= maxy @endcode
*/
Box(double minx, double miny, double maxx, double maxy) : Box(double minx, double miny, double maxx, double maxy) :
m_bottom_left(minx, miny), m_bottom_left(minx, miny),
m_top_right(maxx, maxy) { m_top_right(maxx, maxy) {
assert(minx <= maxx && miny <= maxy);
} }
/**
* Create box from bottom left and top right locations.
*
* @pre Either both locations must be defined or neither.
* @pre If both locations are defined, the
* bottom left location must actually be to the left and below
* the top right location. Same coordinates for bottom/top or
* left/right are also okay.
*/
Box(const osmium::Location& bottom_left, const osmium::Location& top_right) : Box(const osmium::Location& bottom_left, const osmium::Location& top_right) :
m_bottom_left(bottom_left), m_bottom_left(bottom_left),
m_top_right(top_right) { m_top_right(top_right) {
assert(
(!!bottom_left && !!top_right) ||
(bottom_left.x() <= top_right.x() && bottom_left.y() <= top_right.y())
);
} }
Box(const Box&) = default; Box(const Box&) = default;
@ -76,8 +99,13 @@ namespace osmium {
~Box() = default; ~Box() = default;
/** /**
* Extend this bounding box by the given location. If the * Extend this bounding box by the specified location. If the
* location is undefined, the bounding box is unchanged. * location is undefined, the bounding box is unchanged. If
* the box is undefined it will only contain the location after
* this call.
*
* @param location The location we want to extend the box by.
* @returns A reference to this box.
*/ */
Box& extend(const Location& location) noexcept { Box& extend(const Location& location) noexcept {
if (location) { if (location) {
@ -103,8 +131,11 @@ namespace osmium {
} }
/** /**
* Extend this bounding box by the given box. If the * Extend this bounding box by the specified box. If the
* box is undefined, the bounding box is unchanged. * specified box is undefined, the bounding box is unchanged.
*
* @param box The box to extend by.
* @returns A reference to this box.
*/ */
Box& extend(const Box& box) noexcept { Box& extend(const Box& box) noexcept {
extend(box.bottom_left()); extend(box.bottom_left());
@ -113,14 +144,14 @@ namespace osmium {
} }
/** /**
* Box are defined, ie. contains defined coordinates. * Box is defined, ie. contains defined locations.
*/ */
explicit constexpr operator bool() const noexcept { explicit constexpr operator bool() const noexcept {
return static_cast<bool>(m_bottom_left); return static_cast<bool>(m_bottom_left);
} }
/** /**
* Box are valid, ie. defined and inside usual bounds * Box is valid, ie. defined and inside usual bounds
* (-180<=lon<=180, -90<=lat<=90). * (-180<=lon<=180, -90<=lat<=90).
*/ */
OSMIUM_CONSTEXPR bool valid() const noexcept { OSMIUM_CONSTEXPR bool valid() const noexcept {
@ -128,37 +159,43 @@ namespace osmium {
} }
/** /**
* Bottom-left location. * Access bottom-left location.
*/ */
OSMIUM_CONSTEXPR Location bottom_left() const noexcept { OSMIUM_CONSTEXPR Location bottom_left() const noexcept {
return m_bottom_left; return m_bottom_left;
} }
/** /**
* Bottom-left location. * Access bottom-left location.
*/ */
Location& bottom_left() noexcept { Location& bottom_left() noexcept {
return m_bottom_left; return m_bottom_left;
} }
/** /**
* Top-right location. * Access top-right location.
*/ */
OSMIUM_CONSTEXPR Location top_right() const noexcept { OSMIUM_CONSTEXPR Location top_right() const noexcept {
return m_top_right; return m_top_right;
} }
/** /**
* Top-right location. * Access top-right location.
*/ */
Location& top_right() noexcept { Location& top_right() noexcept {
return m_top_right; return m_top_right;
} }
/** /**
* Is the location inside the box? * Check whether the location is inside the box.
*
* @pre Location must be defined.
* @pre Box must be defined.
*/ */
bool contains(const osmium::Location& location) const { bool contains(const osmium::Location& location) const noexcept {
assert(bottom_left());
assert(top_right());
assert(location);
return location.x() >= bottom_left().x() && location.y() >= bottom_left().y() && return location.x() >= bottom_left().x() && location.y() >= bottom_left().y() &&
location.x() <= top_right().x() && location.y() <= top_right().y(); location.x() <= top_right().x() && location.y() <= top_right().y();
} }
@ -166,7 +203,7 @@ namespace osmium {
/** /**
* Calculate size of the box in square degrees. * Calculate size of the box in square degrees.
* *
* @throws osmium::invalid_location unless all coordinates are valid * @throws osmium::invalid_location unless all coordinates are valid.
*/ */
double size() const { double size() const {
return (m_top_right.lon() - m_bottom_left.lon()) * return (m_top_right.lon() - m_bottom_left.lon()) *
@ -176,14 +213,19 @@ namespace osmium {
}; // class Box }; // class Box
/** /**
* Boxes are equal if both locations are equal. * Boxes are equal if both locations are equal. Undefined boxes will
* compare equal.
*/ */
inline OSMIUM_CONSTEXPR bool operator==(const Box& lhs, const Box& rhs) noexcept { inline OSMIUM_CONSTEXPR bool operator==(const Box& lhs, const Box& rhs) noexcept {
return lhs.bottom_left() == rhs.bottom_left() && lhs.top_right() == rhs.top_right(); return lhs.bottom_left() == rhs.bottom_left() &&
lhs.top_right() == rhs.top_right();
} }
/** /**
* Output a box to a stream. * Output a box to a stream. The format is "(LON, LAT, LON, LAT)" or
* "(undefined)" if the box is undefined.
*
* @returns Reference to basic_ostream given as first parameter.
*/ */
template <typename TChar, typename TTraits> template <typename TChar, typename TTraits>
inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const osmium::Box& box) { inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const osmium::Box& box) {
@ -202,6 +244,7 @@ namespace osmium {
} }
return out; return out;
} }
} // namespace osmium } // namespace osmium
#endif // OSMIUM_OSM_BOX_HPP #endif // OSMIUM_OSM_BOX_HPP

View File

@ -298,8 +298,7 @@ namespace osmium {
}; // class Changeset }; // class Changeset
static_assert(sizeof(Changeset) % osmium::memory::align_bytes == 0, static_assert(sizeof(Changeset) % osmium::memory::align_bytes == 0, "Class osmium::Changeset has wrong size to be aligned properly!");
"Class osmium::Changeset has wrong size to be aligned properly!");
/** /**
* Changesets are equal if their IDs are equal. * Changesets are equal if their IDs are equal.

View File

@ -54,7 +54,7 @@ namespace osmium {
public: public:
NodeRef(const osmium::object_id_type ref=0, const osmium::Location& location=Location()) noexcept : NodeRef(const osmium::object_id_type ref = 0, const osmium::Location& location = Location()) noexcept :
m_ref(ref), m_ref(ref),
m_location(location) { m_location(location) {
} }

View File

@ -44,51 +44,92 @@ DEALINGS IN THE SOFTWARE.
namespace osmium { namespace osmium {
/** /**
* A vector of NodeRef objects. Usually this is not instatiated directly, * A vector of NodeRef objects. Usually this is not instantiated directly,
* but one of its subclasses are used. * but one of its subclasses are used.
*/ */
template <osmium::item_type TItemType>
class NodeRefList : public osmium::memory::Item { class NodeRefList : public osmium::memory::Item {
public: public:
static constexpr osmium::item_type itemtype = TItemType; NodeRefList(osmium::item_type itemtype) noexcept :
osmium::memory::Item(sizeof(NodeRefList), itemtype) {
NodeRefList() noexcept :
osmium::memory::Item(sizeof(NodeRefList), TItemType) {
} }
/**
* Checks whether the node list is empty.
*/
bool empty() const noexcept { bool empty() const noexcept {
return sizeof(NodeRefList) == byte_size(); return sizeof(NodeRefList) == byte_size();
} }
/**
* Returns the number of nodes in the list.
*/
size_t size() const noexcept { size_t size() const noexcept {
assert((osmium::memory::Item::byte_size() - sizeof(NodeRefList)) % sizeof(NodeRef) == 0); auto size_node_refs = osmium::memory::Item::byte_size() - sizeof(NodeRefList);
return (osmium::memory::Item::byte_size() - sizeof(NodeRefList)) / sizeof(NodeRef); assert(size_node_refs % sizeof(NodeRef) == 0);
return size_node_refs / sizeof(NodeRef);
} }
const NodeRef& operator[](size_t n) const { /**
* Access specified element.
*
* @param n Get this element of the list.
* @pre @code n < size() @endcode
*/
const NodeRef& operator[](size_t n) const noexcept {
assert(n < size());
const NodeRef* node_ref = &*(cbegin()); const NodeRef* node_ref = &*(cbegin());
return node_ref[n]; return node_ref[n];
} }
const NodeRef& front() const { /**
* Access the first element.
*
* @pre @code !empty() @endcode
*/
const NodeRef& front() const noexcept {
assert(!empty());
return operator[](0); return operator[](0);
} }
const NodeRef& back() const { /**
* Access the last element.
*
* @pre @code !empty() @endcode
*/
const NodeRef& back() const noexcept {
assert(!empty());
return operator[](size()-1); return operator[](size()-1);
} }
bool is_closed() const { /**
* Checks whether the first and last node in the list have the same ID.
*
* @pre @code !empty() @endcode
*/
bool is_closed() const noexcept {
return front().ref() == back().ref(); return front().ref() == back().ref();
} }
bool ends_have_same_id() const { /**
* Checks whether the first and last node in the list have the same ID.
*
* @pre @code !empty() @endcode
*/
bool ends_have_same_id() const noexcept {
return front().ref() == back().ref(); return front().ref() == back().ref();
} }
/**
* Checks whether the first and last node in the list have the same
* location. The ID is not checked.
*
* @pre @code !empty() @endcode
* @pre @code front().location() && back().location() @endcode
*/
bool ends_have_same_location() const { bool ends_have_same_location() const {
assert(front().location() && back().location());
return front().location() == back().location(); return front().location() == back().location();
} }
@ -96,35 +137,43 @@ namespace osmium {
typedef const NodeRef* const_iterator; typedef const NodeRef* const_iterator;
typedef std::reverse_iterator<const NodeRef*> const_reverse_iterator; typedef std::reverse_iterator<const NodeRef*> const_reverse_iterator;
iterator begin() { /// Returns an iterator to the beginning.
iterator begin() noexcept {
return iterator(data() + sizeof(NodeRefList)); return iterator(data() + sizeof(NodeRefList));
} }
iterator end() { /// Returns an iterator to the end.
iterator end() noexcept {
return iterator(data() + byte_size()); return iterator(data() + byte_size());
} }
const_iterator cbegin() const { /// Returns an iterator to the beginning.
const_iterator cbegin() const noexcept {
return const_iterator(data() + sizeof(NodeRefList)); return const_iterator(data() + sizeof(NodeRefList));
} }
const_iterator cend() const { /// Returns an iterator to the end.
const_iterator cend() const noexcept {
return const_iterator(data() + byte_size()); return const_iterator(data() + byte_size());
} }
const_iterator begin() const { /// Returns an iterator to the beginning.
const_iterator begin() const noexcept {
return cbegin(); return cbegin();
} }
const_iterator end() const { /// Returns an iterator to the end.
const_iterator end() const noexcept {
return cend(); return cend();
} }
const_reverse_iterator crbegin() const { /// Returns a reverse_iterator to the beginning.
const_reverse_iterator crbegin() const noexcept {
return const_reverse_iterator(cend()); return const_reverse_iterator(cend());
} }
const_reverse_iterator crend() const { /// Returns a reverse_iterator to the end.
const_reverse_iterator crend() const noexcept {
return const_reverse_iterator(cbegin()); return const_reverse_iterator(cbegin());
} }

View File

@ -101,7 +101,7 @@ namespace osmium {
static constexpr item_type collection_type = item_type::relation_member_list; static constexpr item_type collection_type = item_type::relation_member_list;
RelationMember(const object_id_type ref=0, const item_type type=item_type(), const bool full=false) noexcept : RelationMember(const object_id_type ref = 0, const item_type type = item_type(), const bool full = false) noexcept :
m_ref(ref), m_ref(ref),
m_type(type), m_type(type),
m_flags(full ? 1 : 0) { m_flags(full ? 1 : 0) {

View File

@ -113,6 +113,10 @@ namespace osmium {
return static_cast<time_t>(m_timestamp); return static_cast<time_t>(m_timestamp);
} }
explicit constexpr operator uint32_t() const noexcept {
return m_timestamp;
}
template <typename T> template <typename T>
void operator+=(T time_difference) noexcept { void operator+=(T time_difference) noexcept {
m_timestamp += time_difference; m_timestamp += time_difference;

View File

@ -49,12 +49,14 @@ namespace osmium {
/** /**
* List of node references (id and location) in a way. * List of node references (id and location) in a way.
*/ */
class WayNodeList : public NodeRefList<osmium::item_type::way_node_list> { class WayNodeList : public NodeRefList {
public: public:
static constexpr osmium::item_type itemtype = osmium::item_type::way_node_list;
WayNodeList(): WayNodeList():
NodeRefList<osmium::item_type::way_node_list>() { NodeRefList(itemtype) {
} }
}; // class WayNodeList }; // class WayNodeList

View File

@ -389,7 +389,7 @@ namespace osmium {
RelationMeta relation_meta(offset); RelationMeta relation_meta(offset);
int n=0; int n = 0;
for (auto& member : m_relations_buffer.get<osmium::Relation>(offset).members()) { for (auto& member : m_relations_buffer.get<osmium::Relation>(offset).members()) {
if (static_cast<TCollector*>(this)->keep_member(relation_meta, member)) { if (static_cast<TCollector*>(this)->keep_member(relation_meta, member)) {
member_meta(member.type()).emplace_back(member.ref(), m_relations.size(), n); member_meta(member.type()).emplace_back(member.ref(), m_relations.size(), n);

View File

@ -128,7 +128,7 @@ namespace osmium {
} }
try { try {
for (int i=0; i < m_num_threads; ++i) { for (int i = 0; i < m_num_threads; ++i) {
m_threads.push_back(std::thread(&Pool::worker_thread, this)); m_threads.push_back(std::thread(&Pool::worker_thread, this));
} }
} catch (...) { } catch (...) {

View File

@ -49,7 +49,7 @@ namespace osmium {
namespace thread { namespace thread {
OSMIUM_CONSTEXPR std::chrono::milliseconds full_queue_sleep_duration { 10 }; // XXX static const std::chrono::milliseconds full_queue_sleep_duration { 10 }; // XXX
/** /**
* A thread-safe queue. * A thread-safe queue.
@ -137,7 +137,7 @@ namespace osmium {
m_data_available.wait(lock, [this] { m_data_available.wait(lock, [this] {
return !m_queue.empty(); return !m_queue.empty();
}); });
value=std::move(m_queue.front()); value = std::move(m_queue.front());
m_queue.pop(); m_queue.pop();
} }
@ -148,7 +148,7 @@ namespace osmium {
})) { })) {
return; return;
} }
value=std::move(m_queue.front()); value = std::move(m_queue.front());
m_queue.pop(); m_queue.pop();
} }
@ -157,7 +157,7 @@ namespace osmium {
if (m_queue.empty()) { if (m_queue.empty()) {
return false; return false;
} }
value=std::move(m_queue.front()); value = std::move(m_queue.front());
m_queue.pop(); m_queue.pop();
return true; return true;
} }

View File

@ -107,7 +107,7 @@ namespace osmium {
m_data_available.wait(lock, [this] { m_data_available.wait(lock, [this] {
return !empty_intern(); return !empty_intern();
}); });
value=std::move(m_queue.front()); value = std::move(m_queue.front());
m_queue.pop_front(); m_queue.pop_front();
++m_offset; ++m_offset;
} }
@ -122,7 +122,7 @@ namespace osmium {
if (empty_intern()) { if (empty_intern()) {
return false; return false;
} }
value=std::move(m_queue.front()); value = std::move(m_queue.front());
m_queue.pop_front(); m_queue.pop_front();
++m_offset; ++m_offset;
return true; return true;

View File

@ -37,6 +37,7 @@ DEALINGS IN THE SOFTWARE.
# include <cassert> # include <cassert>
#endif #endif
#include <cstdint>
#include <limits> #include <limits>
#include <type_traits> #include <type_traits>
@ -93,7 +94,7 @@ namespace osmium {
template <typename T, typename F, typename std::enable_if<are_real_integers<T, F>::value && !std::is_same<T, F>::value && (sizeof(T) <= sizeof(F)) && std::is_signed<T>::value && std::is_unsigned<F>::value, int>::type = 0> template <typename T, typename F, typename std::enable_if<are_real_integers<T, F>::value && !std::is_same<T, F>::value && (sizeof(T) <= sizeof(F)) && std::is_signed<T>::value && std::is_unsigned<F>::value, int>::type = 0>
inline T static_cast_with_assert(const F value) { inline T static_cast_with_assert(const F value) {
assert(value <= std::numeric_limits<T>::max()); assert(static_cast<int64_t>(value) <= static_cast<int64_t>(std::numeric_limits<T>::max()));
return static_cast<T>(value); return static_cast<T>(value);
} }

View File

@ -87,7 +87,7 @@ namespace osmium {
public: public:
explicit VerboseOutput(bool verbose=false) noexcept : explicit VerboseOutput(bool verbose = false) noexcept :
m_start(time(NULL)), m_start(time(NULL)),
m_verbose(verbose), m_verbose(verbose),
m_newline(true) { m_newline(true) {

View File

@ -8,6 +8,7 @@
message(STATUS "Configuring unit tests") message(STATUS "Configuring unit tests")
include(CMakeParseArguments)
include_directories(include) include_directories(include)
add_library(testlib STATIC test_main.cpp) add_library(testlib STATIC test_main.cpp)
@ -19,40 +20,62 @@ set(ALL_TESTS "")
# #
# Define function for adding tests # Define function for adding tests
# #
# Call with parameters: # add_unit_tests(group name [ENABLE_IF bool] [LIBS libs] [LABELS labels])
# TGROUP - test group (directory) #
# TNAME - name of test # group - test group (directory)
# ARGV2 - flag to enable test (optional) # name - name of test
# ARGV3 - libraries to add (optional) # bool - boolean variable telling whether the test should be run (optional)
# libs - lib or libs that should be used when compiling test (optional)
# labels - additional labels this test should get (optional)
# #
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
function(add_unit_test TGROUP TNAME) function(add_unit_test _tgroup _tname)
set(ALL_TESTS "${ALL_TESTS};${TGROUP}/${TNAME}" PARENT_SCOPE) set(_testid "${_tgroup}_${_tname}")
if((${ARGC} EQUAL 2) OR (${ARGV2})) set(_tpath "${_tgroup}/${_tname}")
set(ALL_TESTS "${ALL_TESTS};${_tpath}" PARENT_SCOPE)
cmake_parse_arguments(_param "" "ENABLE_IF" "LIBS;LABELS" ${ARGN})
if(Osmium_DEBUG)
message("${_testid} ENABLE_IF=[${_param_ENABLE_IF}] LIBS=[${_param_LIBS}] LABELS=[${_param_LABELS}]")
endif()
if((NOT(DEFINED _param_ENABLE_IF)) OR (_param_ENABLE_IF))
if(Osmium_DEBUG) if(Osmium_DEBUG)
message("Adding test ${TGROUP}/${TNAME}") message("Adding test: ${_tpath}")
endif() endif()
set(TESTNAME "${TGROUP}_${TNAME}") add_executable(${_testid} t/${_tpath}.cpp)
add_executable(${TESTNAME} t/${TGROUP}/${TNAME}.cpp) target_link_libraries(${_testid} testlib)
target_link_libraries(${TESTNAME} testlib)
if((${ARGV2}) AND (DEFINED ARGV3)) if(DEFINED _param_LIBS)
if(Osmium_DEBUG) if(Osmium_DEBUG)
message(" Adding libs ${ARGV3}") message(" Adding libs: ${_param_LIBS}")
endif() endif()
target_link_libraries(${TESTNAME} ${ARGV3}) target_link_libraries(${_testid} ${_param_LIBS})
endif() endif()
add_test(NAME ${TESTNAME}
add_test(NAME ${_testid}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${TESTNAME} COMMAND ${_testid}
) )
set_tests_properties(${TESTNAME} PROPERTIES
LABELS "unit;fast;${TGROUP}" set(_labels "unit;fast;${_tgroup}")
if(DEFINED _param_LABELS)
if(Osmium_DEBUG)
message(" Adding labels: ${_param_LABELS}")
endif()
set(_labels "${_labels};${_param_LABELS}")
endif()
set_tests_properties(${_testid} PROPERTIES
LABELS "${_labels}"
ENVIRONMENT "OSMIUM_TEST_DATA_DIR=${CMAKE_CURRENT_SOURCE_DIR}" ENVIRONMENT "OSMIUM_TEST_DATA_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
) )
else() else()
message("Skipped test ${TGROUP}/${TNAME} because a dependency was not found") message("Skipped test ${_tpath} because a dependency was not found")
set(OSMIUM_SKIPPED_TESTS set(OSMIUM_SKIPPED_TESTS
"${OSMIUM_SKIPPED_TESTS} ${TGROUP}/${TNAME}" "${OSMIUM_SKIPPED_TESTS} ${_tpath}"
CACHE STRING "Tests that were skipped because of missing dependecies") CACHE STRING "Tests that were skipped because of missing dependecies")
endif() endif()
endfunction() endfunction()
@ -85,31 +108,32 @@ else()
set(GEOS_AND_PROJ_FOUND FALSE) set(GEOS_AND_PROJ_FOUND FALSE)
endif() endif()
add_unit_test(geom test_factory_with_projection add_unit_test(geom test_factory_with_projection
${GEOS_AND_PROJ_FOUND} ENABLE_IF ${GEOS_AND_PROJ_FOUND}
"${GEOS_LIBRARY};${PROJ_LIBRARY}") LIBS ${GEOS_LIBRARY} ${PROJ_LIBRARY})
add_unit_test(geom test_geojson) add_unit_test(geom test_geojson)
add_unit_test(geom test_geos ${GEOS_FOUND} ${GEOS_LIBRARY}) add_unit_test(geom test_geos ENABLE_IF ${GEOS_FOUND} LIBS ${GEOS_LIBRARY})
add_unit_test(geom test_geos_wkb ${GEOS_FOUND} ${GEOS_LIBRARY}) add_unit_test(geom test_geos_wkb ENABLE_IF ${GEOS_FOUND} LIBS ${GEOS_LIBRARY})
add_unit_test(geom test_mercator) add_unit_test(geom test_mercator)
add_unit_test(geom test_ogr ${GDAL_FOUND} ${GDAL_LIBRARY}) add_unit_test(geom test_ogr ENABLE_IF ${GDAL_FOUND} LIBS ${GDAL_LIBRARY})
add_unit_test(geom test_projection ${PROJ_FOUND} ${PROJ_LIBRARY}) add_unit_test(geom test_projection ENABLE_IF ${PROJ_FOUND} LIBS ${PROJ_LIBRARY})
add_unit_test(geom test_wkb) add_unit_test(geom test_wkb)
add_unit_test(geom test_wkt) add_unit_test(geom test_wkt)
add_unit_test(index test_id_to_location ${SPARSEHASH_FOUND}) add_unit_test(index test_id_to_location ENABLE_IF ${SPARSEHASH_FOUND})
add_unit_test(index test_typed_mmap) add_unit_test(index test_typed_mmap)
add_unit_test(index test_typed_mmap_grow LABELS "fails_on_windows")
add_unit_test(io test_bzip2 ${BZIP2_FOUND} ${BZIP2_LIBRARIES}) add_unit_test(io test_bzip2 ENABLE_IF ${BZIP2_FOUND} LIBS ${BZIP2_LIBRARIES})
add_unit_test(io test_file_formats) add_unit_test(io test_file_formats)
add_unit_test(io test_reader TRUE "${OSMIUM_XML_LIBRARIES}") add_unit_test(io test_reader LIBS "${OSMIUM_XML_LIBRARIES}")
add_unit_test(io test_output_iterator ${Threads_FOUND} ${CMAKE_THREAD_LIBS_INIT}) add_unit_test(io test_output_iterator ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT})
add_unit_test(tags test_filter) add_unit_test(tags test_filter)
add_unit_test(tags test_operators) add_unit_test(tags test_operators)
add_unit_test(tags test_tag_list) add_unit_test(tags test_tag_list)
add_unit_test(thread test_pool ${Threads_FOUND} ${CMAKE_THREAD_LIBS_INIT}) add_unit_test(thread test_pool ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT})
add_unit_test(util test_cast_with_assert) add_unit_test(util test_cast_with_assert)
add_unit_test(util test_double) add_unit_test(util test_double)

View File

@ -285,7 +285,6 @@ TEST_CASE("Reading OSM XML 121") {
}, osmium::gzip_error); }, osmium::gzip_error);
} }
#if 0
SECTION("Using Reader") { SECTION("Using Reader") {
REQUIRE_THROWS_AS({ REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("121-truncated_gzip_file", "osm.gz")); osmium::io::Reader reader(filename("121-truncated_gzip_file", "osm.gz"));
@ -294,10 +293,105 @@ TEST_CASE("Reading OSM XML 121") {
reader.close(); reader.close();
}, osmium::gzip_error); }, osmium::gzip_error);
} }
#endif
} }
// =============================================
TEST_CASE("Reading OSM XML 122") {
SECTION("Direct") {
REQUIRE_THROWS_AS( {
read_xml("122-no_osm_element");
}, osmium::xml_error);
}
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("122-no_osm_element"));
osmium::io::Header header = reader.header();
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::xml_error);
}
}
// =============================================
TEST_CASE("Reading OSM XML 140") {
SECTION("Using Reader") {
osmium::io::Reader reader(filename("140-unicode"));
osmium::memory::Buffer buffer = reader.read();
reader.close();
int count = 0;
for (auto it = buffer.begin<osmium::Node>(); it != buffer.end<osmium::Node>(); ++it) {
++count;
REQUIRE(it->id() == count);
const osmium::TagList& t = it->tags();
const char* uc = t["unicode_char"];
auto len = atoi(t["unicode_utf8_length"]);
REQUIRE(len == strlen(uc));
REQUIRE(!strcmp(uc, t["unicode_xml"]));
// workaround for missing support for u8 string literals on Windows
#if !defined(_MSC_VER)
switch (count) {
case 1:
REQUIRE(!strcmp(uc, u8"a"));
break;
case 2:
REQUIRE(!strcmp(uc, u8"\u00e4"));
break;
case 3:
REQUIRE(!strcmp(uc, u8"\u30dc"));
break;
case 4:
REQUIRE(!strcmp(uc, u8"\U0001d11e"));
break;
case 5:
REQUIRE(!strcmp(uc, u8"\U0001f6eb"));
break;
default:
REQUIRE(false); // should not be here
}
#endif
}
REQUIRE(count == 5);
}
}
// =============================================
TEST_CASE("Reading OSM XML 141") {
SECTION("Using Reader") {
osmium::io::Reader reader(filename("141-entities"));
osmium::memory::Buffer buffer = reader.read();
reader.close();
REQUIRE(buffer.committed() > 0);
REQUIRE(buffer.get<osmium::memory::Item>(0).type() == osmium::item_type::node);
const osmium::Node& node = buffer.get<osmium::Node>(0);
const osmium::TagList& tags = node.tags();
REQUIRE(!strcmp(tags["less-than"], "<"));
REQUIRE(!strcmp(tags["greater-than"], ">"));
REQUIRE(!strcmp(tags["apostrophe"], "'"));
REQUIRE(!strcmp(tags["ampersand"], "&"));
REQUIRE(!strcmp(tags["quote"], "\""));
}
}
// ============================================= // =============================================
TEST_CASE("Reading OSM XML 200") { TEST_CASE("Reading OSM XML 200") {

View File

@ -4,22 +4,22 @@
TEST_CASE("area_id") { TEST_CASE("area_id") {
SECTION("object_id_to_area_id_conversion") { SECTION("object_id_to_area_id_conversion") {
REQUIRE( 46 == osmium::object_id_to_area_id( 23, osmium::item_type::way)); REQUIRE( 46 == osmium::object_id_to_area_id( 23, osmium::item_type::way));
REQUIRE( 47 == osmium::object_id_to_area_id( 23, osmium::item_type::relation)); REQUIRE( 47 == osmium::object_id_to_area_id( 23, osmium::item_type::relation));
REQUIRE( 0 == osmium::object_id_to_area_id( 0, osmium::item_type::way)); REQUIRE( 0 == osmium::object_id_to_area_id( 0, osmium::item_type::way));
REQUIRE( 1 == osmium::object_id_to_area_id( 0, osmium::item_type::relation)); REQUIRE( 1 == osmium::object_id_to_area_id( 0, osmium::item_type::relation));
REQUIRE(-24 == osmium::object_id_to_area_id(-12, osmium::item_type::way)); REQUIRE(-24 == osmium::object_id_to_area_id(-12, osmium::item_type::way));
REQUIRE(-25 == osmium::object_id_to_area_id(-12, osmium::item_type::relation)); REQUIRE(-25 == osmium::object_id_to_area_id(-12, osmium::item_type::relation));
} }
SECTION("area_id_to_object_id_conversion") { SECTION("area_id_to_object_id_conversion") {
REQUIRE( 23 == osmium::area_id_to_object_id( 46)); REQUIRE( 23 == osmium::area_id_to_object_id( 46));
REQUIRE( 23 == osmium::area_id_to_object_id( 47)); REQUIRE( 23 == osmium::area_id_to_object_id( 47));
REQUIRE( 0 == osmium::area_id_to_object_id( 0)); REQUIRE( 0 == osmium::area_id_to_object_id( 0));
REQUIRE( 0 == osmium::area_id_to_object_id( 1)); REQUIRE( 0 == osmium::area_id_to_object_id( 1));
REQUIRE(-12 == osmium::area_id_to_object_id(-24)); REQUIRE(-12 == osmium::area_id_to_object_id(-24));
REQUIRE(-12 == osmium::area_id_to_object_id(-25)); REQUIRE(-12 == osmium::area_id_to_object_id(-25));
} }
} }

View File

@ -6,110 +6,110 @@ using osmium::area::detail::NodeRefSegment;
TEST_CASE("NodeRefSegmentClass") { TEST_CASE("NodeRefSegmentClass") {
SECTION("instantiation_with_default_parameters") { SECTION("instantiation_with_default_parameters") {
NodeRefSegment s; NodeRefSegment s;
REQUIRE(s.first().ref() == 0); REQUIRE(s.first().ref() == 0);
REQUIRE(s.first().location() == osmium::Location()); REQUIRE(s.first().location() == osmium::Location());
REQUIRE(s.second().ref() == 0); REQUIRE(s.second().ref() == 0);
REQUIRE(s.second().location() == osmium::Location()); REQUIRE(s.second().location() == osmium::Location());
} }
SECTION("instantiation") { SECTION("instantiation") {
osmium::NodeRef nr1(1, { 1.2, 3.4 }); osmium::NodeRef nr1(1, { 1.2, 3.4 });
osmium::NodeRef nr2(2, { 1.4, 3.1 }); osmium::NodeRef nr2(2, { 1.4, 3.1 });
osmium::NodeRef nr3(3, { 1.2, 3.6 }); osmium::NodeRef nr3(3, { 1.2, 3.6 });
osmium::NodeRef nr4(4, { 1.2, 3.7 }); osmium::NodeRef nr4(4, { 1.2, 3.7 });
NodeRefSegment s1(nr1, nr2, nullptr, nullptr); NodeRefSegment s1(nr1, nr2, nullptr, nullptr);
REQUIRE(s1.first().ref() == 1); REQUIRE(s1.first().ref() == 1);
REQUIRE(s1.second().ref() == 2); REQUIRE(s1.second().ref() == 2);
NodeRefSegment s2(nr2, nr3, nullptr, nullptr); NodeRefSegment s2(nr2, nr3, nullptr, nullptr);
REQUIRE(s2.first().ref() == 3); REQUIRE(s2.first().ref() == 3);
REQUIRE(s2.second().ref() == 2); REQUIRE(s2.second().ref() == 2);
NodeRefSegment s3(nr3, nr4, nullptr, nullptr); NodeRefSegment s3(nr3, nr4, nullptr, nullptr);
REQUIRE(s3.first().ref() == 3); REQUIRE(s3.first().ref() == 3);
REQUIRE(s3.second().ref() == 4); REQUIRE(s3.second().ref() == 4);
} }
SECTION("intersection") { SECTION("intersection") {
NodeRefSegment s1({ 1, {0.0, 0.0}}, { 2, {2.0, 2.0}}, nullptr, nullptr); NodeRefSegment s1({ 1, {0.0, 0.0}}, { 2, {2.0, 2.0}}, nullptr, nullptr);
NodeRefSegment s2({ 3, {0.0, 2.0}}, { 4, {2.0, 0.0}}, nullptr, nullptr); NodeRefSegment s2({ 3, {0.0, 2.0}}, { 4, {2.0, 0.0}}, nullptr, nullptr);
NodeRefSegment s3({ 5, {2.0, 0.0}}, { 6, {4.0, 2.0}}, nullptr, nullptr); NodeRefSegment s3({ 5, {2.0, 0.0}}, { 6, {4.0, 2.0}}, nullptr, nullptr);
NodeRefSegment s4({ 7, {1.0, 0.0}}, { 8, {3.0, 2.0}}, nullptr, nullptr); NodeRefSegment s4({ 7, {1.0, 0.0}}, { 8, {3.0, 2.0}}, nullptr, nullptr);
NodeRefSegment s5({ 9, {0.0, 4.0}}, {10, {4.0, 0.0}}, nullptr, nullptr); NodeRefSegment s5({ 9, {0.0, 4.0}}, {10, {4.0, 0.0}}, nullptr, nullptr);
NodeRefSegment s6({11, {0.0, 0.0}}, {12, {1.0, 1.0}}, nullptr, nullptr); NodeRefSegment s6({11, {0.0, 0.0}}, {12, {1.0, 1.0}}, nullptr, nullptr);
NodeRefSegment s7({13, {1.0, 1.0}}, {14, {3.0, 3.0}}, nullptr, nullptr); NodeRefSegment s7({13, {1.0, 1.0}}, {14, {3.0, 3.0}}, nullptr, nullptr);
REQUIRE(calculate_intersection(s1, s2) == osmium::Location(1.0, 1.0)); REQUIRE(calculate_intersection(s1, s2) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s1, s3) == osmium::Location()); REQUIRE(calculate_intersection(s1, s3) == osmium::Location());
REQUIRE(calculate_intersection(s2, s3) == osmium::Location()); REQUIRE(calculate_intersection(s2, s3) == osmium::Location());
REQUIRE(calculate_intersection(s1, s4) == osmium::Location()); REQUIRE(calculate_intersection(s1, s4) == osmium::Location());
REQUIRE(calculate_intersection(s1, s5) == osmium::Location(2.0, 2.0)); REQUIRE(calculate_intersection(s1, s5) == osmium::Location(2.0, 2.0));
REQUIRE(calculate_intersection(s1, s1) == osmium::Location()); REQUIRE(calculate_intersection(s1, s1) == osmium::Location());
REQUIRE(calculate_intersection(s1, s6) == osmium::Location()); REQUIRE(calculate_intersection(s1, s6) == osmium::Location());
REQUIRE(calculate_intersection(s1, s7) == osmium::Location()); REQUIRE(calculate_intersection(s1, s7) == osmium::Location());
} }
SECTION("to_left_of") { SECTION("to_left_of") {
osmium::Location loc { 2.0, 2.0 }; osmium::Location loc { 2.0, 2.0 };
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {4.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {4.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 3.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 3.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 1.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 1.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 3.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 3.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 2.0}}, nullptr, nullptr).to_left_of(loc)); REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 2.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {0.0, 1.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {0.0, 1.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {4.0, 0.0}}, nullptr, nullptr).to_left_of(loc) == false); REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {4.0, 0.0}}, nullptr, nullptr).to_left_of(loc) == false);
} }
SECTION("ordering") { SECTION("ordering") {
osmium::NodeRef node_ref1(1, { 1.0, 3.0 }); osmium::NodeRef node_ref1(1, { 1.0, 3.0 });
osmium::NodeRef node_ref2(2, { 1.4, 2.9 }); osmium::NodeRef node_ref2(2, { 1.4, 2.9 });
osmium::NodeRef node_ref3(3, { 1.2, 3.0 }); osmium::NodeRef node_ref3(3, { 1.2, 3.0 });
osmium::NodeRef node_ref4(4, { 1.2, 3.3 }); osmium::NodeRef node_ref4(4, { 1.2, 3.3 });
REQUIRE(node_ref1 < node_ref2); REQUIRE(node_ref1 < node_ref2);
REQUIRE(node_ref2 < node_ref3); REQUIRE(node_ref2 < node_ref3);
REQUIRE(node_ref1 < node_ref3); REQUIRE(node_ref1 < node_ref3);
REQUIRE(node_ref1 >= node_ref1); REQUIRE(node_ref1 >= node_ref1);
REQUIRE( osmium::location_less()(node_ref1, node_ref2)); REQUIRE( osmium::location_less()(node_ref1, node_ref2));
REQUIRE(!osmium::location_less()(node_ref2, node_ref3)); REQUIRE(!osmium::location_less()(node_ref2, node_ref3));
REQUIRE( osmium::location_less()(node_ref1, node_ref3)); REQUIRE( osmium::location_less()(node_ref1, node_ref3));
REQUIRE( osmium::location_less()(node_ref3, node_ref4)); REQUIRE( osmium::location_less()(node_ref3, node_ref4));
REQUIRE(!osmium::location_less()(node_ref1, node_ref1)); REQUIRE(!osmium::location_less()(node_ref1, node_ref1));
} }
} }

View File

@ -7,75 +7,85 @@
TEST_CASE("Box") { TEST_CASE("Box") {
SECTION("instantiation") { SECTION("instantiation") {
osmium::Box b; osmium::Box b;
REQUIRE(!b); REQUIRE(!b);
REQUIRE(!b.bottom_left()); REQUIRE(!b.bottom_left());
REQUIRE(!b.top_right()); REQUIRE(!b.top_right());
REQUIRE_THROWS_AS(b.size(), osmium::invalid_location); REQUIRE_THROWS_AS(b.size(), osmium::invalid_location);
} }
SECTION("instantiation_and_extend_with_undefined") { SECTION("instantiation_and_extend_with_undefined") {
osmium::Box b; osmium::Box b;
REQUIRE(!b); REQUIRE(!b);
b.extend(osmium::Location()); b.extend(osmium::Location());
REQUIRE(!b.bottom_left()); REQUIRE(!b.bottom_left());
REQUIRE(!b.top_right()); REQUIRE(!b.top_right());
} }
SECTION("instantiation_and_extend") { SECTION("instantiation_and_extend") {
osmium::Box b; osmium::Box b;
b.extend(osmium::Location(1.2, 3.4)); osmium::Location loc1 { 1.2, 3.4 };
REQUIRE(!!b); b.extend(loc1);
REQUIRE(!!b.bottom_left()); REQUIRE(!!b);
REQUIRE(!!b.top_right()); REQUIRE(!!b.bottom_left());
b.extend(osmium::Location(3.4, 4.5)); REQUIRE(!!b.top_right());
b.extend(osmium::Location(5.6, 7.8)); REQUIRE(b.contains(loc1));
REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4));
REQUIRE(b.top_right() == osmium::Location(5.6, 7.8));
// extend with undefined doesn't change anything osmium::Location loc2 { 3.4, 4.5 };
b.extend(osmium::Location()); osmium::Location loc3 { 5.6, 7.8 };
REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4));
REQUIRE(b.top_right() == osmium::Location(5.6, 7.8));
}
SECTION("output_defined") { b.extend(loc2);
osmium::Box b; b.extend(loc3);
b.extend(osmium::Location(1.2, 3.4)); REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4));
b.extend(osmium::Location(5.6, 7.8)); REQUIRE(b.top_right() == osmium::Location(5.6, 7.8));
std::stringstream out;
out << b;
REQUIRE(out.str() == "(1.2,3.4,5.6,7.8)");
REQUIRE(b.size() == Approx(19.36).epsilon(0.000001));
}
SECTION("output_undefined") { // extend with undefined doesn't change anything
osmium::Box b; b.extend(osmium::Location());
std::stringstream out; REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4));
out << b; REQUIRE(b.top_right() == osmium::Location(5.6, 7.8));
REQUIRE(out.str() == "(undefined)");
}
SECTION("box_inside_box") { REQUIRE(b.contains(loc1));
osmium::Box outer; REQUIRE(b.contains(loc2));
outer.extend(osmium::Location(1, 1)); REQUIRE(b.contains(loc3));
outer.extend(osmium::Location(10, 10)); }
osmium::Box inner; SECTION("output_defined") {
inner.extend(osmium::Location(2, 2)); osmium::Box b;
inner.extend(osmium::Location(4, 4)); b.extend(osmium::Location(1.2, 3.4));
b.extend(osmium::Location(5.6, 7.8));
std::stringstream out;
out << b;
REQUIRE(out.str() == "(1.2,3.4,5.6,7.8)");
REQUIRE(b.size() == Approx(19.36).epsilon(0.000001));
}
osmium::Box overlap; SECTION("output_undefined") {
overlap.extend(osmium::Location(3, 3)); osmium::Box b;
overlap.extend(osmium::Location(5, 5)); std::stringstream out;
out << b;
REQUIRE(out.str() == "(undefined)");
}
REQUIRE( osmium::geom::contains(inner, outer)); SECTION("box_inside_box") {
REQUIRE(!osmium::geom::contains(outer, inner)); osmium::Box outer;
outer.extend(osmium::Location(1, 1));
outer.extend(osmium::Location(10, 10));
REQUIRE(!osmium::geom::contains(overlap, inner)); osmium::Box inner;
REQUIRE(!osmium::geom::contains(inner, overlap)); inner.extend(osmium::Location(2, 2));
} inner.extend(osmium::Location(4, 4));
osmium::Box overlap;
overlap.extend(osmium::Location(3, 3));
overlap.extend(osmium::Location(5, 5));
REQUIRE( osmium::geom::contains(inner, outer));
REQUIRE(!osmium::geom::contains(outer, inner));
REQUIRE(!osmium::geom::contains(overlap, inner));
REQUIRE(!osmium::geom::contains(inner, overlap));
}
} }

View File

@ -4,28 +4,28 @@
TEST_CASE("entity_bits") { TEST_CASE("entity_bits") {
SECTION("can_be_set_and_checked") { SECTION("can_be_set_and_checked") {
osmium::osm_entity_bits::type entities = osmium::osm_entity_bits::node | osmium::osm_entity_bits::way; osmium::osm_entity_bits::type entities = osmium::osm_entity_bits::node | osmium::osm_entity_bits::way;
REQUIRE(entities == (osmium::osm_entity_bits::node | osmium::osm_entity_bits::way)); REQUIRE(entities == (osmium::osm_entity_bits::node | osmium::osm_entity_bits::way));
entities |= osmium::osm_entity_bits::relation; entities |= osmium::osm_entity_bits::relation;
REQUIRE((entities & osmium::osm_entity_bits::object)); REQUIRE((entities & osmium::osm_entity_bits::object));
entities |= osmium::osm_entity_bits::area; entities |= osmium::osm_entity_bits::area;
REQUIRE(entities == osmium::osm_entity_bits::object); REQUIRE(entities == osmium::osm_entity_bits::object);
REQUIRE(! (entities & osmium::osm_entity_bits::changeset)); REQUIRE(! (entities & osmium::osm_entity_bits::changeset));
entities &= osmium::osm_entity_bits::node; entities &= osmium::osm_entity_bits::node;
REQUIRE((entities & osmium::osm_entity_bits::node)); REQUIRE((entities & osmium::osm_entity_bits::node));
REQUIRE(! (entities & osmium::osm_entity_bits::way)); REQUIRE(! (entities & osmium::osm_entity_bits::way));
REQUIRE(entities == osmium::osm_entity_bits::node); REQUIRE(entities == osmium::osm_entity_bits::node);
REQUIRE(osmium::osm_entity_bits::node == osmium::osm_entity_bits::from_item_type(osmium::item_type::node)); REQUIRE(osmium::osm_entity_bits::node == osmium::osm_entity_bits::from_item_type(osmium::item_type::node));
REQUIRE(osmium::osm_entity_bits::way == osmium::osm_entity_bits::from_item_type(osmium::item_type::way)); REQUIRE(osmium::osm_entity_bits::way == osmium::osm_entity_bits::from_item_type(osmium::item_type::way));
REQUIRE(osmium::osm_entity_bits::relation == osmium::osm_entity_bits::from_item_type(osmium::item_type::relation)); REQUIRE(osmium::osm_entity_bits::relation == osmium::osm_entity_bits::from_item_type(osmium::item_type::relation));
REQUIRE(osmium::osm_entity_bits::changeset == osmium::osm_entity_bits::from_item_type(osmium::item_type::changeset)); REQUIRE(osmium::osm_entity_bits::changeset == osmium::osm_entity_bits::from_item_type(osmium::item_type::changeset));
REQUIRE(osmium::osm_entity_bits::area == osmium::osm_entity_bits::from_item_type(osmium::item_type::area)); REQUIRE(osmium::osm_entity_bits::area == osmium::osm_entity_bits::from_item_type(osmium::item_type::area));
} }
} }

View File

@ -10,145 +10,145 @@ TEST_CASE("Location") {
// fails on MSVC and doesn't really matter // fails on MSVC and doesn't really matter
// static_assert(std::is_literal_type<osmium::Location>::value, "osmium::Location not literal type"); // static_assert(std::is_literal_type<osmium::Location>::value, "osmium::Location not literal type");
SECTION("instantiation_with_default_parameters") { SECTION("instantiation_with_default_parameters") {
osmium::Location loc; osmium::Location loc;
REQUIRE(!loc); REQUIRE(!loc);
REQUIRE_THROWS_AS(loc.lon(), osmium::invalid_location); REQUIRE_THROWS_AS(loc.lon(), osmium::invalid_location);
REQUIRE_THROWS_AS(loc.lat(), osmium::invalid_location); REQUIRE_THROWS_AS(loc.lat(), osmium::invalid_location);
} }
SECTION("instantiation_with_double_parameters") { SECTION("instantiation_with_double_parameters") {
osmium::Location loc1(1.2, 4.5); osmium::Location loc1(1.2, 4.5);
REQUIRE(!!loc1); REQUIRE(!!loc1);
REQUIRE(12000000 == loc1.x()); REQUIRE(12000000 == loc1.x());
REQUIRE(45000000 == loc1.y()); REQUIRE(45000000 == loc1.y());
REQUIRE(1.2 == loc1.lon()); REQUIRE(1.2 == loc1.lon());
REQUIRE(4.5 == loc1.lat()); REQUIRE(4.5 == loc1.lat());
osmium::Location loc2(loc1); osmium::Location loc2(loc1);
REQUIRE(4.5 == loc2.lat()); REQUIRE(4.5 == loc2.lat());
osmium::Location loc3 = loc1; osmium::Location loc3 = loc1;
REQUIRE(4.5 == loc3.lat()); REQUIRE(4.5 == loc3.lat());
} }
SECTION("instantiation_with_double_parameters_constructor_with_universal_initializer") { SECTION("instantiation_with_double_parameters_constructor_with_universal_initializer") {
osmium::Location loc { 2.2, 3.3 }; osmium::Location loc { 2.2, 3.3 };
REQUIRE(2.2 == loc.lon()); REQUIRE(2.2 == loc.lon());
REQUIRE(3.3 == loc.lat()); REQUIRE(3.3 == loc.lat());
} }
SECTION("instantiation_with_double_parameters_constructor_with_initializer_list") { SECTION("instantiation_with_double_parameters_constructor_with_initializer_list") {
osmium::Location loc({ 4.4, 5.5 }); osmium::Location loc({ 4.4, 5.5 });
REQUIRE(4.4 == loc.lon()); REQUIRE(4.4 == loc.lon());
REQUIRE(5.5 == loc.lat()); REQUIRE(5.5 == loc.lat());
} }
SECTION("instantiation_with_double_parameters_operator_equal") { SECTION("instantiation_with_double_parameters_operator_equal") {
osmium::Location loc = { 5.5, 6.6 }; osmium::Location loc = { 5.5, 6.6 };
REQUIRE(5.5 == loc.lon()); REQUIRE(5.5 == loc.lon());
REQUIRE(6.6 == loc.lat()); REQUIRE(6.6 == loc.lat());
} }
SECTION("equality") { SECTION("equality") {
osmium::Location loc1(1.2, 4.5); osmium::Location loc1(1.2, 4.5);
osmium::Location loc2(1.2, 4.5); osmium::Location loc2(1.2, 4.5);
osmium::Location loc3(1.5, 1.5); osmium::Location loc3(1.5, 1.5);
REQUIRE(loc1 == loc2); REQUIRE(loc1 == loc2);
REQUIRE(loc1 != loc3); REQUIRE(loc1 != loc3);
} }
SECTION("order") { SECTION("order") {
REQUIRE(osmium::Location(-1.2, 10.0) < osmium::Location(1.2, 10.0)); REQUIRE(osmium::Location(-1.2, 10.0) < osmium::Location(1.2, 10.0));
REQUIRE(osmium::Location(1.2, 10.0) > osmium::Location(-1.2, 10.0)); REQUIRE(osmium::Location(1.2, 10.0) > osmium::Location(-1.2, 10.0));
REQUIRE(osmium::Location(10.2, 20.0) < osmium::Location(11.2, 20.2)); REQUIRE(osmium::Location(10.2, 20.0) < osmium::Location(11.2, 20.2));
REQUIRE(osmium::Location(10.2, 20.2) < osmium::Location(11.2, 20.0)); REQUIRE(osmium::Location(10.2, 20.2) < osmium::Location(11.2, 20.0));
REQUIRE(osmium::Location(11.2, 20.2) > osmium::Location(10.2, 20.0)); REQUIRE(osmium::Location(11.2, 20.2) > osmium::Location(10.2, 20.0));
} }
SECTION("validity") { SECTION("validity") {
REQUIRE(osmium::Location(0.0, 0.0).valid()); REQUIRE(osmium::Location(0.0, 0.0).valid());
REQUIRE(osmium::Location(1.2, 4.5).valid()); REQUIRE(osmium::Location(1.2, 4.5).valid());
REQUIRE(osmium::Location(-1.2, 4.5).valid()); REQUIRE(osmium::Location(-1.2, 4.5).valid());
REQUIRE(osmium::Location(-180.0, -90.0).valid()); REQUIRE(osmium::Location(-180.0, -90.0).valid());
REQUIRE(osmium::Location(180.0, -90.0).valid()); REQUIRE(osmium::Location(180.0, -90.0).valid());
REQUIRE(osmium::Location(-180.0, 90.0).valid()); REQUIRE(osmium::Location(-180.0, 90.0).valid());
REQUIRE(osmium::Location(180.0, 90.0).valid()); REQUIRE(osmium::Location(180.0, 90.0).valid());
REQUIRE(!osmium::Location(200.0, 4.5).valid()); REQUIRE(!osmium::Location(200.0, 4.5).valid());
REQUIRE(!osmium::Location(-1.2, -100.0).valid()); REQUIRE(!osmium::Location(-1.2, -100.0).valid());
REQUIRE(!osmium::Location(-180.0, 90.005).valid()); REQUIRE(!osmium::Location(-180.0, 90.005).valid());
} }
SECTION("output_to_iterator_comma_separator") { SECTION("output_to_iterator_comma_separator") {
char buffer[100]; char buffer[100];
osmium::Location loc(-3.2, 47.3); osmium::Location loc(-3.2, 47.3);
*loc.as_string(buffer, ',') = 0; *loc.as_string(buffer, ',') = 0;
REQUIRE(std::string("-3.2,47.3") == buffer); REQUIRE(std::string("-3.2,47.3") == buffer);
} }
SECTION("output_to_iterator_space_separator") { SECTION("output_to_iterator_space_separator") {
char buffer[100]; char buffer[100];
osmium::Location loc(0.0, 7.0); osmium::Location loc(0.0, 7.0);
*loc.as_string(buffer, ' ') = 0; *loc.as_string(buffer, ' ') = 0;
REQUIRE(std::string("0 7") == buffer); REQUIRE(std::string("0 7") == buffer);
} }
SECTION("output_to_iterator_check_precision") { SECTION("output_to_iterator_check_precision") {
char buffer[100]; char buffer[100];
osmium::Location loc(-179.9999999, -90.0); osmium::Location loc(-179.9999999, -90.0);
*loc.as_string(buffer, ' ') = 0; *loc.as_string(buffer, ' ') = 0;
REQUIRE(std::string("-179.9999999 -90") == buffer); REQUIRE(std::string("-179.9999999 -90") == buffer);
} }
SECTION("output_to_iterator_undefined_location") { SECTION("output_to_iterator_undefined_location") {
char buffer[100]; char buffer[100];
osmium::Location loc; osmium::Location loc;
REQUIRE_THROWS_AS(loc.as_string(buffer, ','), osmium::invalid_location); REQUIRE_THROWS_AS(loc.as_string(buffer, ','), osmium::invalid_location);
} }
SECTION("output_to_string_comman_separator") { SECTION("output_to_string_comman_separator") {
std::string s; std::string s;
osmium::Location loc(-3.2, 47.3); osmium::Location loc(-3.2, 47.3);
loc.as_string(std::back_inserter(s), ','); loc.as_string(std::back_inserter(s), ',');
REQUIRE(s == "-3.2,47.3"); REQUIRE(s == "-3.2,47.3");
} }
SECTION("output_to_string_space_separator") { SECTION("output_to_string_space_separator") {
std::string s; std::string s;
osmium::Location loc(0.0, 7.0); osmium::Location loc(0.0, 7.0);
loc.as_string(std::back_inserter(s), ' '); loc.as_string(std::back_inserter(s), ' ');
REQUIRE(s == "0 7"); REQUIRE(s == "0 7");
} }
SECTION("output_to_string_check_precision") { SECTION("output_to_string_check_precision") {
std::string s; std::string s;
osmium::Location loc(-179.9999999, -90.0); osmium::Location loc(-179.9999999, -90.0);
loc.as_string(std::back_inserter(s), ' '); loc.as_string(std::back_inserter(s), ' ');
REQUIRE(s == "-179.9999999 -90"); REQUIRE(s == "-179.9999999 -90");
} }
SECTION("output_to_string_undefined_location") { SECTION("output_to_string_undefined_location") {
std::string s; std::string s;
osmium::Location loc; osmium::Location loc;
REQUIRE_THROWS_AS(loc.as_string(std::back_inserter(s), ','), osmium::invalid_location); REQUIRE_THROWS_AS(loc.as_string(std::back_inserter(s), ','), osmium::invalid_location);
} }
SECTION("output_defined") { SECTION("output_defined") {
osmium::Location p(-3.2, 47.3); osmium::Location p(-3.2, 47.3);
std::stringstream out; std::stringstream out;
out << p; out << p;
REQUIRE(out.str() == "(-3.2,47.3)"); REQUIRE(out.str() == "(-3.2,47.3)");
} }
SECTION("output_undefined") { SECTION("output_undefined") {
osmium::Location p; osmium::Location p;
std::stringstream out; std::stringstream out;
out << p; out << p;
REQUIRE(out.str() == "(undefined,undefined)"); REQUIRE(out.str() == "(undefined,undefined)");
} }
} }

View File

@ -4,54 +4,54 @@
TEST_CASE("NodeRef") { TEST_CASE("NodeRef") {
SECTION("instantiation_with_default_parameters") { SECTION("instantiation_with_default_parameters") {
osmium::NodeRef node_ref; osmium::NodeRef node_ref;
REQUIRE(node_ref.ref() == 0); REQUIRE(node_ref.ref() == 0);
// REQUIRE(!node_ref.has_location()); // REQUIRE(!node_ref.has_location());
} }
SECTION("instantiation_with_id") { SECTION("instantiation_with_id") {
osmium::NodeRef node_ref(7); osmium::NodeRef node_ref(7);
REQUIRE(node_ref.ref() == 7); REQUIRE(node_ref.ref() == 7);
} }
SECTION("equality") { SECTION("equality") {
osmium::NodeRef node_ref1(7, { 1.2, 3.4 }); osmium::NodeRef node_ref1(7, { 1.2, 3.4 });
osmium::NodeRef node_ref2(7, { 1.4, 3.1 }); osmium::NodeRef node_ref2(7, { 1.4, 3.1 });
osmium::NodeRef node_ref3(9, { 1.2, 3.4 }); osmium::NodeRef node_ref3(9, { 1.2, 3.4 });
REQUIRE(node_ref1 == node_ref2); REQUIRE(node_ref1 == node_ref2);
REQUIRE(node_ref1 != node_ref3); REQUIRE(node_ref1 != node_ref3);
REQUIRE(!osmium::location_equal()(node_ref1, node_ref2)); REQUIRE(!osmium::location_equal()(node_ref1, node_ref2));
REQUIRE(!osmium::location_equal()(node_ref2, node_ref3)); REQUIRE(!osmium::location_equal()(node_ref2, node_ref3));
REQUIRE(osmium::location_equal()(node_ref1, node_ref3)); REQUIRE(osmium::location_equal()(node_ref1, node_ref3));
} }
SECTION("set_location") { SECTION("set_location") {
osmium::NodeRef node_ref(7); osmium::NodeRef node_ref(7);
REQUIRE(!node_ref.location().valid()); REQUIRE(!node_ref.location().valid());
REQUIRE(node_ref.location() == osmium::Location()); REQUIRE(node_ref.location() == osmium::Location());
node_ref.set_location(osmium::Location(13.5, -7.2)); node_ref.set_location(osmium::Location(13.5, -7.2));
REQUIRE(node_ref.location().lon() == 13.5); REQUIRE(node_ref.location().lon() == 13.5);
REQUIRE(node_ref.location().valid()); REQUIRE(node_ref.location().valid());
} }
SECTION("ordering") { SECTION("ordering") {
osmium::NodeRef node_ref1(1, { 1.0, 3.0 }); osmium::NodeRef node_ref1(1, { 1.0, 3.0 });
osmium::NodeRef node_ref2(2, { 1.4, 2.9 }); osmium::NodeRef node_ref2(2, { 1.4, 2.9 });
osmium::NodeRef node_ref3(3, { 1.2, 3.0 }); osmium::NodeRef node_ref3(3, { 1.2, 3.0 });
osmium::NodeRef node_ref4(4, { 1.2, 3.3 }); osmium::NodeRef node_ref4(4, { 1.2, 3.3 });
REQUIRE(node_ref1 < node_ref2); REQUIRE(node_ref1 < node_ref2);
REQUIRE(node_ref2 < node_ref3); REQUIRE(node_ref2 < node_ref3);
REQUIRE(node_ref1 < node_ref3); REQUIRE(node_ref1 < node_ref3);
REQUIRE(node_ref1 >= node_ref1); REQUIRE(node_ref1 >= node_ref1);
REQUIRE(osmium::location_less()(node_ref1, node_ref2)); REQUIRE(osmium::location_less()(node_ref1, node_ref2));
REQUIRE(!osmium::location_less()(node_ref2, node_ref3)); REQUIRE(!osmium::location_less()(node_ref2, node_ref3));
REQUIRE(osmium::location_less()(node_ref1, node_ref3)); REQUIRE(osmium::location_less()(node_ref1, node_ref3));
REQUIRE(osmium::location_less()(node_ref3, node_ref4)); REQUIRE(osmium::location_less()(node_ref3, node_ref4));
REQUIRE(!osmium::location_less()(node_ref1, node_ref1)); REQUIRE(!osmium::location_less()(node_ref1, node_ref1));
} }
} }

View File

@ -6,142 +6,142 @@
TEST_CASE("Object_Comparisons") { TEST_CASE("Object_Comparisons") {
SECTION("order") { SECTION("order") {
osmium::memory::Buffer buffer(10 * 1000); osmium::memory::Buffer buffer(10 * 1000);
{ {
// add node 1 // add node 1
osmium::builder::NodeBuilder node_builder(buffer); osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser"); node_builder.add_user("testuser");
buffer.commit(); buffer.commit();
}
{
// add node 2
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser");
buffer.commit();
}
auto it = buffer.begin();
osmium::Node& node1 = static_cast<osmium::Node&>(*it);
osmium::Node& node2 = static_cast<osmium::Node&>(*(++it));
node1.set_id(10);
node1.set_version(1);
node2.set_id(15);
node2.set_version(2);
REQUIRE(true == (node1 < node2));
REQUIRE(false == (node1 > node2));
node1.set_id(20);
node1.set_version(1);
node2.set_id(20);
node2.set_version(2);
REQUIRE(true == (node1 < node2));
REQUIRE(false == (node1 > node2));
node1.set_id(-10);
node1.set_version(2);
node2.set_id(-15);
node2.set_version(1);
REQUIRE(true == (node1 < node2));
REQUIRE(false == (node1 > node2));
} }
{ SECTION("order_types") {
// add node 2 osmium::memory::Buffer buffer(10 * 1000);
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser"); {
buffer.commit(); // add node 1
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(3);
node.set_version(3);
node_builder.add_user("testuser");
buffer.commit();
}
{
// add node 2
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(3);
node.set_version(4);
node_builder.add_user("testuser");
buffer.commit();
}
{
// add node 3
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(3);
node.set_version(4);
node_builder.add_user("testuser");
buffer.commit();
}
{
// add way
osmium::builder::WayBuilder way_builder(buffer);
osmium::Way& way = way_builder.object();
REQUIRE(osmium::item_type::way == way.type());
way.set_id(2);
way.set_version(2);
way_builder.add_user("testuser");
buffer.commit();
}
{
// add relation
osmium::builder::RelationBuilder relation_builder(buffer);
osmium::Relation& relation = relation_builder.object();
REQUIRE(osmium::item_type::relation == relation.type());
relation.set_id(1);
relation.set_version(1);
relation_builder.add_user("testuser");
buffer.commit();
}
auto it = buffer.begin();
const osmium::Node& node1 = static_cast<const osmium::Node&>(*it);
const osmium::Node& node2 = static_cast<const osmium::Node&>(*(++it));
const osmium::Node& node3 = static_cast<const osmium::Node&>(*(++it));
const osmium::Way& way = static_cast<const osmium::Way&>(*(++it));
const osmium::Relation& relation = static_cast<const osmium::Relation&>(*(++it));
REQUIRE(true == (node1 < node2));
REQUIRE(true == (node2 < way));
REQUIRE(false == (node2 > way));
REQUIRE(true == (way < relation));
REQUIRE(true == (node1 < relation));
REQUIRE(true == osmium::object_order_type_id_version()(node1, node2));
REQUIRE(true == osmium::object_order_type_id_reverse_version()(node2, node1));
REQUIRE(true == osmium::object_order_type_id_version()(node1, way));
REQUIRE(true == osmium::object_order_type_id_reverse_version()(node1, way));
REQUIRE(false == osmium::object_equal_type_id_version()(node1, node2));
REQUIRE(true == osmium::object_equal_type_id_version()(node2, node3));
REQUIRE(true == osmium::object_equal_type_id()(node1, node2));
REQUIRE(true == osmium::object_equal_type_id()(node2, node3));
REQUIRE(false == osmium::object_equal_type_id_version()(node1, way));
REQUIRE(false == osmium::object_equal_type_id_version()(node1, relation));
REQUIRE(false == osmium::object_equal_type_id()(node1, relation));
} }
auto it = buffer.begin();
osmium::Node& node1 = static_cast<osmium::Node&>(*it);
osmium::Node& node2 = static_cast<osmium::Node&>(*(++it));
node1.set_id(10);
node1.set_version(1);
node2.set_id(15);
node2.set_version(2);
REQUIRE(true == (node1 < node2));
REQUIRE(false == (node1 > node2));
node1.set_id(20);
node1.set_version(1);
node2.set_id(20);
node2.set_version(2);
REQUIRE(true == (node1 < node2));
REQUIRE(false == (node1 > node2));
node1.set_id(-10);
node1.set_version(2);
node2.set_id(-15);
node2.set_version(1);
REQUIRE(true == (node1 < node2));
REQUIRE(false == (node1 > node2));
}
SECTION("order_types") {
osmium::memory::Buffer buffer(10 * 1000);
{
// add node 1
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(3);
node.set_version(3);
node_builder.add_user("testuser");
buffer.commit();
}
{
// add node 2
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(3);
node.set_version(4);
node_builder.add_user("testuser");
buffer.commit();
}
{
// add node 3
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(3);
node.set_version(4);
node_builder.add_user("testuser");
buffer.commit();
}
{
// add way
osmium::builder::WayBuilder way_builder(buffer);
osmium::Way& way = way_builder.object();
REQUIRE(osmium::item_type::way == way.type());
way.set_id(2);
way.set_version(2);
way_builder.add_user("testuser");
buffer.commit();
}
{
// add relation
osmium::builder::RelationBuilder relation_builder(buffer);
osmium::Relation& relation = relation_builder.object();
REQUIRE(osmium::item_type::relation == relation.type());
relation.set_id(1);
relation.set_version(1);
relation_builder.add_user("testuser");
buffer.commit();
}
auto it = buffer.begin();
const osmium::Node& node1 = static_cast<const osmium::Node&>(*it);
const osmium::Node& node2 = static_cast<const osmium::Node&>(*(++it));
const osmium::Node& node3 = static_cast<const osmium::Node&>(*(++it));
const osmium::Way& way = static_cast<const osmium::Way&>(*(++it));
const osmium::Relation& relation = static_cast<const osmium::Relation&>(*(++it));
REQUIRE(true == (node1 < node2));
REQUIRE(true == (node2 < way));
REQUIRE(false == (node2 > way));
REQUIRE(true == (way < relation));
REQUIRE(true == (node1 < relation));
REQUIRE(true == osmium::object_order_type_id_version()(node1, node2));
REQUIRE(true == osmium::object_order_type_id_reverse_version()(node2, node1));
REQUIRE(true == osmium::object_order_type_id_version()(node1, way));
REQUIRE(true == osmium::object_order_type_id_reverse_version()(node1, way));
REQUIRE(false == osmium::object_equal_type_id_version()(node1, node2));
REQUIRE(true == osmium::object_equal_type_id_version()(node2, node3));
REQUIRE(true == osmium::object_equal_type_id()(node1, node2));
REQUIRE(true == osmium::object_equal_type_id()(node2, node3));
REQUIRE(false == osmium::object_equal_type_id_version()(node1, way));
REQUIRE(false == osmium::object_equal_type_id_version()(node1, relation));
REQUIRE(false == osmium::object_equal_type_id()(node1, relation));
}
} }

View File

@ -6,40 +6,53 @@
TEST_CASE("Timestamp") { TEST_CASE("Timestamp") {
SECTION("can be default initialized to invalid value") { SECTION("can be default initialized to invalid value") {
osmium::Timestamp t; osmium::Timestamp t;
REQUIRE(0 == t); REQUIRE(0 == t);
REQUIRE("" == t.to_iso()); REQUIRE("" == t.to_iso());
} }
SECTION("invalid value is zero") { SECTION("invalid value is zero") {
osmium::Timestamp t(static_cast<time_t>(0)); osmium::Timestamp t(static_cast<time_t>(0));
REQUIRE(0 == t); REQUIRE(0 == t);
REQUIRE("" == t.to_iso()); REQUIRE("" == t.to_iso());
} }
SECTION("can be initialized from time_t") { SECTION("can be initialized from time_t") {
osmium::Timestamp t(static_cast<time_t>(1)); osmium::Timestamp t(static_cast<time_t>(1));
REQUIRE(1 == t); REQUIRE(1 == t);
REQUIRE("1970-01-01T00:00:01Z" == t.to_iso()); REQUIRE("1970-01-01T00:00:01Z" == t.to_iso());
} }
SECTION("can be initialized from string") { SECTION("can be initialized from string") {
osmium::Timestamp t("2000-01-01T00:00:00Z"); osmium::Timestamp t("2000-01-01T00:00:00Z");
REQUIRE("2000-01-01T00:00:00Z" == t.to_iso()); REQUIRE("2000-01-01T00:00:00Z" == t.to_iso());
} }
SECTION("can be compared") { SECTION("can be implicitly cast to time_t") {
osmium::Timestamp t1(10); osmium::Timestamp t(4242);
osmium::Timestamp t2(50); time_t x = t;
REQUIRE(t1 < t2); REQUIRE(x == 4242);
} }
SECTION("can be written to stream") { SECTION("uint32_t can be initialized from Timestamp") {
std::stringstream ss; osmium::Timestamp t(4242);
osmium::Timestamp t(1); uint32_t x { t };
ss << t;
REQUIRE("1970-01-01T00:00:01Z" == ss.str()); REQUIRE(x == 4242);
} }
SECTION("can be compared") {
osmium::Timestamp t1(10);
osmium::Timestamp t2(50);
REQUIRE(t1 < t2);
}
SECTION("can be written to stream") {
std::stringstream ss;
osmium::Timestamp t(1);
ss << t;
REQUIRE("1970-01-01T00:00:01Z" == ss.str());
}
} }

View File

@ -58,78 +58,78 @@ void check_node_2(osmium::Node& node) {
TEST_CASE("Buffer_Node") { TEST_CASE("Buffer_Node") {
SECTION("buffer_node") { SECTION("buffer_node") {
constexpr size_t buffer_size = 10000; constexpr size_t buffer_size = 10000;
unsigned char data[buffer_size]; unsigned char data[buffer_size];
osmium::memory::Buffer buffer(data, buffer_size, 0); osmium::memory::Buffer buffer(data, buffer_size, 0);
{
// add node 1
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(1);
node.set_version(3);
node.set_visible(true);
node.set_changeset(333);
node.set_uid(21);
node.set_timestamp(123);
node.set_location(osmium::Location(3.5, 4.7));
node_builder.add_user("testuser");
buffer.commit();
}
{
// add node 2
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(2);
node.set_version(3);
node.set_visible(true);
node.set_changeset(333);
node.set_uid(21);
node.set_timestamp(123);
node.set_location(osmium::Location(3.5, 4.7));
node_builder.add_user("testuser");
{ {
osmium::builder::TagListBuilder tag_builder(buffer, &node_builder); // add node 1
tag_builder.add_tag("amenity", "bank"); osmium::builder::NodeBuilder node_builder(buffer);
tag_builder.add_tag("name", "OSM Savings"); osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(1);
node.set_version(3);
node.set_visible(true);
node.set_changeset(333);
node.set_uid(21);
node.set_timestamp(123);
node.set_location(osmium::Location(3.5, 4.7));
node_builder.add_user("testuser");
buffer.commit();
} }
buffer.commit(); {
} // add node 2
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
REQUIRE(2 == std::distance(buffer.begin(), buffer.end())); node.set_id(2);
int item_no = 0; node.set_version(3);
for (osmium::memory::Item& item : buffer) { node.set_visible(true);
REQUIRE(osmium::item_type::node == item.type()); node.set_changeset(333);
node.set_uid(21);
node.set_timestamp(123);
node.set_location(osmium::Location(3.5, 4.7));
osmium::Node& node = static_cast<osmium::Node&>(item); node_builder.add_user("testuser");
switch (item_no) { {
case 0: osmium::builder::TagListBuilder tag_builder(buffer, &node_builder);
check_node_1(node); tag_builder.add_tag("amenity", "bank");
break; tag_builder.add_tag("name", "OSM Savings");
case 1: }
check_node_2(node);
break; buffer.commit();
default:
break;
} }
++item_no; REQUIRE(2 == std::distance(buffer.begin(), buffer.end()));
int item_no = 0;
for (osmium::memory::Item& item : buffer) {
REQUIRE(osmium::item_type::node == item.type());
osmium::Node& node = static_cast<osmium::Node&>(item);
switch (item_no) {
case 0:
check_node_1(node);
break;
case 1:
check_node_2(node);
break;
default:
break;
}
++item_no;
}
} }
} }
}

View File

@ -10,32 +10,32 @@
TEST_CASE("Projection") { TEST_CASE("Projection") {
SECTION("point_mercator") { SECTION("point_mercator") {
osmium::geom::WKTFactory<osmium::geom::MercatorProjection> factory(2); osmium::geom::WKTFactory<osmium::geom::MercatorProjection> factory(2);
std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))}; std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))};
REQUIRE(std::string{"POINT(356222.37 467961.14)"} == wkt); REQUIRE(std::string {"POINT(356222.37 467961.14)"} == wkt);
} }
SECTION("point_epsg_3857") { SECTION("point_epsg_3857") {
osmium::geom::WKTFactory<osmium::geom::Projection> factory(osmium::geom::Projection(3857), 2); osmium::geom::WKTFactory<osmium::geom::Projection> factory(osmium::geom::Projection(3857), 2);
std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))}; std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))};
REQUIRE(std::string{"POINT(356222.37 467961.14)"} == wkt); REQUIRE(std::string {"POINT(356222.37 467961.14)"} == wkt);
} }
SECTION("wkb_with_parameter") { SECTION("wkb_with_parameter") {
osmium::geom::WKBFactory<osmium::geom::Projection> wkb_factory(osmium::geom::Projection(3857), osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); osmium::geom::WKBFactory<osmium::geom::Projection> wkb_factory(osmium::geom::Projection(3857), osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
osmium::geom::GEOSFactory<osmium::geom::Projection> geos_factory(osmium::geom::Projection(3857)); osmium::geom::GEOSFactory<osmium::geom::Projection> geos_factory(osmium::geom::Projection(3857));
std::string wkb = wkb_factory.create_point(osmium::Location(3.2, 4.2)); std::string wkb = wkb_factory.create_point(osmium::Location(3.2, 4.2));
std::unique_ptr<geos::geom::Point> geos_point = geos_factory.create_point(osmium::Location(3.2, 4.2)); std::unique_ptr<geos::geom::Point> geos_point = geos_factory.create_point(osmium::Location(3.2, 4.2));
REQUIRE(geos_to_wkb(geos_point.get()) == wkb); REQUIRE(geos_to_wkb(geos_point.get()) == wkb);
} }
SECTION("cleanup") { SECTION("cleanup") {
// trying to make valgrind happy, but there is still a memory leak in proj library // trying to make valgrind happy, but there is still a memory leak in proj library
pj_deallocate_grids(); pj_deallocate_grids();
} }
} }

View File

@ -4,34 +4,34 @@
TEST_CASE("Mercator") { TEST_CASE("Mercator") {
SECTION("mercator_projection") { SECTION("mercator_projection") {
osmium::geom::MercatorProjection projection; osmium::geom::MercatorProjection projection;
REQUIRE(3857 == projection.epsg()); REQUIRE(3857 == projection.epsg());
REQUIRE("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs" == projection.proj_string()); REQUIRE("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs" == projection.proj_string());
} }
SECTION("low_level_mercator_functions") { SECTION("low_level_mercator_functions") {
osmium::geom::Coordinates c1(17.839, -3.249); osmium::geom::Coordinates c1(17.839, -3.249);
osmium::geom::Coordinates r1 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c1)); osmium::geom::Coordinates r1 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c1));
REQUIRE(r1.x == Approx(c1.x).epsilon(0.000001)); REQUIRE(r1.x == Approx(c1.x).epsilon(0.000001));
REQUIRE(r1.y == Approx(c1.y).epsilon(0.000001)); REQUIRE(r1.y == Approx(c1.y).epsilon(0.000001));
osmium::geom::Coordinates c2(-89.2, 15.915); osmium::geom::Coordinates c2(-89.2, 15.915);
osmium::geom::Coordinates r2 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c2)); osmium::geom::Coordinates r2 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c2));
REQUIRE(r2.x == Approx(c2.x).epsilon(0.000001)); REQUIRE(r2.x == Approx(c2.x).epsilon(0.000001));
REQUIRE(r2.y == Approx(c2.y).epsilon(0.000001)); REQUIRE(r2.y == Approx(c2.y).epsilon(0.000001));
osmium::geom::Coordinates c3(180.0, 85.0); osmium::geom::Coordinates c3(180.0, 85.0);
osmium::geom::Coordinates r3 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c3)); osmium::geom::Coordinates r3 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c3));
REQUIRE(r3.x == Approx(c3.x).epsilon(0.000001)); REQUIRE(r3.x == Approx(c3.x).epsilon(0.000001));
REQUIRE(r3.y == Approx(c3.y).epsilon(0.000001)); REQUIRE(r3.y == Approx(c3.y).epsilon(0.000001));
} }
SECTION("mercator_bounds") { SECTION("mercator_bounds") {
osmium::Location mmax(180.0, osmium::geom::MERCATOR_MAX_LAT); osmium::Location mmax(180.0, osmium::geom::MERCATOR_MAX_LAT);
osmium::geom::Coordinates c = osmium::geom::lonlat_to_mercator(mmax); osmium::geom::Coordinates c = osmium::geom::lonlat_to_mercator(mmax);
REQUIRE(c.x == Approx(c.y).epsilon(0.001)); REQUIRE(c.x == Approx(c.y).epsilon(0.001));
REQUIRE(osmium::geom::detail::y_to_lat(osmium::geom::detail::lon_to_x(180.0)) == Approx(osmium::geom::MERCATOR_MAX_LAT).epsilon(0.0000001)); REQUIRE(osmium::geom::detail::y_to_lat(osmium::geom::detail::lon_to_x(180.0)) == Approx(osmium::geom::MERCATOR_MAX_LAT).epsilon(0.0000001));
} }
} }

View File

@ -58,113 +58,113 @@ void test_func_real(TIndex& index) {
TEST_CASE("IdToLocation") { TEST_CASE("IdToLocation") {
SECTION("Dummy") { SECTION("Dummy") {
typedef osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location> index_type; typedef osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1; index_type index1;
REQUIRE(0 == index1.size()); REQUIRE(0 == index1.size());
REQUIRE(0 == index1.used_memory()); REQUIRE(0 == index1.used_memory());
test_func_all<index_type>(index1); test_func_all<index_type>(index1);
REQUIRE(0 == index1.size()); REQUIRE(0 == index1.size());
REQUIRE(0 == index1.used_memory()); REQUIRE(0 == index1.used_memory());
} }
SECTION("DenseMemArray") { SECTION("DenseMemArray") {
typedef osmium::index::map::DenseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_type; typedef osmium::index::map::DenseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1; index_type index1;
index1.reserve(1000); index1.reserve(1000);
test_func_all<index_type>(index1); test_func_all<index_type>(index1);
index_type index2; index_type index2;
index2.reserve(1000); index2.reserve(1000);
test_func_real<index_type>(index2); test_func_real<index_type>(index2);
} }
#ifdef __linux__ #ifdef __linux__
SECTION("DenseMmapArray") { SECTION("DenseMmapArray") {
typedef osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location> index_type; typedef osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1; index_type index1;
test_func_all<index_type>(index1); test_func_all<index_type>(index1);
index_type index2; index_type index2;
test_func_real<index_type>(index2); test_func_real<index_type>(index2);
} }
#else #else
# pragma message("not running 'DenseMapMmap' test case on this machine") # pragma message("not running 'DenseMapMmap' test case on this machine")
#endif #endif
SECTION("DenseFileArray") { SECTION("DenseFileArray") {
typedef osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location> index_type; typedef osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1; index_type index1;
test_func_all<index_type>(index1); test_func_all<index_type>(index1);
index_type index2; index_type index2;
test_func_real<index_type>(index2); test_func_real<index_type>(index2);
} }
#ifdef OSMIUM_WITH_SPARSEHASH #ifdef OSMIUM_WITH_SPARSEHASH
SECTION("SparseMemTable") { SECTION("SparseMemTable") {
typedef osmium::index::map::SparseMemTable<osmium::unsigned_object_id_type, osmium::Location> index_type; typedef osmium::index::map::SparseMemTable<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1; index_type index1;
test_func_all<index_type>(index1); test_func_all<index_type>(index1);
index_type index2; index_type index2;
test_func_real<index_type>(index2); test_func_real<index_type>(index2);
} }
#endif #endif
SECTION("SparseMemMap") { SECTION("SparseMemMap") {
typedef osmium::index::map::SparseMemMap<osmium::unsigned_object_id_type, osmium::Location> index_type; typedef osmium::index::map::SparseMemMap<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1; index_type index1;
test_func_all<index_type>(index1); test_func_all<index_type>(index1);
index_type index2; index_type index2;
test_func_real<index_type>(index2); test_func_real<index_type>(index2);
} }
SECTION("SparseMemArray") { SECTION("SparseMemArray") {
typedef osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_type; typedef osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1; index_type index1;
REQUIRE(0 == index1.size()); REQUIRE(0 == index1.size());
REQUIRE(0 == index1.used_memory()); REQUIRE(0 == index1.used_memory());
test_func_all<index_type>(index1); test_func_all<index_type>(index1);
REQUIRE(2 == index1.size()); REQUIRE(2 == index1.size());
index_type index2; index_type index2;
test_func_real<index_type>(index2); test_func_real<index_type>(index2);
} }
SECTION("Dynamic map choice") { SECTION("Dynamic map choice") {
typedef osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location> map_type; typedef osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location> map_type;
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance(); const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
std::vector<std::string> map_type_names = map_factory.map_types(); std::vector<std::string> map_type_names = map_factory.map_types();
REQUIRE(map_type_names.size() >= 5); REQUIRE(map_type_names.size() >= 5);
for (const auto& map_type_name : map_type_names) { for (const auto& map_type_name : map_type_names) {
std::unique_ptr<map_type> index1 = map_factory.create_map(map_type_name); std::unique_ptr<map_type> index1 = map_factory.create_map(map_type_name);
index1->reserve(1000); index1->reserve(1000);
test_func_all<map_type>(*index1); test_func_all<map_type>(*index1);
std::unique_ptr<map_type> index2 = map_factory.create_map(map_type_name); std::unique_ptr<map_type> index2 = map_factory.create_map(map_type_name);
index2->reserve(1000); index2->reserve(1000);
test_func_real<map_type>(*index2); test_func_real<map_type>(*index2);
}
} }
}
} }

View File

@ -3,97 +3,74 @@
#include <osmium/index/detail/typed_mmap.hpp> #include <osmium/index/detail/typed_mmap.hpp>
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32)) #if defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32))
#include "win_mkstemp.hpp" #include "win_mkstemp.hpp"
#endif #endif
TEST_CASE("TypedMmap") { TEST_CASE("TypedMmap") {
SECTION("Mmap") { SECTION("Mmap") {
uint64_t* data = osmium::detail::typed_mmap<uint64_t>::map(10); uint64_t* data = osmium::detail::typed_mmap<uint64_t>::map(10);
data[0] = 4ul; data[0] = 4ul;
data[3] = 9ul; data[3] = 9ul;
data[9] = 25ul; data[9] = 25ul;
REQUIRE(4ul == data[0]); REQUIRE(4ul == data[0]);
REQUIRE(9ul == data[3]); REQUIRE(9ul == data[3]);
REQUIRE(25ul == data[9]); REQUIRE(25ul == data[9]);
osmium::detail::typed_mmap<uint64_t>::unmap(data, 10); osmium::detail::typed_mmap<uint64_t>::unmap(data, 10);
} }
SECTION("MmapSizeZero") { SECTION("MmapSizeZero") {
REQUIRE_THROWS_AS(osmium::detail::typed_mmap<uint64_t>::map(0), std::system_error); REQUIRE_THROWS_AS(osmium::detail::typed_mmap<uint64_t>::map(0), std::system_error);
} }
SECTION("MmapHugeSize") { SECTION("MmapHugeSize") {
// this is a horrible hack to only run the test on 64bit machines. // this is a horrible hack to only run the test on 64bit machines.
if (sizeof(size_t) >= 8) { if (sizeof(size_t) >= 8) {
REQUIRE_THROWS_AS(osmium::detail::typed_mmap<uint64_t>::map(1ULL << (sizeof(size_t) * 6)), std::system_error); REQUIRE_THROWS_AS(osmium::detail::typed_mmap<uint64_t>::map(1ULL << (sizeof(size_t) * 6)), std::system_error);
}
} }
}
#ifdef __linux__ #ifdef __linux__
SECTION("Remap") { SECTION("Remap") {
uint64_t* data = osmium::detail::typed_mmap<uint64_t>::map(10); uint64_t* data = osmium::detail::typed_mmap<uint64_t>::map(10);
data[0] = 4ul; data[0] = 4ul;
data[3] = 9ul; data[3] = 9ul;
data[9] = 25ul; data[9] = 25ul;
uint64_t* new_data = osmium::detail::typed_mmap<uint64_t>::remap(data, 10, 1000); uint64_t* new_data = osmium::detail::typed_mmap<uint64_t>::remap(data, 10, 1000);
REQUIRE(4ul == new_data[0]); REQUIRE(4ul == new_data[0]);
REQUIRE(9ul == new_data[3]); REQUIRE(9ul == new_data[3]);
REQUIRE(25ul == new_data[9]); REQUIRE(25ul == new_data[9]);
} }
#else #else
# pragma message("not running 'Remap' test case on this machine") # pragma message("not running 'Remap' test case on this machine")
#endif #endif
SECTION("FileSize") { SECTION("FileSize") {
const int size = 100; const int size = 100;
char filename[] = "test_mmap_file_size_XXXXXX"; char filename[] = "test_mmap_file_size_XXXXXX";
const int fd = mkstemp(filename); const int fd = mkstemp(filename);
REQUIRE(fd > 0); REQUIRE(fd > 0);
REQUIRE(0 == osmium::detail::typed_mmap<uint64_t>::file_size(fd)); REQUIRE(0 == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
REQUIRE(0 == ftruncate(fd, size * sizeof(uint64_t))); REQUIRE(0 == ftruncate(fd, size * sizeof(uint64_t)));
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd)); REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
osmium::detail::typed_mmap<uint64_t>::grow_file(size / 2, fd); osmium::detail::typed_mmap<uint64_t>::grow_file(size / 2, fd);
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd)); REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
osmium::detail::typed_mmap<uint64_t>::grow_file(size, fd); osmium::detail::typed_mmap<uint64_t>::grow_file(size, fd);
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd)); REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
osmium::detail::typed_mmap<uint64_t>::grow_file(size * 2, fd); osmium::detail::typed_mmap<uint64_t>::grow_file(size * 2, fd);
REQUIRE((size * 2) == osmium::detail::typed_mmap<uint64_t>::file_size(fd)); REQUIRE((size * 2) == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
REQUIRE(0 == close(fd)); REQUIRE(0 == close(fd));
REQUIRE(0 == unlink(filename)); REQUIRE(0 == unlink(filename));
} }
SECTION("GrowAndMap") {
const int size = 100;
char filename[] = "test_mmap_grow_and_map_XXXXXX";
const int fd = mkstemp(filename);
REQUIRE(fd > 0);
uint64_t* data = osmium::detail::typed_mmap<uint64_t>::grow_and_map(size, fd);
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
data[0] = 1ul;
data[1] = 8ul;
data[99] = 27ul;
REQUIRE(1ul == data[0]);
REQUIRE(8ul == data[1]);
REQUIRE(27ul == data[99]);
osmium::detail::typed_mmap<uint64_t>::unmap(data, size);
REQUIRE(0 == close(fd));
REQUIRE(0 == unlink(filename));
}
} }

View File

@ -0,0 +1,34 @@
#include "catch.hpp"
#include <osmium/index/detail/typed_mmap.hpp>
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32))
#include "win_mkstemp.hpp"
#endif
TEST_CASE("TypedMmapGrow") {
SECTION("GrowAndMap") {
const int size = 100;
char filename[] = "test_mmap_grow_and_map_XXXXXX";
const int fd = mkstemp(filename);
REQUIRE(fd > 0);
uint64_t* data = osmium::detail::typed_mmap<uint64_t>::grow_and_map(size, fd);
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
data[0] = 1ul;
data[1] = 8ul;
data[99] = 27ul;
REQUIRE(1ul == data[0]);
REQUIRE(8ul == data[1]);
REQUIRE(27ul == data[99]);
osmium::detail::typed_mmap<uint64_t>::unmap(data, size);
REQUIRE(0 == close(fd));
REQUIRE(0 == unlink(filename));
}
}

View File

@ -9,25 +9,25 @@
TEST_CASE("Bzip2") { TEST_CASE("Bzip2") {
SECTION("read_compressed_file") { SECTION("read_compressed_file") {
std::string input_file = with_data_dir("t/io/data_bzip2.txt.bz2"); std::string input_file = with_data_dir("t/io/data_bzip2.txt.bz2");
int fd = ::open(input_file.c_str(), O_RDONLY); int fd = ::open(input_file.c_str(), O_RDONLY);
REQUIRE(fd > 0); REQUIRE(fd > 0);
size_t size = 0; size_t size = 0;
std::string all; std::string all;
{ {
osmium::io::Bzip2Decompressor decomp(fd); osmium::io::Bzip2Decompressor decomp(fd);
for (std::string data = decomp.read(); !data.empty(); data = decomp.read()) { for (std::string data = decomp.read(); !data.empty(); data = decomp.read()) {
size += data.size(); size += data.size();
all += data; all += data;
}
} }
REQUIRE(9 == size);
REQUIRE("TESTDATA\n" == all);
} }
REQUIRE(9 == size);
REQUIRE("TESTDATA\n" == all);
}
} }

View File

@ -6,246 +6,246 @@
TEST_CASE("FileFormats") { TEST_CASE("FileFormats") {
SECTION("default_file_format") { SECTION("default_file_format") {
osmium::io::File f; osmium::io::File f;
REQUIRE(osmium::io::file_format::unknown == f.format()); REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
REQUIRE_THROWS_AS(f.check(), std::runtime_error); REQUIRE_THROWS_AS(f.check(), std::runtime_error);
} }
SECTION("stdin_stdout_empty") { SECTION("stdin_stdout_empty") {
osmium::io::File f {""}; osmium::io::File f {""};
REQUIRE(osmium::io::file_format::unknown == f.format()); REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
REQUIRE_THROWS_AS(f.check(), std::runtime_error); REQUIRE_THROWS_AS(f.check(), std::runtime_error);
} }
SECTION("stdin_stdout_dash") { SECTION("stdin_stdout_dash") {
osmium::io::File f {"-"}; osmium::io::File f {"-"};
REQUIRE(osmium::io::file_format::unknown == f.format()); REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
REQUIRE_THROWS_AS(f.check(), std::runtime_error); REQUIRE_THROWS_AS(f.check(), std::runtime_error);
} }
SECTION("stdin_stdout_bz2") { SECTION("stdin_stdout_bz2") {
osmium::io::File f {"-", "osm.bz2"}; osmium::io::File f {"-", "osm.bz2"};
REQUIRE("" == f.filename()); REQUIRE("" == f.filename());
REQUIRE(osmium::io::file_format::xml == f.format()); REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::bzip2 == f.compression()); REQUIRE(osmium::io::file_compression::bzip2 == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("detect_file_format_by_suffix_osm") { SECTION("detect_file_format_by_suffix_osm") {
osmium::io::File f {"test.osm"}; osmium::io::File f {"test.osm"};
REQUIRE(osmium::io::file_format::xml == f.format()); REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("detect_file_format_by_suffix_pbf") { SECTION("detect_file_format_by_suffix_pbf") {
osmium::io::File f {"test.pbf"}; osmium::io::File f {"test.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format()); REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("detect_file_format_by_suffix_osm_pbf") { SECTION("detect_file_format_by_suffix_osm_pbf") {
osmium::io::File f {"test.osm.pbf"}; osmium::io::File f {"test.osm.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format()); REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("detect_file_format_by_suffix_opl") { SECTION("detect_file_format_by_suffix_opl") {
osmium::io::File f {"test.opl"}; osmium::io::File f {"test.opl"};
REQUIRE(osmium::io::file_format::opl == f.format()); REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("detect_file_format_by_suffix_osm_opl") { SECTION("detect_file_format_by_suffix_osm_opl") {
osmium::io::File f {"test.osm.opl"}; osmium::io::File f {"test.osm.opl"};
REQUIRE(osmium::io::file_format::opl == f.format()); REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("detect_file_format_by_suffix_osm_gz") { SECTION("detect_file_format_by_suffix_osm_gz") {
osmium::io::File f {"test.osm.gz"}; osmium::io::File f {"test.osm.gz"};
REQUIRE(osmium::io::file_format::xml == f.format()); REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression()); REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("detect_file_format_by_suffix_opl_bz2") { SECTION("detect_file_format_by_suffix_opl_bz2") {
osmium::io::File f {"test.osm.opl.bz2"}; osmium::io::File f {"test.osm.opl.bz2"};
REQUIRE(osmium::io::file_format::opl == f.format()); REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::bzip2 == f.compression()); REQUIRE(osmium::io::file_compression::bzip2 == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("detect_file_format_by_suffix_osc_gz") { SECTION("detect_file_format_by_suffix_osc_gz") {
osmium::io::File f {"test.osc.gz"}; osmium::io::File f {"test.osc.gz"};
REQUIRE(osmium::io::file_format::xml == f.format()); REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression()); REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions()); REQUIRE(true == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("detect_file_format_by_suffix_opl_gz") { SECTION("detect_file_format_by_suffix_opl_gz") {
osmium::io::File f {"test.osh.opl.gz"}; osmium::io::File f {"test.osh.opl.gz"};
REQUIRE(osmium::io::file_format::opl == f.format()); REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression()); REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions()); REQUIRE(true == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("detect_file_format_by_suffix_osh_pbf") { SECTION("detect_file_format_by_suffix_osh_pbf") {
osmium::io::File f {"test.osh.pbf"}; osmium::io::File f {"test.osh.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format()); REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions()); REQUIRE(true == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("override_file_format_by_suffix_osm") { SECTION("override_file_format_by_suffix_osm") {
osmium::io::File f {"test", "osm"}; osmium::io::File f {"test", "osm"};
REQUIRE(osmium::io::file_format::xml == f.format()); REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("override_file_format_by_suffix_pbf") { SECTION("override_file_format_by_suffix_pbf") {
osmium::io::File f {"test", "pbf"}; osmium::io::File f {"test", "pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format()); REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("override_file_format_by_suffix_osm_pbf") { SECTION("override_file_format_by_suffix_osm_pbf") {
osmium::io::File f {"test", "osm.pbf"}; osmium::io::File f {"test", "osm.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format()); REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("override_file_format_by_suffix_opl") { SECTION("override_file_format_by_suffix_opl") {
osmium::io::File f {"test", "opl"}; osmium::io::File f {"test", "opl"};
REQUIRE(osmium::io::file_format::opl == f.format()); REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("override_file_format_by_suffix_osm_opl") { SECTION("override_file_format_by_suffix_osm_opl") {
osmium::io::File f {"test", "osm.opl"}; osmium::io::File f {"test", "osm.opl"};
REQUIRE(osmium::io::file_format::opl == f.format()); REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("override_file_format_by_suffix_osm_gz") { SECTION("override_file_format_by_suffix_osm_gz") {
osmium::io::File f {"test", "osm.gz"}; osmium::io::File f {"test", "osm.gz"};
REQUIRE(osmium::io::file_format::xml == f.format()); REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression()); REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("override_file_format_by_suffix_osm_opl_bz2") { SECTION("override_file_format_by_suffix_osm_opl_bz2") {
osmium::io::File f {"test", "osm.opl.bz2"}; osmium::io::File f {"test", "osm.opl.bz2"};
REQUIRE(osmium::io::file_format::opl == f.format()); REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::bzip2 == f.compression()); REQUIRE(osmium::io::file_compression::bzip2 == f.compression());
REQUIRE(false == f.has_multiple_object_versions()); REQUIRE(false == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("override_file_format_by_suffix_osc_gz") { SECTION("override_file_format_by_suffix_osc_gz") {
osmium::io::File f {"test", "osc.gz"}; osmium::io::File f {"test", "osc.gz"};
REQUIRE(osmium::io::file_format::xml == f.format()); REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression()); REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions()); REQUIRE(true == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("override_file_format_by_suffix_osh_opl_gz") { SECTION("override_file_format_by_suffix_osh_opl_gz") {
osmium::io::File f {"test", "osh.opl.gz"}; osmium::io::File f {"test", "osh.opl.gz"};
REQUIRE(osmium::io::file_format::opl == f.format()); REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression()); REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions()); REQUIRE(true == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("override_file_format_by_suffix_osh_pbf") { SECTION("override_file_format_by_suffix_osh_pbf") {
osmium::io::File f {"test", "osh.pbf"}; osmium::io::File f {"test", "osh.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format()); REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions()); REQUIRE(true == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("format_options_pbf_history") { SECTION("format_options_pbf_history") {
osmium::io::File f {"test", "pbf,history=true"}; osmium::io::File f {"test", "pbf,history=true"};
REQUIRE(osmium::io::file_format::pbf == f.format()); REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions()); REQUIRE(true == f.has_multiple_object_versions());
f.check(); f.check();
} }
SECTION("format_options_pbf_foo") { SECTION("format_options_pbf_foo") {
osmium::io::File f {"test.osm", "pbf,foo=bar"}; osmium::io::File f {"test.osm", "pbf,foo=bar"};
REQUIRE(osmium::io::file_format::pbf == f.format()); REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE("bar" == f.get("foo")); REQUIRE("bar" == f.get("foo"));
f.check(); f.check();
} }
SECTION("format_options_xml_abc_something") { SECTION("format_options_xml_abc_something") {
osmium::io::File f {"test.bla", "xml,abc,some=thing"}; osmium::io::File f {"test.bla", "xml,abc,some=thing"};
REQUIRE(osmium::io::file_format::xml == f.format()); REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE("true" == f.get("abc")); REQUIRE("true" == f.get("abc"));
REQUIRE("thing" == f.get("some")); REQUIRE("thing" == f.get("some"));
REQUIRE(2 == std::distance(f.begin(), f.end())); REQUIRE(2 == std::distance(f.begin(), f.end()));
f.check(); f.check();
} }
SECTION("unknown_format_foo_bar") { SECTION("unknown_format_foo_bar") {
osmium::io::File f {"test.foo.bar"}; osmium::io::File f {"test.foo.bar"};
REQUIRE(osmium::io::file_format::unknown == f.format()); REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression()); REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE_THROWS_AS(f.check(), std::runtime_error); REQUIRE_THROWS_AS(f.check(), std::runtime_error);
} }
SECTION("unknown_format_foo") { SECTION("unknown_format_foo") {
osmium::io::File f {"test", "foo"}; osmium::io::File f {"test", "foo"};
REQUIRE_THROWS_AS(f.check(), std::runtime_error); REQUIRE_THROWS_AS(f.check(), std::runtime_error);
} }
SECTION("unknown_format_osm_foo") { SECTION("unknown_format_osm_foo") {
osmium::io::File f {"test", "osm.foo"}; osmium::io::File f {"test", "osm.foo"};
REQUIRE_THROWS_AS(f.check(), std::runtime_error); REQUIRE_THROWS_AS(f.check(), std::runtime_error);
} }
SECTION("unknown_format_bla_equals_foo") { SECTION("unknown_format_bla_equals_foo") {
osmium::io::File f {"test", "bla=foo"}; osmium::io::File f {"test", "bla=foo"};
REQUIRE_THROWS_AS(f.check(), std::runtime_error); REQUIRE_THROWS_AS(f.check(), std::runtime_error);
} }
} }

View File

@ -25,192 +25,192 @@ void check_filter(const osmium::TagList& tag_list, const TFilter filter, const s
TEST_CASE("Filter") { TEST_CASE("Filter") {
SECTION("KeyFilter_matches_some_tags") { SECTION("KeyFilter_matches_some_tags") {
osmium::tags::KeyFilter filter(false); osmium::tags::KeyFilter filter(false);
filter.add(true, "highway").add(true, "railway"); filter.add(true, "highway").add(true, "railway");
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, // match { "highway", "primary" }, // match
{ "name", "Main Street" }, // no match { "name", "Main Street" }, // no match
{ "source", "GPS" } // no match { "source", "GPS" } // no match
}); });
std::vector<bool> results = { true, false, false }; std::vector<bool> results = { true, false, false };
check_filter(tag_list, filter, results); check_filter(tag_list, filter, results);
} }
SECTION("KeyFilter_iterator_filters_tags") { SECTION("KeyFilter_iterator_filters_tags") {
osmium::tags::KeyFilter filter(false); osmium::tags::KeyFilter filter(false);
filter.add(true, "highway").add(true, "source"); filter.add(true, "highway").add(true, "source");
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, // match { "highway", "primary" }, // match
{ "name", "Main Street" }, // no match { "name", "Main Street" }, // no match
{ "source", "GPS" } // no match { "source", "GPS" } // no match
}); });
osmium::tags::KeyFilter::iterator it(filter, tl.begin(), tl.end()); osmium::tags::KeyFilter::iterator it(filter, tl.begin(), tl.end());
const osmium::tags::KeyFilter::iterator end(filter, tl.end(), tl.end()); const osmium::tags::KeyFilter::iterator end(filter, tl.end(), tl.end());
REQUIRE(2 == std::distance(it, end)); REQUIRE(2 == std::distance(it, end));
REQUIRE(it != end); REQUIRE(it != end);
REQUIRE(std::string("highway") == it->key()); REQUIRE(std::string("highway") == it->key());
REQUIRE(std::string("primary") == it->value()); REQUIRE(std::string("primary") == it->value());
++it; ++it;
REQUIRE(std::string("source") == it->key()); REQUIRE(std::string("source") == it->key());
REQUIRE(std::string("GPS") == it->value()); REQUIRE(std::string("GPS") == it->value());
REQUIRE(++it == end); REQUIRE(++it == end);
} }
SECTION("KeyValueFilter_matches_some_tags") { SECTION("KeyValueFilter_matches_some_tags") {
osmium::tags::KeyValueFilter filter(false); osmium::tags::KeyValueFilter filter(false);
filter.add(true, "highway", "residential").add(true, "highway", "primary").add(true, "railway"); filter.add(true, "highway", "residential").add(true, "highway", "primary").add(true, "railway");
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, { "highway", "primary" },
{ "railway", "tram" }, { "railway", "tram" },
{ "source", "GPS" } { "source", "GPS" }
}); });
std::vector<bool> results = {true, true, false}; std::vector<bool> results = {true, true, false};
check_filter(tag_list, filter, results); check_filter(tag_list, filter, results);
} }
SECTION("KeyValueFilter_ordering_matters") { SECTION("KeyValueFilter_ordering_matters") {
osmium::tags::KeyValueFilter filter1(false); osmium::tags::KeyValueFilter filter1(false);
filter1.add(true, "highway").add(false, "highway", "road"); filter1.add(true, "highway").add(false, "highway", "road");
osmium::tags::KeyValueFilter filter2(false); osmium::tags::KeyValueFilter filter2(false);
filter2.add(false, "highway", "road").add(true, "highway"); filter2.add(false, "highway", "road").add(true, "highway");
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list1 = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tag_list1 = osmium::builder::build_tag_list(buffer, {
{ "highway", "road" }, { "highway", "road" },
{ "name", "Main Street" } { "name", "Main Street" }
}); });
const osmium::TagList& tag_list2 = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tag_list2 = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, { "highway", "primary" },
{ "name", "Main Street" } { "name", "Main Street" }
}); });
check_filter(tag_list1, filter1, {true, false}); check_filter(tag_list1, filter1, {true, false});
check_filter(tag_list1, filter2, {false, false}); check_filter(tag_list1, filter2, {false, false});
check_filter(tag_list2, filter2, {true, false}); check_filter(tag_list2, filter2, {true, false});
} }
SECTION("KeyValueFilter_matches_against_taglist_with_any") { SECTION("KeyValueFilter_matches_against_taglist_with_any") {
osmium::tags::KeyValueFilter filter(false); osmium::tags::KeyValueFilter filter(false);
filter.add(true, "highway", "primary").add(true, "name"); filter.add(true, "highway", "primary").add(true, "name");
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, { "highway", "primary" },
{ "railway", "tram" }, { "railway", "tram" },
{ "source", "GPS" } { "source", "GPS" }
}); });
REQUIRE( osmium::tags::match_any_of(tag_list, filter)); REQUIRE( osmium::tags::match_any_of(tag_list, filter));
REQUIRE(!osmium::tags::match_all_of(tag_list, filter)); REQUIRE(!osmium::tags::match_all_of(tag_list, filter));
REQUIRE(!osmium::tags::match_none_of(tag_list, filter)); REQUIRE(!osmium::tags::match_none_of(tag_list, filter));
} }
SECTION("KeyValueFilter_matches_against_taglist_with_all") { SECTION("KeyValueFilter_matches_against_taglist_with_all") {
osmium::tags::KeyValueFilter filter(false); osmium::tags::KeyValueFilter filter(false);
filter.add(true, "highway", "primary").add(true, "name"); filter.add(true, "highway", "primary").add(true, "name");
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, { "highway", "primary" },
{ "name", "Main Street" } { "name", "Main Street" }
}); });
REQUIRE( osmium::tags::match_any_of(tag_list, filter)); REQUIRE( osmium::tags::match_any_of(tag_list, filter));
REQUIRE( osmium::tags::match_all_of(tag_list, filter)); REQUIRE( osmium::tags::match_all_of(tag_list, filter));
REQUIRE(!osmium::tags::match_none_of(tag_list, filter)); REQUIRE(!osmium::tags::match_none_of(tag_list, filter));
} }
SECTION("KeyValueFilter_matches_against_taglist_with_none") { SECTION("KeyValueFilter_matches_against_taglist_with_none") {
osmium::tags::KeyValueFilter filter(false); osmium::tags::KeyValueFilter filter(false);
filter.add(true, "highway", "road").add(true, "source"); filter.add(true, "highway", "road").add(true, "source");
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, { "highway", "primary" },
{ "name", "Main Street" } { "name", "Main Street" }
}); });
REQUIRE(!osmium::tags::match_any_of(tag_list, filter)); REQUIRE(!osmium::tags::match_any_of(tag_list, filter));
REQUIRE(!osmium::tags::match_all_of(tag_list, filter)); REQUIRE(!osmium::tags::match_all_of(tag_list, filter));
REQUIRE( osmium::tags::match_none_of(tag_list, filter)); REQUIRE( osmium::tags::match_none_of(tag_list, filter));
} }
SECTION("KeyValueFilter_matches_against_taglist_with_any_called_with_rvalue") { SECTION("KeyValueFilter_matches_against_taglist_with_any_called_with_rvalue") {
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, { "highway", "primary" },
{ "railway", "tram" }, { "railway", "tram" },
{ "source", "GPS" } { "source", "GPS" }
}); });
REQUIRE(osmium::tags::match_any_of(tag_list, REQUIRE(osmium::tags::match_any_of(tag_list,
osmium::tags::KeyValueFilter().add(true, "highway", "primary").add(true, "name"))); osmium::tags::KeyValueFilter().add(true, "highway", "primary").add(true, "name")));
} }
SECTION("RegexFilter_matches_some_tags") { SECTION("RegexFilter_matches_some_tags") {
osmium::tags::RegexFilter filter(false); osmium::tags::RegexFilter filter(false);
filter.add(true, "highway", std::regex(".*_link")); filter.add(true, "highway", std::regex(".*_link"));
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list1 = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tag_list1 = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary_link" }, { "highway", "primary_link" },
{ "source", "GPS" } { "source", "GPS" }
}); });
const osmium::TagList& tag_list2 = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tag_list2 = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, { "highway", "primary" },
{ "source", "GPS" } { "source", "GPS" }
}); });
check_filter(tag_list1, filter, {true, false}); check_filter(tag_list1, filter, {true, false});
check_filter(tag_list2, filter, {false, false}); check_filter(tag_list2, filter, {false, false});
} }
SECTION("RegexFilter_matches_some_tags_with_lvalue_regex") { SECTION("RegexFilter_matches_some_tags_with_lvalue_regex") {
osmium::tags::RegexFilter filter(false); osmium::tags::RegexFilter filter(false);
std::regex r(".*straße"); std::regex r(".*straße");
filter.add(true, "name", r); filter.add(true, "name", r);
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, { "highway", "primary" },
{ "name", "Hauptstraße" } { "name", "Hauptstraße" }
}); });
check_filter(tag_list, filter, {false, true}); check_filter(tag_list, filter, {false, true});
} }
SECTION("KeyPrefixFilter_matches_some_tags") { SECTION("KeyPrefixFilter_matches_some_tags") {
osmium::tags::KeyPrefixFilter filter(false); osmium::tags::KeyPrefixFilter filter(false);
filter.add(true, "name:"); filter.add(true, "name:");
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, { "highway", "primary" },
{ "name:de", "Hauptstraße" } { "name:de", "Hauptstraße" }
}); });
check_filter(tag_list, filter, {false, true}); check_filter(tag_list, filter, {false, true});
} }
} }

View File

@ -8,54 +8,54 @@
TEST_CASE("Operators") { TEST_CASE("Operators") {
SECTION("Equal") { SECTION("Equal") {
osmium::memory::Buffer buffer1(10240); osmium::memory::Buffer buffer1(10240);
{ {
osmium::builder::TagListBuilder tl_builder(buffer1); osmium::builder::TagListBuilder tl_builder(buffer1);
tl_builder.add_tag("highway", "primary"); tl_builder.add_tag("highway", "primary");
tl_builder.add_tag("name", "Main Street"); tl_builder.add_tag("name", "Main Street");
tl_builder.add_tag("source", "GPS"); tl_builder.add_tag("source", "GPS");
}
buffer1.commit();
osmium::memory::Buffer buffer2(10240);
{
osmium::builder::TagListBuilder tl_builder(buffer2);
tl_builder.add_tag("highway", "primary");
}
buffer2.commit();
const osmium::TagList& tl1 = buffer1.get<const osmium::TagList>(0);
const osmium::TagList& tl2 = buffer2.get<const osmium::TagList>(0);
auto tagit1 = tl1.begin();
auto tagit2 = tl2.begin();
REQUIRE(*tagit1 == *tagit2);
++tagit1;
REQUIRE(!(*tagit1 == *tagit2));
} }
buffer1.commit();
osmium::memory::Buffer buffer2(10240); SECTION("Order") {
{ osmium::memory::Buffer buffer(10240);
osmium::builder::TagListBuilder tl_builder(buffer2); {
tl_builder.add_tag("highway", "primary"); osmium::builder::TagListBuilder tl_builder(buffer);
tl_builder.add_tag("highway", "residential");
tl_builder.add_tag("highway", "primary");
tl_builder.add_tag("name", "Main Street");
tl_builder.add_tag("amenity", "post_box");
}
buffer.commit();
const osmium::TagList& tl = buffer.get<const osmium::TagList>(0);
const osmium::Tag& t1 = *(tl.begin());
const osmium::Tag& t2 = *(std::next(tl.begin(), 1));
const osmium::Tag& t3 = *(std::next(tl.begin(), 2));
const osmium::Tag& t4 = *(std::next(tl.begin(), 3));
REQUIRE(t2 < t1);
REQUIRE(t1 < t3);
REQUIRE(t2 < t3);
REQUIRE(t4 < t1);
} }
buffer2.commit();
const osmium::TagList& tl1 = buffer1.get<const osmium::TagList>(0);
const osmium::TagList& tl2 = buffer2.get<const osmium::TagList>(0);
auto tagit1 = tl1.begin();
auto tagit2 = tl2.begin();
REQUIRE(*tagit1 == *tagit2);
++tagit1;
REQUIRE(!(*tagit1 == *tagit2));
}
SECTION("Order") {
osmium::memory::Buffer buffer(10240);
{
osmium::builder::TagListBuilder tl_builder(buffer);
tl_builder.add_tag("highway", "residential");
tl_builder.add_tag("highway", "primary");
tl_builder.add_tag("name", "Main Street");
tl_builder.add_tag("amenity", "post_box");
}
buffer.commit();
const osmium::TagList& tl = buffer.get<const osmium::TagList>(0);
const osmium::Tag& t1 = *(tl.begin());
const osmium::Tag& t2 = *(std::next(tl.begin(), 1));
const osmium::Tag& t3 = *(std::next(tl.begin(), 2));
const osmium::Tag& t4 = *(std::next(tl.begin(), 3));
REQUIRE(t2 < t1);
REQUIRE(t1 < t3);
REQUIRE(t2 < t3);
REQUIRE(t4 < t1);
}
} }

View File

@ -6,71 +6,71 @@
TEST_CASE("tag_list") { TEST_CASE("tag_list") {
SECTION("can_be_created_from_initializer_list") { SECTION("can_be_created_from_initializer_list") {
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, { const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, { "highway", "primary" },
{ "name", "Main Street" }, { "name", "Main Street" },
{ "source", "GPS" } { "source", "GPS" }
}); });
REQUIRE(osmium::item_type::tag_list == tl.type()); REQUIRE(osmium::item_type::tag_list == tl.type());
REQUIRE(3 == tl.size()); REQUIRE(3 == tl.size());
REQUIRE(std::string("highway") == tl.begin()->key()); REQUIRE(std::string("highway") == tl.begin()->key());
REQUIRE(std::string("primary") == tl.begin()->value());
}
SECTION("can_be_created_from_map") {
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list_from_map(buffer, std::map<const char*, const char*>({
{ "highway", "primary" },
{ "name", "Main Street" }
}));
REQUIRE(osmium::item_type::tag_list == tl.type());
REQUIRE(2 == tl.size());
if (std::string("highway") == tl.begin()->key()) {
REQUIRE(std::string("primary") == tl.begin()->value()); REQUIRE(std::string("primary") == tl.begin()->value());
REQUIRE(std::string("name") == std::next(tl.begin(), 1)->key());
REQUIRE(std::string("Main Street") == std::next(tl.begin(), 1)->value());
} else {
REQUIRE(std::string("highway") == std::next(tl.begin(), 1)->key());
REQUIRE(std::string("primary") == std::next(tl.begin(), 1)->value());
REQUIRE(std::string("name") == tl.begin()->key());
REQUIRE(std::string("Main Street") == tl.begin()->value());
} }
}
SECTION("can_be_created_with_callback") { SECTION("can_be_created_from_map") {
osmium::memory::Buffer buffer(10240); osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) { const osmium::TagList& tl = osmium::builder::build_tag_list_from_map(buffer, std::map<const char*, const char*>({
tlb.add_tag("highway", "primary"); { "highway", "primary" },
tlb.add_tag("bridge", "true"); { "name", "Main Street" }
}); }));
REQUIRE(osmium::item_type::tag_list == tl.type()); REQUIRE(osmium::item_type::tag_list == tl.type());
REQUIRE(2 == tl.size()); REQUIRE(2 == tl.size());
REQUIRE(std::string("bridge") == std::next(tl.begin(), 1)->key());
REQUIRE(std::string("true") == std::next(tl.begin(), 1)->value());
}
SECTION("returns_value_by_key") { if (std::string("highway") == tl.begin()->key()) {
osmium::memory::Buffer buffer(10240); REQUIRE(std::string("primary") == tl.begin()->value());
REQUIRE(std::string("name") == std::next(tl.begin(), 1)->key());
REQUIRE(std::string("Main Street") == std::next(tl.begin(), 1)->value());
} else {
REQUIRE(std::string("highway") == std::next(tl.begin(), 1)->key());
REQUIRE(std::string("primary") == std::next(tl.begin(), 1)->value());
REQUIRE(std::string("name") == tl.begin()->key());
REQUIRE(std::string("Main Street") == tl.begin()->value());
}
}
const osmium::TagList& tl = osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) { SECTION("can_be_created_with_callback") {
tlb.add_tag("highway", "primary"); osmium::memory::Buffer buffer(10240);
tlb.add_tag("bridge", "true");
});
REQUIRE(std::string("primary") == tl.get_value_by_key("highway")); const osmium::TagList& tl = osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) {
REQUIRE(nullptr == tl.get_value_by_key("name")); tlb.add_tag("highway", "primary");
REQUIRE(std::string("foo") == tl.get_value_by_key("name", "foo")); tlb.add_tag("bridge", "true");
});
REQUIRE(std::string("true") == tl["bridge"]); REQUIRE(osmium::item_type::tag_list == tl.type());
} REQUIRE(2 == tl.size());
REQUIRE(std::string("bridge") == std::next(tl.begin(), 1)->key());
REQUIRE(std::string("true") == std::next(tl.begin(), 1)->value());
}
SECTION("returns_value_by_key") {
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) {
tlb.add_tag("highway", "primary");
tlb.add_tag("bridge", "true");
});
REQUIRE(std::string("primary") == tl.get_value_by_key("highway"));
REQUIRE(nullptr == tl.get_value_by_key("name"));
REQUIRE(std::string("foo") == tl.get_value_by_key("name", "foo"));
REQUIRE(std::string("true") == tl["bridge"]);
}
} }

View File

@ -36,7 +36,7 @@ TEST_CASE("thread") {
SECTION("can send job to thread pool") { SECTION("can send job to thread pool") {
auto& pool = osmium::thread::Pool::instance(); auto& pool = osmium::thread::Pool::instance();
result = 0; result = 0;
auto future = pool.submit(test_job_ok{}); auto future = pool.submit(test_job_ok {});
// wait a bit for the other thread to get a chance to run // wait a bit for the other thread to get a chance to run
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
@ -50,7 +50,7 @@ TEST_CASE("thread") {
SECTION("can send job to thread pool") { SECTION("can send job to thread pool") {
auto& pool = osmium::thread::Pool::instance(); auto& pool = osmium::thread::Pool::instance();
auto future = pool.submit(test_job_with_result{}); auto future = pool.submit(test_job_with_result {});
REQUIRE(future.get() == 42); REQUIRE(future.get() == 42);
} }
@ -60,7 +60,7 @@ TEST_CASE("thread") {
result = 0; result = 0;
bool got_exception = false; bool got_exception = false;
auto future = pool.submit(test_job_throw{}); auto future = pool.submit(test_job_throw {});
REQUIRE_THROWS_AS(future.get(), std::runtime_error); REQUIRE_THROWS_AS(future.get(), std::runtime_error);
} }

View File

@ -4,30 +4,30 @@
TEST_CASE("Double") { TEST_CASE("Double") {
SECTION("double2string") { SECTION("double2string") {
std::string s1; std::string s1;
osmium::util::double2string(s1, 1.123, 7); osmium::util::double2string(s1, 1.123, 7);
REQUIRE(s1 == "1.123"); REQUIRE(s1 == "1.123");
std::string s2; std::string s2;
osmium::util::double2string(s2, 1.000, 7); osmium::util::double2string(s2, 1.000, 7);
REQUIRE(s2 == "1"); REQUIRE(s2 == "1");
std::string s3; std::string s3;
osmium::util::double2string(s3, 0.0, 7); osmium::util::double2string(s3, 0.0, 7);
REQUIRE(s3 == "0"); REQUIRE(s3 == "0");
std::string s4; std::string s4;
osmium::util::double2string(s4, 0.020, 7); osmium::util::double2string(s4, 0.020, 7);
REQUIRE(s4 == "0.02"); REQUIRE(s4 == "0.02");
std::string s5; std::string s5;
osmium::util::double2string(s5, -0.020, 7); osmium::util::double2string(s5, -0.020, 7);
REQUIRE(s5 == "-0.02"); REQUIRE(s5 == "-0.02");
std::string s6; std::string s6;
osmium::util::double2string(s6, -0.0, 7); osmium::util::double2string(s6, -0.0, 7);
REQUIRE(s6 == "-0"); REQUIRE(s6 == "-0");
} }
} }

View File

@ -6,43 +6,43 @@
TEST_CASE("Options") { TEST_CASE("Options") {
SECTION("set_simple") { SECTION("set_simple") {
osmium::util::Options o; osmium::util::Options o;
o.set("foo", "bar"); o.set("foo", "bar");
REQUIRE("bar" == o.get("foo")); REQUIRE("bar" == o.get("foo"));
REQUIRE("" == o.get("empty")); REQUIRE("" == o.get("empty"));
REQUIRE("default" == o.get("empty", "default")); REQUIRE("default" == o.get("empty", "default"));
REQUIRE(!o.is_true("foo")); REQUIRE(!o.is_true("foo"));
REQUIRE(!o.is_true("empty")); REQUIRE(!o.is_true("empty"));
REQUIRE(1 == o.size()); REQUIRE(1 == o.size());
} }
SECTION("set_from_bool") { SECTION("set_from_bool") {
osmium::util::Options o; osmium::util::Options o;
o.set("t", true); o.set("t", true);
o.set("f", false); o.set("f", false);
REQUIRE("true" == o.get("t")); REQUIRE("true" == o.get("t"));
REQUIRE("false" == o.get("f")); REQUIRE("false" == o.get("f"));
REQUIRE("" == o.get("empty")); REQUIRE("" == o.get("empty"));
REQUIRE(o.is_true("t")); REQUIRE(o.is_true("t"));
REQUIRE(!o.is_true("f")); REQUIRE(!o.is_true("f"));
REQUIRE(2 == o.size()); REQUIRE(2 == o.size());
} }
SECTION("set_from_single_string_with_equals") { SECTION("set_from_single_string_with_equals") {
osmium::util::Options o; osmium::util::Options o;
o.set("foo=bar"); o.set("foo=bar");
REQUIRE("bar" == o.get("foo")); REQUIRE("bar" == o.get("foo"));
REQUIRE(1 == o.size()); REQUIRE(1 == o.size());
} }
SECTION("set_from_single_string_without_equals") { SECTION("set_from_single_string_without_equals") {
osmium::util::Options o; osmium::util::Options o;
o.set("foo"); o.set("foo");
REQUIRE("true" == o.get("foo")); REQUIRE("true" == o.get("foo"));
REQUIRE(o.is_true("foo")); REQUIRE(o.is_true("foo"));
REQUIRE(1 == o.size()); REQUIRE(1 == o.size());
} }
} }

View File

@ -4,54 +4,54 @@
TEST_CASE("split_string") { TEST_CASE("split_string") {
SECTION("split_string string") { SECTION("split_string string") {
std::string str { "foo,baramba,baz" }; std::string str { "foo,baramba,baz" };
std::vector<std::string> result = {"foo", "baramba", "baz"}; std::vector<std::string> result = {"foo", "baramba", "baz"};
REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(result == osmium::split_string(str, ','));
} }
SECTION("split_string string without sep") { SECTION("split_string string without sep") {
std::string str { "foo" }; std::string str { "foo" };
std::vector<std::string> result = {"foo"}; std::vector<std::string> result = {"foo"};
REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(result == osmium::split_string(str, ','));
} }
SECTION("split_string string with empty at end") { SECTION("split_string string with empty at end") {
std::string str { "foo,bar," }; std::string str { "foo,bar," };
std::vector<std::string> result = {"foo", "bar", ""}; std::vector<std::string> result = {"foo", "bar", ""};
REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(result == osmium::split_string(str, ','));
} }
SECTION("split_string string with empty in middle") { SECTION("split_string string with empty in middle") {
std::string str { "foo,,bar" }; std::string str { "foo,,bar" };
std::vector<std::string> result = {"foo", "", "bar"}; std::vector<std::string> result = {"foo", "", "bar"};
REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(result == osmium::split_string(str, ','));
} }
SECTION("split_string string with empty at start") { SECTION("split_string string with empty at start") {
std::string str { ",bar,baz" }; std::string str { ",bar,baz" };
std::vector<std::string> result = {"", "bar", "baz"}; std::vector<std::string> result = {"", "bar", "baz"};
REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(result == osmium::split_string(str, ','));
} }
SECTION("split_string sep") { SECTION("split_string sep") {
std::string str { "," }; std::string str { "," };
std::vector<std::string> result = {"", ""}; std::vector<std::string> result = {"", ""};
REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(result == osmium::split_string(str, ','));
} }
SECTION("split_string empty string") { SECTION("split_string empty string") {
std::string str { "" }; std::string str { "" };
std::vector<std::string> result; std::vector<std::string> result;
REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(result == osmium::split_string(str, ','));
} }
} }