Update vendored vtzero dependency to v1.1.0 (#6871)

This commit is contained in:
Dennis Luxen 2024-05-07 22:19:48 +02:00 committed by GitHub
parent 79de092bb2
commit 10237b8761
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
43 changed files with 16229 additions and 9674 deletions

View File

@ -28,10 +28,10 @@ PROTOZERO_PATH="mapbox/protozero"
PROTOZERO_TAG=v1.6.2
VTZERO_PATH="mapbox/vtzero"
VTZERO_TAG=v1.0.1
VTZERO_TAG=v1.1.0
FMT_PATH="fmtlib/fmt"
FMT_TAG=v9.1.0
FMT_TAG=v10.2.1
function update_subtree () {
name=${1^^}

View File

@ -1,5 +1,5 @@
---
Checks: '*,-cert-dcl21-cpp,-cert-err60-cpp,-clang-analyzer-core.CallAndMessage,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-fuchsia-*,-google-runtime-references,-hicpp-no-array-decay,-readability-avoid-const-params-in-decls,-readability-implicit-bool-cast,-readability-implicit-bool-conversion'
Checks: '*,-cert-dcl21-cpp,-cert-err60-cpp,-clang-analyzer-core.CallAndMessage,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-fuchsia-*,-google-runtime-references,-hicpp-no-array-decay,-hicpp-vararg,-misc-non-private-member-variables-in-classes,-modernize-use-trailing-return-type,-readability-avoid-const-params-in-decls,-readability-implicit-bool-cast,-readability-implicit-bool-conversion,-readability-magic-numbers'
#
# Disabled checks:
#
@ -12,6 +12,14 @@ Checks: '*,-cert-dcl21-cpp,-cert-err60-cpp,-clang-analyzer-core.CallAndMessage,-
# clang-analyzer-core.CallAndMessage
# Produces false positives
#
# cppcoreguidelines-avoid-magic-numbers
# readability-magic-numbers
# Not wrong, but many tests just have those
#
# cppcoreguidelines-non-private-member-variables-in-classes
# misc-non-private-member-variables-in-classes
# Can be useful, we use it for some mock classes in tests for instance
#
# cppcoreguidelines-owning-memory
# Don't want to add dependency on gsl library.
#
@ -31,6 +39,12 @@ Checks: '*,-cert-dcl21-cpp,-cert-err60-cpp,-clang-analyzer-core.CallAndMessage,-
# hicpp-no-array-decay
# Limited use and many false positives including for all asserts.
#
# hicpp-vararg
# False positives from Catch2
#
# modernize-use-trailing-return-type
# We are not that modern.
#
# readability-avoid-const-params-in-decls
# Inconsistently complaines about some cases but not others. It is nice
# to have const in parameters if we don't change them just like with any

View File

@ -8,8 +8,6 @@ language: generic
sudo: false
dist: trusty
#-----------------------------------------------------------------------------
# Save common build configurations as shortcuts, so we can reference them later.
@ -33,11 +31,20 @@ addons_shortcuts:
addons_clang50: &clang50
apt:
sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0' ]
packages: [ 'libboost1.55-dev', 'clang-5.0', 'clang-tidy-5.0' ]
packages: [ 'libboost1.55-dev', 'clang-5.0' ]
addons_clang60: &clang60
apt:
sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-6.0' ]
packages: [ 'libboost1.55-dev', 'clang-6.0', 'clang-tidy-6.0' ]
packages: [ 'libboost1.55-dev', 'clang-6.0' ]
addons_clang7: &clang7
apt:
packages: [ 'libboost-dev', 'clang-7' ]
addons_clang8: &clang8
apt:
packages: [ 'libboost-dev', 'clang-8' ]
addons_clang9: &clang9
apt:
packages: [ 'libboost-dev', 'clang-9', 'clang-tidy-9' ]
addons_gcc48: &gcc48
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
@ -54,99 +61,192 @@ addons_shortcuts:
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'libboost1.55-dev', 'g++-6', 'gcc-6' ]
addons_gcc7: &gcc7
apt:
packages: [ 'libboost-dev' ]
addons_gcc8: &gcc8
apt:
packages: [ 'libboost-dev', 'g++-8', 'gcc-8' ]
#-----------------------------------------------------------------------------
matrix:
jobs:
include:
- os: linux
dist: trusty
compiler: "clang-3.5"
env: BUILD='Debug' CC=clang-3.5 CXX=clang++-3.5
addons: *clang35
- os: linux
dist: trusty
compiler: "clang-3.8"
env: BUILD='Debug' CC=clang-3.8 CXX=clang++-3.8
addons: *clang38
- os: linux
dist: trusty
compiler: "clang-3.9"
env: BUILD='Debug' CC=clang-3.9 CXX=clang++-3.9
addons: *clang39
- os: linux
dist: trusty
compiler: "clang-4.0"
env: BUILD='Debug' CC=clang-4.0 CXX=clang++-4.0
addons: *clang40
- os: linux
dist: trusty
compiler: "clang-5.0"
env: BUILD='Debug' CC=clang-5.0 CXX=clang++-5.0
CLANG_TIDY=clang-tidy-5.0
addons: *clang50
- os: linux
compiler: "clang-5.0"
env: BUILD='Release' CC=clang-5.0 CXX=clang++-5.0
addons: *clang50
- os: linux
compiler: "clang-5.0"
env: BUILD='Debug' CC=clang-5.0 CXX=clang++-5.0
CXXFLAGS="-fsanitize=address,undefined,integer -fno-sanitize-recover=all -fno-omit-frame-pointer"
LDFLAGS="-fsanitize=address,undefined,integer"
# LSAN doesn't work on container-based system
sudo: required
addons: *clang50
- os: linux
dist: trusty
compiler: "clang-6.0"
env: BUILD='Debug' CC=clang-6.0 CXX=clang++-6.0
addons: *clang60
- os: linux
dist: bionic
compiler: "clang-7"
env: BUILD='Debug' CC=clang-7 CXX=clang++-7
addons: *clang7
- os: linux
dist: bionic
compiler: "clang-8"
env: BUILD='Debug' CC=clang-8 CXX=clang++-8
addons: *clang8
- os: linux
dist: bionic
compiler: "clang-9"
env: BUILD='Debug' CC=clang-9 CXX=clang++-9
CLANG_TIDY=clang-tidy-9
addons: *clang9
- os: linux
dist: bionic
compiler: "clang-9"
env: BUILD='Release' CC=clang-9 CXX=clang++-9
addons: *clang9
- os: linux
dist: bionic
compiler: "clang-9"
env: BUILD='Debug' CC=clang-9 CXX=clang++-9
CXXFLAGS="-fsanitize=address,undefined,integer -fno-sanitize-recover=all -fno-omit-frame-pointer"
LDFLAGS="-fsanitize=address,undefined,integer"
# LSAN doesn't work on container-based system
sudo: required
addons: *clang9
- os: linux
arch: arm64
dist: bionic
compiler: "clang-9"
env: BUILD='Debug' CC=clang-9 CXX=clang++-9
CXXFLAGS="-fsanitize=address,undefined,integer -fno-sanitize-recover=all -fno-omit-frame-pointer"
LDFLAGS="-fsanitize=address,undefined,integer"
# LSAN doesn't work on container-based system
sudo: required
addons: *clang9
- os: linux
arch: ppc64le
dist: bionic
compiler: "clang-9"
env: BUILD='Debug' CC=clang-9 CXX=clang++-9
CXXFLAGS="-fsanitize=address,undefined,integer -fno-sanitize-recover=all -fno-omit-frame-pointer"
LDFLAGS="-fsanitize=address,undefined,integer"
# LSAN doesn't work on container-based system
sudo: required
addons: *clang9
- os: linux
arch: s390x
dist: bionic
compiler: "clang-9"
env: BUILD='Debug' CC=clang-9 CXX=clang++-9
CXXFLAGS="-fsanitize=address,undefined,integer -fno-sanitize-recover=all -fno-omit-frame-pointer"
LDFLAGS="-fsanitize=address,undefined,integer"
# LSAN doesn't work on container-based system
sudo: required
addons: *clang9
- os: linux
dist: trusty
compiler: "gcc-4.8"
env: BUILD='Debug' CC=gcc-4.8 CXX=g++-4.8
addons: *gcc48
- os: linux
compiler: "gcc-4.9"
env: BUILD='Debug' CC=gcc-4.9 CXX=g++-4.9
COVERAGE=gcov-4.9
CXXFLAGS="--coverage" LDFLAGS="--coverage"
addons: *gcc49
- os: linux
dist: trusty
compiler: "gcc-5"
env: BUILD='Debug' CC=gcc-5 CXX=g++-5
CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0"
addons: *gcc5
- os: linux
dist: trusty
compiler: "gcc-5"
env: BUILD='Debug' CC=gcc-5 CXX=g++-5
CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=1"
addons: *gcc5
- os: linux
dist: trusty
compiler: "gcc-6"
env: BUILD='Debug' CC=gcc-6 CXX=g++-6
addons: *gcc6
- os: linux
compiler: "gcc-6"
env: BUILD='Debug' CC=gcc-6 CXX=g++-6
dist: bionic
compiler: "gcc-7"
env: BUILD='Debug' CC=gcc-7 CXX=g++-7
addons: *gcc7
- os: linux
dist: bionic
compiler: "gcc-8"
env: BUILD='Debug' CC=gcc-8 CXX=g++-8
COVERAGE=gcov-8
CXXFLAGS="--coverage" LDFLAGS="--coverage"
addons: *gcc8
- os: linux
dist: bionic
compiler: "gcc-8"
env: BUILD='Debug' CC=gcc-8 CXX=g++-8
PROTOZERO_DATA_VIEW=std::experimental::string_view
addons: *gcc6
addons: *gcc8
- os: linux
compiler: "gcc-6"
env: BUILD='Release' CC=gcc-6 CXX=g++-6
addons: *gcc6
dist: bionic
compiler: "gcc-8"
env: BUILD='Release' CC=gcc-8 CXX=g++-8
addons: *gcc8
- os: linux
arch: arm64
dist: bionic
compiler: "gcc-8"
env: BUILD='Debug' CC=gcc-8 CXX=g++-8
addons: *gcc8
- os: linux
arch: ppc64le
dist: bionic
compiler: "gcc-8"
env: BUILD='Debug' CC=gcc-8 CXX=g++-8
addons: *gcc8
# Fails with out of memory error
# - os: linux
# arch: s390x
# dist: bionic
# compiler: "gcc-8"
# env: BUILD='Debug' CC=gcc-8 CXX=g++-8
# addons: *gcc8
- os: osx
osx_image: xcode6.4
osx_image: xcode9.4
compiler: clang
env: BUILD='Debug'
- os: osx
osx_image: xcode7.3
osx_image: xcode10.3
compiler: clang
env: BUILD='Debug'
- os: osx
osx_image: xcode8.3
osx_image: xcode11.4
compiler: clang
env: BUILD='Debug'
- os: osx
osx_image: xcode9.1
compiler: clang
env: BUILD='Debug'
- os: osx
osx_image: xcode9.1
osx_image: xcode11.4
compiler: clang
env: BUILD='Release'

View File

@ -14,6 +14,47 @@ This project adheres to [Semantic Versioning](https://semver.org/).
### Fixed
## [1.1.0] - 2020-06-11
### Changed
* Now needs protozero 1.7.0 or above.
* Use `protozero::basic_pbf_builder` to make buffer type configurable. This
allows you to create the final vector tile in any type of buffer, not just
`std::string`. See documentation for details.
* Switch to catch2 for testing.
### Fixed
* Examples `vtzero-create` and `vtzero-streets` now commit features written.
* Various fixes and small cleanups, mostly based on clang-tidy reports.
## [1.0.3] - 2018-07-17
### Added
* New `copy_id()` helper function on feature builder copies ID (if it exists)
from an existing feature.
* New `copy_properties()` helper funtion on feature builder copies all
properties from an existing feature, optionally using a `property_mapper`.
* New `feature::for_each_property_indexes()` member function.
### Fixed
* The example program `vtzero-stats` now catches exceptions and exists with
an error message.
* Fix an assert where a wrong iterator was checked.
## [1.0.2] - 2018-06-26
### Fixed
* `layer_builder::add_feature()` did not work, because it didn't commit
the features it added.
## [1.0.1] - 2018-04-12
### Added
@ -37,8 +78,12 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## [1.0.0] - 2018-03-09
First release
First release
[unreleased]: https://github.com/osmcode/libosmium/compare/v1.1.0...HEAD
[1.1.0]: https://github.com/osmcode/libosmium/compare/v1.0.3...v1.1.0
[1.0.3]: https://github.com/osmcode/libosmium/compare/v1.0.2...v1.0.3
[1.0.2]: https://github.com/osmcode/libosmium/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/osmcode/libosmium/compare/v1.0.0...v1.0.1

View File

@ -15,8 +15,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
project(vtzero)
set(VTZERO_VERSION_MAJOR 1)
set(VTZERO_VERSION_MINOR 0)
set(VTZERO_VERSION_PATCH 1)
set(VTZERO_VERSION_MINOR 1)
set(VTZERO_VERSION_PATCH 0)
set(VTZERO_VERSION
"${VTZERO_VERSION_MAJOR}.${VTZERO_VERSION_MINOR}.${VTZERO_VERSION_PATCH}")
@ -62,7 +62,7 @@ endif()
#
#-----------------------------------------------------------------------------
find_package(Protozero 1.6.0 REQUIRED)
find_package(Protozero 1.7.0 REQUIRED)
include_directories(SYSTEM ${PROTOZERO_INCLUDE_DIR})
@ -75,7 +75,7 @@ find_package(Boost)
#
#-----------------------------------------------------------------------------
message(STATUS "Looking for clang-tidy")
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-6.0 clang-tidy-5.0)
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-10 clang-tidy-9 clang-tidy-8 clang-tidy-7 clang-tidy-6.0 clang-tidy-5.0)
if(CLANG_TIDY)
message(STATUS "Looking for clang-tidy - found ${CLANG_TIDY}")

View File

@ -13,7 +13,7 @@ Implements the [Mapbox Vector Tile Specification 2.x](https://www.mapbox.com/vec
* C++11 compiler (GCC 4.8 or higher, clang 3.5 or higher, ...)
* CMake
* [Protozero](https://github.com/mapbox/protozero) version >= 1.6.0
* [Protozero](https://github.com/mapbox/protozero) version >= 1.7.0
## Build

View File

@ -52,10 +52,5 @@ build_script:
build-appveyor.bat
)
# remove garbage VS messages
# https://help.appveyor.com/discussions/problems/4569-the-target-_convertpdbfiles-listed-in-a-beforetargets-attribute-at-c-does-not-exist-in-the-project-and-will-be-ignored
before_build:
- del "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets"
#-----------------------------------------------------------------------------

View File

@ -9,7 +9,7 @@ SET
ECHO cmake on AppVeyor
cmake -version
ECHO activating VS cmd prompt && CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
ECHO activating VS cmd prompt && CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
IF %ERRORLEVEL% NEQ 0 GOTO ERROR
IF EXIST build ECHO deleting build dir... && RD /Q /S build
@ -21,11 +21,8 @@ IF %ERRORLEVEL% NEQ 0 GOTO ERROR
CD build
ECHO config^: %config%
::This will produce lots of LNK4099 warnings which can be ignored.
::Unfortunately they can't be disabled, see
::https://stackoverflow.com/questions/661606/visual-c-how-to-disable-specific-linker-warnings
SET CMAKE_CMD=cmake .. ^
-LA -G "Visual Studio 14 Win64"
-LA -G "Visual Studio 15 2017 Win64"
ECHO calling^: %CMAKE_CMD%
%CMAKE_CMD%
@ -36,9 +33,7 @@ IF /I "%APPVEYOR%"=="True" SET avlogger=/logger:"C:\Program Files\AppVeyor\Build
msbuild vtzero.sln ^
/p:Configuration=%config% ^
/toolsversion:14.0 ^
/p:Platform=x64 ^
/p:PlatformToolset=v140 %avlogger%
%avlogger%
IF %ERRORLEVEL% NEQ 0 GOTO ERROR
ctest --output-on-failure ^

View File

@ -2044,7 +2044,7 @@ EXTERNAL_PAGES = YES
# interpreter (i.e. the result of 'which perl').
# The default file (with absolute path) is: /usr/bin/perl.
PERL_PATH = /usr/bin/perl
#PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
@ -2066,7 +2066,7 @@ CLASS_DIAGRAMS = YES
# the mscgen tool resides. If left empty the tool is assumed to be found in the
# default search path.
MSCGEN_PATH =
#MSCGEN_PATH =
# You can include diagrams made with dia in doxygen documentation. Doxygen will
# then run dia to produce the diagram and insert it in the documentation. The

View File

@ -65,9 +65,7 @@ while (auto feature = layer.next_feature()) {
if (keep_feature(feature)) {
// instantiate a feature builder as usual and copy id and geometry
vtzero::geometry_feature_builder feature_builder{layer_builder};
if (feature.has_id()) {
feature_builder.set_id(feature.id());
}
feature_builder.copy_id(feature);
feature_builder.set_geometry(feature.geometry());
// now iterate over all properties...

View File

@ -210,8 +210,8 @@ converted into whatever type the value really has.
```cpp
auto property = ...;
std::string pkey = property.key(); // returns a vtzero::data_view which can
// be converted to std::string
auto pkey = std::string(property.key()); // returns a vtzero::data_view which can
// be converted to std::string
property_value pvalue = property.value();
```

View File

@ -140,7 +140,7 @@ you can create your own overload of this function. See the
### Adding a multipoint geometry
Call `add_points()` with the number of points in the geometry as only argument.
Call `add_points()` with the number of points in the geometry as the only argument.
After that call `set_point()` for each of those points. `set_point()` has
multiple overloads just like the `add_point()` method described above.
@ -537,3 +537,29 @@ own functions (for instance when you need to convert from your own types to
vtzero types like with the `mylocation` and `stars` types above) or just use
the functions in the base classes.
## Using a custom buffer type
Usually `std::string` is used as a buffer type:
```cpp
std::string buffer;
tbuilder.serialize(buffer);
```
But you can also use other buffer types supported by Protozero, like
`std::vector<char>`:
```cpp
#include <protozero/buffer_vector.hpp>
std::vector<char> buffer;
tbuilder.serialize(buffer);
```
Or you can use your own buffer types and write special adaptors for it.
See the Protozero documentation for details.
Note that while in theory this allows you to also use fixed-sized buffers
through the `protozero::fixed_sized_buffer_adaptor` class, vtzero will still
use `std::string` for additional buffers internally.

View File

@ -17,85 +17,97 @@
#include <vector>
int main() {
vtzero::tile_builder tile;
vtzero::layer_builder layer_points{tile, "points"};
vtzero::layer_builder layer_lines{tile, "lines"};
vtzero::layer_builder layer_polygons{tile, "polygons"};
try {
vtzero::tile_builder tile;
vtzero::layer_builder layer_points{tile, "points"};
vtzero::layer_builder layer_lines{tile, "lines"};
vtzero::layer_builder layer_polygons{tile, "polygons"};
vtzero::key_index<std::unordered_map> idx{layer_points};
vtzero::key_index<std::unordered_map> idx{layer_points};
{
vtzero::point_feature_builder feature{layer_points};
feature.set_id(1);
feature.add_points(1);
feature.set_point(10, 10);
feature.add_property("foo", "bar");
feature.add_property("x", "y");
feature.rollback();
{
vtzero::point_feature_builder feature{layer_points};
feature.set_id(1);
feature.add_points(1);
feature.set_point(10, 10);
feature.add_property("foo", "bar");
feature.add_property("x", "y");
feature.rollback();
}
const auto some = idx("some");
{
vtzero::point_feature_builder feature{layer_points};
feature.set_id(2);
feature.add_point(20, 20);
feature.add_property(some, "attr");
feature.commit();
}
{
vtzero::point_feature_builder feature{layer_points};
feature.set_id(3);
feature.add_point(20, 20);
feature.add_property(idx("some"), "attr");
feature.commit();
}
{
vtzero::point_feature_builder feature{layer_points};
feature.set_id(4);
feature.add_point(20, 20);
feature.add_property(idx("some"), "otherattr");
feature.commit();
}
vtzero::point_feature_builder feature1{layer_points};
feature1.set_id(5);
feature1.add_point(vtzero::point{20, 20});
feature1.add_property("otherkey", "attr");
feature1.commit();
vtzero::value_index<vtzero::sint_value_type, int32_t, std::unordered_map> maxspeed_index{layer_lines};
{
vtzero::linestring_feature_builder feature{layer_lines};
feature.set_id(6);
feature.add_linestring(3);
feature.set_point(10, 10);
feature.set_point(10, 20);
feature.set_point(vtzero::point{20, 20});
std::vector<vtzero::point> points = {{11, 11}, {12, 13}};
feature.add_linestring_from_container(points);
feature.add_property("highway", "primary");
feature.add_property(std::string{"maxspeed"}, maxspeed_index(50));
feature.commit();
}
{
vtzero::polygon_feature_builder feature{layer_polygons};
feature.set_id(7);
feature.add_ring(5);
feature.set_point(0, 0);
feature.set_point(10, 0);
feature.set_point(10, 10);
feature.set_point(0, 10);
feature.set_point(0, 0);
feature.add_ring(4);
feature.set_point(3, 3);
feature.set_point(3, 5);
feature.set_point(5, 5);
feature.close_ring();
feature.add_property("natural", "wood");
feature.add_property("number_of_trees", vtzero::sint_value_type{23402752});
feature.commit();
}
const auto data = tile.serialize();
write_data_to_file(data, "test.mvt");
} catch (const std::exception& e) {
std::cerr << "Fatal error: " << e.what() << '\n';
return 1;
}
const auto some = idx("some");
{
vtzero::point_feature_builder feature{layer_points};
feature.set_id(2);
feature.add_point(20, 20);
feature.add_property(some, "attr");
}
{
vtzero::point_feature_builder feature{layer_points};
feature.set_id(3);
feature.add_point(20, 20);
feature.add_property(idx("some"), "attr");
}
{
vtzero::point_feature_builder feature{layer_points};
feature.set_id(4);
feature.add_point(20, 20);
feature.add_property(idx("some"), "otherattr");
}
vtzero::point_feature_builder feature1{layer_points};
feature1.set_id(5);
feature1.add_point(vtzero::point{20, 20});
feature1.add_property("otherkey", "attr");
feature1.commit();
vtzero::value_index<vtzero::sint_value_type, int32_t, std::unordered_map> maxspeed_index{layer_lines};
{
vtzero::linestring_feature_builder feature{layer_lines};
feature.set_id(6);
feature.add_linestring(3);
feature.set_point(10, 10);
feature.set_point(10, 20);
feature.set_point(vtzero::point{20, 20});
std::vector<vtzero::point> points = {{11, 11}, {12, 13}};
feature.add_linestring_from_container(points);
feature.add_property("highway", "primary");
feature.add_property(std::string{"maxspeed"}, maxspeed_index(50));
}
{
vtzero::polygon_feature_builder feature{layer_polygons};
feature.set_id(7);
feature.add_ring(5);
feature.set_point(0, 0);
feature.set_point(10, 0);
feature.set_point(10, 10);
feature.set_point(0, 10);
feature.set_point(0, 0);
feature.add_ring(4);
feature.set_point(3, 3);
feature.set_point(3, 5);
feature.set_point(5, 5);
feature.close_ring();
feature.add_property("natural", "wood");
feature.add_property("number_of_trees", vtzero::sint_value_type{23402752});
}
const auto data = tile.serialize();
write_data_to_file(data, "test.mvt");
return 0;
}

View File

@ -138,5 +138,7 @@ int main(int argc, char* argv[]) {
out.back() = ' ';
std::cout << '\n' << out << "]\n";
return 0;
}

View File

@ -21,81 +21,88 @@
#include <string>
int main(int argc, char* argv[]) {
std::string filename;
std::string layer_num_or_name;
std::string idstr;
std::string output_file{"filtered.mvt"};
try {
std::string filename;
std::string layer_num_or_name;
std::string idstr;
std::string output_file{"filtered.mvt"};
bool help = false;
bool help = false;
const auto cli
= clara::Opt(output_file, "FILE")
["-o"]["--output"]
("write output to FILE")
| clara::Help(help)
| clara::Arg(filename, "FILENAME").required()
("vector tile")
| clara::Arg(layer_num_or_name, "LAYER-NUM|LAYER-NAME").required()
("layer")
| clara::Arg(idstr, "ID")
("feature_id");
const auto cli
= clara::Opt(output_file, "FILE")
["-o"]["--output"]
("write output to FILE")
| clara::Help(help)
| clara::Arg(filename, "FILENAME").required()
("vector tile")
| clara::Arg(layer_num_or_name, "LAYER-NUM|LAYER-NAME").required()
("layer")
| clara::Arg(idstr, "ID")
("feature_id");
const auto result = cli.parse(clara::Args(argc, argv));
if (!result) {
std::cerr << "Error in command line: " << result.errorMessage() << '\n';
return 1;
}
if (help) {
std::cout << cli
<< "\nFilter contents of vector tile.\n";
return 0;
}
if (filename.empty()) {
std::cerr << "Error in command line: Missing file name of vector tile to read\n";
return 1;
}
if (layer_num_or_name.empty()) {
std::cerr << "Error in command line: Missing layer number or name\n";
return 1;
}
const auto data = read_file(filename);
vtzero::vector_tile tile{data};
auto layer = get_layer(tile, layer_num_or_name);
std::cerr << "Found layer: " << std::string(layer.name()) << "\n";
vtzero::tile_builder tb;
if (idstr.empty()) {
tb.add_existing_layer(layer);
} else {
char* str_end = nullptr;
const int64_t id = std::strtoll(idstr.c_str(), &str_end, 10);
if (str_end != idstr.c_str() + idstr.size()) {
std::cerr << "Feature ID must be numeric.\n";
return 1;
}
if (id < 0) {
std::cerr << "Feature ID must be >= 0.\n";
const auto result = cli.parse(clara::Args(argc, argv));
if (!result) {
std::cerr << "Error in command line: " << result.errorMessage() << '\n';
return 1;
}
const auto feature = layer.get_feature_by_id(static_cast<uint64_t>(id));
if (!feature.valid()) {
std::cerr << "No feature with that id: " << id << '\n';
if (help) {
std::cout << cli
<< "\nFilter contents of vector tile.\n";
return 0;
}
if (filename.empty()) {
std::cerr << "Error in command line: Missing file name of vector tile to read\n";
return 1;
}
vtzero::layer_builder layer_builder{tb, layer};
layer_builder.add_feature(feature);
if (layer_num_or_name.empty()) {
std::cerr << "Error in command line: Missing layer number or name\n";
return 1;
}
const auto data = read_file(filename);
vtzero::vector_tile tile{data};
auto layer = get_layer(tile, layer_num_or_name);
std::cerr << "Found layer: " << std::string(layer.name()) << "\n";
vtzero::tile_builder tb;
if (idstr.empty()) {
tb.add_existing_layer(layer);
} else {
char* str_end = nullptr;
const int64_t id = std::strtoll(idstr.c_str(), &str_end, 10);
if (str_end != idstr.c_str() + idstr.size()) {
std::cerr << "Feature ID must be numeric.\n";
return 1;
}
if (id < 0) {
std::cerr << "Feature ID must be >= 0.\n";
return 1;
}
const auto feature = layer.get_feature_by_id(static_cast<uint64_t>(id));
if (!feature.valid()) {
std::cerr << "No feature with that id: " << id << '\n';
return 1;
}
vtzero::layer_builder layer_builder{tb, layer};
layer_builder.add_feature(feature);
}
std::string output = tb.serialize();
write_data_to_file(output, output_file);
} catch (const std::exception& e) {
std::cerr << "Fatal error: " << e.what() << '\n';
return 1;
}
std::string output = tb.serialize();
write_data_to_file(output, output_file);
return 0;
}

View File

@ -26,7 +26,7 @@ public:
void points_begin(const uint32_t /*count*/) const noexcept {
}
void points_point(const vtzero::point point) const {
static void points_point(const vtzero::point point) {
std::cout << " POINT(" << point.x << ',' << point.y << ")\n";
}
@ -111,7 +111,7 @@ struct print_value {
}; // struct print_value
static void print_layer(vtzero::layer& layer, bool print_tables, bool print_value_types, int& layer_num, int& feature_num) {
static void print_layer(vtzero::layer& layer, bool print_tables, bool print_value_types, int layer_num, int& feature_num) {
std::cout << "=============================================================\n"
<< "layer: " << layer_num << '\n'
<< " name: " << std::string(layer.name()) << '\n'

View File

@ -20,17 +20,23 @@ int main(int argc, char* argv[]) {
return 1;
}
std::string input_file{argv[1]};
const auto data = read_file(input_file);
try {
std::string input_file{argv[1]};
const auto data = read_file(input_file);
vtzero::vector_tile tile{data};
vtzero::vector_tile tile{data};
while (const auto layer = tile.next_layer()) {
std::cout.write(layer.name().data(), static_cast<std::streamsize>(layer.name().size()));
std::cout << ' '
<< layer.num_features() << ' '
<< layer.key_table().size() << ' '
<< layer.value_table().size() << '\n';
while (const auto layer = tile.next_layer()) {
std::cout.write(layer.name().data(), static_cast<std::streamsize>(layer.name().size()));
std::cout << ' '
<< layer.num_features() << ' '
<< layer.key_table().size() << ' '
<< layer.value_table().size() << '\n';
}
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << '\n';
return 1;
}
}
return 0;
}

View File

@ -58,14 +58,14 @@ int main(int argc, char* argv[]) {
while (auto feature = layer.next_feature()) {
if (keep_feature(feature)) {
vtzero::geometry_feature_builder feature_builder{layer_builder};
if (feature.has_id()) {
feature_builder.set_id(feature.id());
}
feature_builder.copy_id(feature);
feature_builder.set_geometry(feature.geometry());
while (auto idxs = feature.next_property_indexes()) {
feature_builder.add_property(mapper(idxs));
}
feature_builder.commit();
}
}
@ -75,5 +75,7 @@ int main(int argc, char* argv[]) {
std::cerr << "Error: " << e.what() << '\n';
return 1;
}
return 0;
}

View File

@ -22,11 +22,12 @@ documentation.
#include "types.hpp"
#include "vector_tile.hpp"
#include <protozero/pbf_builder.hpp>
#include <protozero/basic_pbf_builder.hpp>
#include <cstdlib>
#include <iostream>
#include <memory>
#include <numeric>
#include <string>
#include <type_traits>
#include <utility>
@ -53,7 +54,7 @@ namespace vtzero {
friend class layer_builder;
std::vector<std::unique_ptr<detail::layer_builder_base>> m_layers;
std::vector<std::unique_ptr<detail::layer_builder_impl>> m_layers;
/**
* Add a new layer to the vector tile based on an existing layer. The
@ -63,7 +64,7 @@ namespace vtzero {
* existing layer.
*/
detail::layer_builder_impl* add_layer(const layer& layer) {
const auto ptr = new detail::layer_builder_impl{layer.name(), layer.version(), layer.extent()};
auto* ptr = new detail::layer_builder_impl{layer.name(), layer.version(), layer.extent()};
m_layers.emplace_back(ptr);
return ptr;
}
@ -82,7 +83,7 @@ namespace vtzero {
*/
template <typename TString>
detail::layer_builder_impl* add_layer(TString&& name, uint32_t version, uint32_t extent) {
const auto ptr = new detail::layer_builder_impl{std::forward<TString>(name), version, extent};
auto* ptr = new detail::layer_builder_impl{std::forward<TString>(name), version, extent};
m_layers.emplace_back(ptr);
return ptr;
}
@ -116,7 +117,7 @@ namespace vtzero {
* layer.
*/
void add_existing_layer(data_view&& data) {
m_layers.emplace_back(new detail::layer_builder_existing{std::forward<data_view>(data)});
m_layers.emplace_back(new detail::layer_builder_impl{std::forward<data_view>(data)});
}
/**
@ -135,17 +136,18 @@ namespace vtzero {
* The data will be appended to the specified buffer. The buffer
* doesn't have to be empty.
*
* @tparam TBuffer Type of buffer. Must be std:string or other buffer
* type supported by protozero.
* @param buffer Buffer to append the encoded vector tile to.
*/
void serialize(std::string& buffer) const {
std::size_t estimated_size = 0;
for (const auto& layer : m_layers) {
estimated_size += layer->estimated_size();
}
template <typename TBuffer>
void serialize(TBuffer& buffer) const {
const std::size_t estimated_size = std::accumulate(m_layers.cbegin(), m_layers.cend(), 0ULL, [](std::size_t sum, const std::unique_ptr<detail::layer_builder_impl>& layer) {
return sum + layer->estimated_size();
});
buffer.reserve(buffer.size() + estimated_size);
protozero::pbf_builder<detail::pbf_tile> pbf_tile_builder{buffer};
protozero::basic_pbf_builder<TBuffer, detail::pbf_tile> pbf_tile_builder{buffer};
pbf_tile_builder.reserve(estimated_size);
for (const auto& layer : m_layers) {
layer->build(pbf_tile_builder);
}
@ -156,7 +158,7 @@ namespace vtzero {
* and return it.
*
* If you want to use an existing buffer instead, use the serialize()
* method taking a std::string& as parameter.
* member function taking a TBuffer& as parameter.
*
* @returns std::string Buffer with encoded vector_tile data.
*/
@ -373,7 +375,7 @@ namespace vtzero {
/// Helper function to check size isn't too large
template <typename T>
uint32_t check_num_points(T size) {
if (size >= (1ul << 29u)) {
if (size >= (1UL << 29U)) {
throw geometry_exception{"Maximum of 2^29 - 1 points allowed in geometry"};
}
return static_cast<uint32_t>(size);
@ -420,7 +422,7 @@ namespace vtzero {
* Set the ID of this feature.
*
* You can only call this method once and it must be before calling
* any other method manipulating the geometry.
* any method manipulating the geometry.
*
* @param id The ID.
*/
@ -430,7 +432,27 @@ namespace vtzero {
vtzero_assert(!m_pbf_geometry.valid() &&
!m_pbf_tags.valid() &&
"Call set_id() before setting the geometry or adding properties");
m_feature_writer.add_uint64(detail::pbf_feature::id, id);
set_id_impl(id);
}
/**
* Copy the ID of an existing feature to this feature. If the
* feature doesn't have an ID, no ID is set.
*
* You can only call this method once and it must be before calling
* any method manipulating the geometry.
*
* @param feature The feature to copy the ID from.
*/
void copy_id(const feature& feature) {
vtzero_assert(m_feature_writer.valid() &&
"Can not call copy_id() after commit() or rollback()");
vtzero_assert(!m_pbf_geometry.valid() &&
!m_pbf_tags.valid() &&
"Call copy_id() before setting the geometry or adding properties");
if (feature.has_id()) {
set_id_impl(feature.id());
}
}
/**
@ -448,6 +470,41 @@ namespace vtzero {
add_property_impl(std::forward<TProp>(prop));
}
/**
* Copy all properties of an existing feature to the one being built.
*
* @param feature The feature to copy the properties from.
*/
void copy_properties(const feature& feature) {
vtzero_assert(m_feature_writer.valid() &&
"Can not call copy_properties() after commit() or rollback()");
prepare_to_add_property();
feature.for_each_property([this](const property& prop) {
add_property_impl(prop);
return true;
});
}
/**
* Copy all properties of an existing feature to the one being built
* using a property_mapper.
*
* @tparam TMapper Must be the property_mapper class or something
* equivalent.
* @param feature The feature to copy the properties from.
* @param mapper Instance of the property_mapper class.
*/
template <typename TMapper>
void copy_properties(const feature& feature, TMapper& mapper) {
vtzero_assert(m_feature_writer.valid() &&
"Can not call copy_properties() after commit() or rollback()");
prepare_to_add_property();
feature.for_each_property_indexes([this, &mapper](const index_value_pair& idxs) {
add_property_impl(mapper(idxs));
return true;
});
}
/**
* Add a property to this feature. Can only be called after all the
* methods manipulating the geometry.
@ -607,7 +664,7 @@ namespace vtzero {
"can not call add_points() twice or mix with add_point()");
vtzero_assert(!m_pbf_tags.valid() &&
"add_points() has to be called before properties are added");
vtzero_assert(count > 0 && count < (1ul << 29u) && "add_points() must be called with 0 < count < 2^29");
vtzero_assert(count > 0 && count < (1UL << 29U) && "add_points() must be called with 0 < count < 2^29");
m_num_points.set(count);
m_pbf_geometry = {m_feature_writer, detail::pbf_feature::geometry};
m_pbf_geometry.add_element(detail::command_move_to(count));
@ -750,7 +807,7 @@ namespace vtzero {
"Can not add geometry after commit() or rollback()");
vtzero_assert(!m_pbf_tags.valid() &&
"add_linestring() has to be called before properties are added");
vtzero_assert(count > 1 && count < (1ul << 29u) && "add_linestring() must be called with 1 < count < 2^29");
vtzero_assert(count > 1 && count < (1UL << 29U) && "add_linestring() must be called with 1 < count < 2^29");
m_num_points.assert_is_zero();
if (!m_pbf_geometry.valid()) {
m_pbf_geometry = {m_feature_writer, detail::pbf_feature::geometry};
@ -924,7 +981,7 @@ namespace vtzero {
"Can not add geometry after commit() or rollback()");
vtzero_assert(!m_pbf_tags.valid() &&
"add_ring() has to be called before properties are added");
vtzero_assert(count > 3 && count < (1ul << 29u) && "add_ring() must be called with 3 < count < 2^29");
vtzero_assert(count > 3 && count < (1UL << 29U) && "add_ring() must be called with 3 < count < 2^29");
m_num_points.assert_is_zero();
if (!m_pbf_geometry.valid()) {
m_pbf_geometry = {m_feature_writer, detail::pbf_feature::geometry};
@ -1152,7 +1209,25 @@ namespace vtzero {
vtzero_assert(m_feature_writer.valid() &&
"Can not call set_id() after commit() or rollback()");
vtzero_assert(!m_pbf_tags.valid());
m_feature_writer.add_uint64(detail::pbf_feature::id, id);
set_id_impl(id);
}
/**
* Copy the ID of an existing feature to this feature. If the
* feature doesn't have an ID, no ID is set.
*
* You can only call this function once and it must be before calling
* set_geometry().
*
* @param feature The feature to copy the ID from.
*/
void copy_id(const feature& feature) {
vtzero_assert(m_feature_writer.valid() &&
"Can not call copy_id() after commit() or rollback()");
vtzero_assert(!m_pbf_tags.valid());
if (feature.has_id()) {
set_id_impl(feature.id());
}
}
/**
@ -1204,6 +1279,39 @@ namespace vtzero {
add_property_impl(std::forward<TKey>(key), std::forward<TValue>(value));
}
/**
* Copy all properties of an existing feature to the one being built.
*
* @param feature The feature to copy the properties from.
*/
void copy_properties(const feature& feature) {
vtzero_assert(m_feature_writer.valid() &&
"Can not call copy_properties() after commit() or rollback()");
feature.for_each_property([this](const property& prop) {
add_property_impl(prop);
return true;
});
}
/**
* Copy all properties of an existing feature to the one being built
* using a property_mapper.
*
* @tparam TMapper Must be the property_mapper class or something
* equivalent.
* @param feature The feature to copy the properties from.
* @param mapper Instance of the property_mapper class.
*/
template <typename TMapper>
void copy_properties(const feature& feature, TMapper& mapper) {
vtzero_assert(m_feature_writer.valid() &&
"Can not call copy_properties() after commit() or rollback()");
feature.for_each_property_indexes([this, &mapper](const index_value_pair& idxs) {
add_property_impl(mapper(idxs));
return true;
});
}
/**
* Commit this feature. Call this after all the details of this
* feature have been added. If this is not called, the feature
@ -1249,6 +1357,7 @@ namespace vtzero {
feature_builder.add_property(p);
return true;
});
feature_builder.commit();
}
} // namespace vtzero

View File

@ -20,7 +20,7 @@ documentation.
#include "property_value.hpp"
#include "types.hpp"
#include <protozero/pbf_builder.hpp>
#include <protozero/basic_pbf_builder.hpp>
#include <protozero/pbf_message.hpp>
#include <cstdlib>
@ -32,27 +32,12 @@ namespace vtzero {
namespace detail {
class layer_builder_base {
class layer_builder_impl {
public:
layer_builder_base() noexcept = default;
virtual ~layer_builder_base() noexcept = default;
layer_builder_base(const layer_builder_base&) noexcept = default;
layer_builder_base& operator=(const layer_builder_base&) noexcept = default;
layer_builder_base(layer_builder_base&&) noexcept = default;
layer_builder_base& operator=(layer_builder_base&&) noexcept = default;
virtual std::size_t estimated_size() const = 0;
virtual void build(protozero::pbf_builder<detail::pbf_tile>& pbf_tile_builder) const = 0;
}; // class layer_builder_base
class layer_builder_impl : public layer_builder_base {
// If this layer is copied from an existing layer, this points
// to the data of the original layer. For newly built layers,
// this is empty.
data_view m_data_view{};
// Buffer containing the encoded layer metadata and features
std::string m_data;
@ -63,13 +48,16 @@ namespace vtzero {
// Buffer containing the encoded values table
std::string m_values_data;
protozero::pbf_builder<detail::pbf_layer> m_pbf_message_layer;
protozero::pbf_builder<detail::pbf_layer> m_pbf_message_keys;
protozero::pbf_builder<detail::pbf_layer> m_pbf_message_values;
protozero::pbf_builder<detail::pbf_layer> m_pbf_message_layer{};
protozero::pbf_builder<detail::pbf_layer> m_pbf_message_keys{};
protozero::pbf_builder<detail::pbf_layer> m_pbf_message_values{};
// The number of features in the layer
std::size_t m_num_features = 0;
// Vector tile spec version
uint32_t m_version = 0;
// The number of keys in the keys table
uint32_t m_num_keys = 0;
@ -160,17 +148,24 @@ namespace vtzero {
public:
// This layer should be a copy of an existing layer
explicit layer_builder_impl(const data_view data) :
m_data_view(data) {
}
// This layer is being created from scratch
template <typename TString>
layer_builder_impl(TString&& name, uint32_t version, uint32_t extent) :
m_pbf_message_layer(m_data),
m_pbf_message_keys(m_keys_data),
m_pbf_message_values(m_values_data) {
m_pbf_message_values(m_values_data),
m_version(version) {
m_pbf_message_layer.add_uint32(detail::pbf_layer::version, version);
m_pbf_message_layer.add_string(detail::pbf_layer::name, std::forward<TString>(name));
m_pbf_message_layer.add_uint32(detail::pbf_layer::extent, extent);
}
~layer_builder_impl() noexcept override = default;
~layer_builder_impl() noexcept = default;
layer_builder_impl(const layer_builder_impl&) = delete;
layer_builder_impl& operator=(const layer_builder_impl&) = delete;
@ -178,6 +173,10 @@ namespace vtzero {
layer_builder_impl(layer_builder_impl&&) = default;
layer_builder_impl& operator=(layer_builder_impl&&) = default;
uint32_t version() const noexcept {
return m_version;
}
index_value add_key_without_dup_check(const data_view text) {
m_pbf_message_keys.add_string(detail::pbf_layer::keys, text);
return m_num_keys++;
@ -227,7 +226,14 @@ namespace vtzero {
++m_num_features;
}
std::size_t estimated_size() const override {
std::size_t estimated_size() const {
if (m_data_view.data()) {
// This is a layer created as copy from an existing layer
constexpr const std::size_t estimated_overhead_for_pbf_encoding = 8;
return m_data_view.size() + estimated_overhead_for_pbf_encoding;
}
// This is a layer created from scratch
constexpr const std::size_t estimated_overhead_for_pbf_encoding = 8;
return data().size() +
keys_data().size() +
@ -235,7 +241,15 @@ namespace vtzero {
estimated_overhead_for_pbf_encoding;
}
void build(protozero::pbf_builder<detail::pbf_tile>& pbf_tile_builder) const override {
template <typename TBuffer>
void build(protozero::basic_pbf_builder<TBuffer, detail::pbf_tile>& pbf_tile_builder) const {
if (m_data_view.data()) {
// This is a layer created as copy from an existing layer
pbf_tile_builder.add_bytes(detail::pbf_tile::layers, m_data_view);
return;
}
// This is a layer created from scratch
if (m_num_features > 0) {
pbf_tile_builder.add_bytes_vectored(detail::pbf_tile::layers,
data(),
@ -246,27 +260,6 @@ namespace vtzero {
}; // class layer_builder_impl
class layer_builder_existing : public layer_builder_base {
data_view m_data;
public:
explicit layer_builder_existing(const data_view data) :
m_data(data) {
}
std::size_t estimated_size() const override {
constexpr const std::size_t estimated_overhead_for_pbf_encoding = 8;
return m_data.size() + estimated_overhead_for_pbf_encoding;
}
void build(protozero::pbf_builder<detail::pbf_tile>& pbf_tile_builder) const override {
pbf_tile_builder.add_bytes(detail::pbf_tile::layers, m_data);
}
}; // class layer_builder_existing
} // namespace detail
} // namespace vtzero

View File

@ -259,6 +259,19 @@ namespace vtzero {
template <typename TFunc>
bool for_each_property(TFunc&& func) const;
/**
* Call a function for each key/value index of this feature.
*
* @tparam TFunc The type of the function. It must take a single
* argument of type index_value_pair&& and return a bool.
* If the function returns false, the iteration will be stopped.
* @param func The function to call.
* @returns true if the iteration was completed and false otherwise.
* @pre @code valid() @endcode
*/
template <typename TFunc>
bool for_each_property_indexes(TFunc&& func) const;
}; // class feature
/**

View File

@ -78,6 +78,14 @@ namespace vtzero {
feature_builder_base& operator=(feature_builder_base&&) noexcept = default;
uint32_t version() const noexcept {
return m_layer->version();
}
void set_id_impl(uint64_t id) {
m_feature_writer.add_uint64(detail::pbf_feature::id, id);
}
void add_property_impl(const property& property) {
add_key_internal(property.key());
add_value_internal(property.value());

View File

@ -89,7 +89,7 @@ namespace vtzero {
};
inline constexpr uint32_t command_integer(CommandId id, const uint32_t count) noexcept {
return (static_cast<uint32_t>(id) & 0x7u) | (count << 3u);
return (static_cast<uint32_t>(id) & 0x7U) | (count << 3U);
}
inline constexpr uint32_t command_move_to(const uint32_t count) noexcept {
@ -105,11 +105,11 @@ namespace vtzero {
}
inline constexpr uint32_t get_command_id(const uint32_t command_integer) noexcept {
return command_integer & 0x7u;
return command_integer & 0x7U;
}
inline constexpr uint32_t get_command_count(const uint32_t command_integer) noexcept {
return command_integer >> 3u;
return command_integer >> 3U;
}
// The maximum value for the command count according to the spec.

View File

@ -48,6 +48,10 @@ namespace vtzero {
* @code
* layer.get_feature_by_id(7);
* @endcode
*
* Note that the layer class uses mutable members inside to cache the
* key and value tables. It can not be used safely in several threads
* at once!
*/
class layer {
@ -465,7 +469,7 @@ namespace vtzero {
throw out_of_range_exception{ki};
}
assert(m_property_iterator != m_properties.end());
assert(it != m_properties.end());
const uint32_t vi = *it++;
if (!index_value{vi}.valid()) {
throw out_of_range_exception{vi};
@ -479,6 +483,30 @@ namespace vtzero {
return true;
}
template <typename TFunc>
bool feature::for_each_property_indexes(TFunc&& func) const {
vtzero_assert(valid());
for (auto it = m_properties.begin(); it != m_properties.end();) {
const uint32_t ki = *it++;
if (!index_value{ki}.valid()) {
throw out_of_range_exception{ki};
}
assert(it != m_properties.end());
const uint32_t vi = *it++;
if (!index_value{vi}.valid()) {
throw out_of_range_exception{vi};
}
if (!std::forward<TFunc>(func)(index_value_pair{ki, vi})) {
return false;
}
}
return true;
}
} // namespace vtzero
#endif // VTZERO_LAYER_HPP

View File

@ -12,14 +12,17 @@ documentation.
#include <protozero/pbf_reader.hpp>
#include <array>
#include <cassert>
// @cond internal
// Wrappers for assert() used for testing
#ifndef vtzero_assert
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
# define vtzero_assert(x) assert(x)
#endif
#ifndef vtzero_assert_in_noexcept_function
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
# define vtzero_assert_in_noexcept_function(x) assert(x)
#endif
// @endcond
@ -56,10 +59,10 @@ namespace vtzero {
* Return the name of a GeomType (for debug output etc.)
*/
inline const char* geom_type_name(GeomType type) noexcept {
static const char* names[] = {
"unknown", "point", "linestring", "polygon"
static const std::array<const char*, 4> names = {
{"unknown", "point", "linestring", "polygon"}
};
return names[static_cast<int>(type)]; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
return names[static_cast<std::size_t>(type)]; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
}
/// The property value type as specified in the vector tile spec
@ -77,10 +80,10 @@ namespace vtzero {
* Return the name of a property value type (for debug output etc.)
*/
inline const char* property_value_type_name(property_value_type type) noexcept {
static const char* names[] = {
"", "string", "float", "double", "int", "uint", "sint", "bool"
static const std::array<const char*, 8> names = {
{"", "string", "float", "double", "int", "uint", "sint", "bool"}
};
return names[static_cast<int>(type)]; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
return names[static_cast<std::size_t>(type)]; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
}
namespace detail {
@ -145,7 +148,7 @@ namespace vtzero {
/// @endcond
/// value
float value = 0.0f;
float value = 0.0F;
/// Construct float_value_type with value 0.0
constexpr float_value_type() noexcept = default;

View File

@ -20,10 +20,10 @@ documentation.
#define VTZERO_VERSION_MAJOR 1
/// The minor version number
#define VTZERO_VERSION_MINOR 0
#define VTZERO_VERSION_MINOR 1
/// The patch number
#define VTZERO_VERSION_PATCH 1
#define VTZERO_VERSION_PATCH 0
/// The complete version number
#define VTZERO_VERSION_CODE \
@ -31,6 +31,6 @@ documentation.
VTZERO_VERSION_PATCH)
/// Version number as string
#define VTZERO_VERSION_STRING "1.0.1"
#define VTZERO_VERSION_STRING "1.1.0"
#endif // VTZERO_VERSION_HPP

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@
#include <string>
static std::string open_tile(const std::string& path) {
const auto fixtures_dir = std::getenv("FIXTURES_DIR");
const auto* fixtures_dir = std::getenv("FIXTURES_DIR");
if (fixtures_dir == nullptr) {
std::cerr << "Set FIXTURES_DIR environment variable to the directory where the mvt fixtures are!\n";
std::exit(2);
@ -25,8 +25,8 @@ static std::string open_tile(const std::string& path) {
throw std::runtime_error{"could not open: '" + path + "'"};
}
const std::string message{std::istreambuf_iterator<char>(stream.rdbuf()),
std::istreambuf_iterator<char>()};
std::string message{std::istreambuf_iterator<char>(stream.rdbuf()),
std::istreambuf_iterator<char>()};
stream.close();
return message;
@ -187,7 +187,7 @@ TEST_CASE("MVT test 004: Tile with single point with missing geometry") {
std::string buffer{open_tile("004/tile.mvt")};
vtzero::vector_tile tile{buffer};
REQUIRE_THROWS_AS(check_layer(tile), const vtzero::format_exception&);
REQUIRE_THROWS_AS(check_layer(tile), vtzero::format_exception);
}
TEST_CASE("MVT test 005: Tile with single point with broken tags array") {
@ -199,7 +199,7 @@ TEST_CASE("MVT test 005: Tile with single point with broken tags array") {
auto layer = tile.next_layer();
REQUIRE_FALSE(layer.empty());
REQUIRE_THROWS_AS(layer.next_feature(), const vtzero::format_exception&);
REQUIRE_THROWS_AS(layer.next_feature(), vtzero::format_exception);
}
TEST_CASE("MVT test 006: Tile with single point with invalid GeomType") {
@ -210,7 +210,7 @@ TEST_CASE("MVT test 006: Tile with single point with invalid GeomType") {
auto layer = tile.next_layer();
REQUIRE_FALSE(layer.empty());
REQUIRE_THROWS_AS(layer.next_feature(), const vtzero::format_exception&);
REQUIRE_THROWS_AS(layer.next_feature(), vtzero::format_exception);
}
TEST_CASE("MVT test 007: Layer version as string instead of as an int") {
@ -218,7 +218,7 @@ TEST_CASE("MVT test 007: Layer version as string instead of as an int") {
vtzero::vector_tile tile{buffer};
REQUIRE(tile.count_layers() == 1);
REQUIRE_THROWS_AS(tile.get_layer(0), const vtzero::format_exception&);
REQUIRE_THROWS_AS(tile.get_layer(0), vtzero::format_exception);
}
TEST_CASE("MVT test 008: Tile layer extent encoded as string") {
@ -226,7 +226,7 @@ TEST_CASE("MVT test 008: Tile layer extent encoded as string") {
vtzero::vector_tile tile{buffer};
REQUIRE(tile.count_layers() == 1);
REQUIRE_THROWS_AS(tile.next_layer(), const vtzero::format_exception&);
REQUIRE_THROWS_AS(tile.next_layer(), vtzero::format_exception);
}
TEST_CASE("MVT test 009: Tile layer extent missing") {
@ -254,7 +254,7 @@ TEST_CASE("MVT test 010: Tile layer value is encoded as int, but pretends to be
REQUIRE_FALSE(layer.empty());
const auto pv = layer.value(0);
REQUIRE_THROWS_AS(pv.type(), const vtzero::format_exception&);
REQUIRE_THROWS_AS(pv.type(), vtzero::format_exception);
}
TEST_CASE("MVT test 011: Tile layer value is encoded as unknown type") {
@ -266,7 +266,7 @@ TEST_CASE("MVT test 011: Tile layer value is encoded as unknown type") {
REQUIRE_FALSE(layer.empty());
const auto pv = layer.value(0);
REQUIRE_THROWS_AS(pv.type(), const vtzero::format_exception&);
REQUIRE_THROWS_AS(pv.type(), vtzero::format_exception);
}
TEST_CASE("MVT test 012: Unknown layer version") {
@ -274,7 +274,7 @@ TEST_CASE("MVT test 012: Unknown layer version") {
vtzero::vector_tile tile{buffer};
REQUIRE(tile.count_layers() == 1);
REQUIRE_THROWS_AS(tile.next_layer(), const vtzero::version_exception&);
REQUIRE_THROWS_AS(tile.next_layer(), vtzero::version_exception);
}
TEST_CASE("MVT test 013: Tile with key in table encoded as int") {
@ -282,7 +282,7 @@ TEST_CASE("MVT test 013: Tile with key in table encoded as int") {
vtzero::vector_tile tile{buffer};
REQUIRE(tile.count_layers() == 1);
REQUIRE_THROWS_AS(tile.next_layer(), const vtzero::format_exception&);
REQUIRE_THROWS_AS(tile.next_layer(), vtzero::format_exception);
}
TEST_CASE("MVT test 014: Tile layer without a name") {
@ -290,7 +290,7 @@ TEST_CASE("MVT test 014: Tile layer without a name") {
vtzero::vector_tile tile{buffer};
REQUIRE(tile.count_layers() == 1);
REQUIRE_THROWS_AS(tile.next_layer(), const vtzero::format_exception&);
REQUIRE_THROWS_AS(tile.next_layer(), vtzero::format_exception);
}
TEST_CASE("MVT test 015: Two layers with the same name") {
@ -444,8 +444,8 @@ TEST_CASE("MVT test 023: Invalid layer: missing layer name") {
vtzero::vector_tile tile{buffer};
REQUIRE(tile.count_layers() == 1);
REQUIRE_THROWS_AS(tile.next_layer(), const vtzero::format_exception&);
REQUIRE_THROWS_AS(tile.get_layer_by_name("foo"), const vtzero::format_exception&);
REQUIRE_THROWS_AS(tile.next_layer(), vtzero::format_exception);
REQUIRE_THROWS_AS(tile.get_layer_by_name("foo"), vtzero::format_exception);
}
TEST_CASE("MVT test 024: Missing layer version") {
@ -483,7 +483,7 @@ TEST_CASE("MVT test 026: Extra value type") {
const auto pvv = table[0];
REQUIRE(pvv.valid());
REQUIRE_THROWS_AS(pvv.type(), const vtzero::format_exception&);
REQUIRE_THROWS_AS(pvv.type(), vtzero::format_exception);
}
TEST_CASE("MVT test 027: Layer with unused bool property value") {
@ -509,7 +509,7 @@ TEST_CASE("MVT test 030: Two geometry fields") {
auto layer = tile.next_layer();
REQUIRE_FALSE(layer.empty());
REQUIRE_THROWS_AS(layer.next_feature(), const vtzero::format_exception&);
REQUIRE_THROWS_AS(layer.next_feature(), vtzero::format_exception);
}
TEST_CASE("MVT test 032: Layer with single feature with string property value") {
@ -535,6 +535,18 @@ TEST_CASE("MVT test 032: Layer with single feature with string property value")
REQUIRE(ii.key().value() == 0);
REQUIRE(ii.value().value() == 0);
REQUIRE_FALSE(feature.next_property_indexes());
int32_t sum = 0;
int32_t count = 0;
feature.for_each_property_indexes([&](vtzero::index_value_pair&& ivp) {
sum += ivp.key().value();
sum += ivp.value().value();
++count;
return true;
});
REQUIRE(sum == 0);
REQUIRE(count == 1);
}
TEST_CASE("MVT test 033: Layer with single feature with float property value") {
@ -634,13 +646,13 @@ TEST_CASE("MVT test 038: Layer with all types of property value") {
REQUIRE(vtab[5].sint_value() == -87948);
REQUIRE(vtab[6].uint_value() == 87948);
REQUIRE_THROWS_AS(vtab[0].bool_value(), const vtzero::type_exception&);
REQUIRE_THROWS_AS(vtab[0].int_value(), const vtzero::type_exception&);
REQUIRE_THROWS_AS(vtab[0].double_value(), const vtzero::type_exception&);
REQUIRE_THROWS_AS(vtab[0].float_value(), const vtzero::type_exception&);
REQUIRE_THROWS_AS(vtab[0].sint_value(), const vtzero::type_exception&);
REQUIRE_THROWS_AS(vtab[0].uint_value(), const vtzero::type_exception&);
REQUIRE_THROWS_AS(vtab[1].string_value(), const vtzero::type_exception&);
REQUIRE_THROWS_AS(vtab[0].bool_value(), vtzero::type_exception);
REQUIRE_THROWS_AS(vtab[0].int_value(), vtzero::type_exception);
REQUIRE_THROWS_AS(vtab[0].double_value(), vtzero::type_exception);
REQUIRE_THROWS_AS(vtab[0].float_value(), vtzero::type_exception);
REQUIRE_THROWS_AS(vtab[0].sint_value(), vtzero::type_exception);
REQUIRE_THROWS_AS(vtab[0].uint_value(), vtzero::type_exception);
REQUIRE_THROWS_AS(vtab[1].string_value(), vtzero::type_exception);
}
TEST_CASE("MVT test 039: Default values are actually encoded in the tile") {
@ -659,7 +671,7 @@ TEST_CASE("MVT test 039: Default values are actually encoded in the tile") {
REQUIRE(feature.geometry_type() == vtzero::GeomType::UNKNOWN);
REQUIRE(feature.empty());
REQUIRE_THROWS_AS(vtzero::decode_geometry(feature.geometry(), geom_handler{}), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(vtzero::decode_geometry(feature.geometry(), geom_handler{}), vtzero::geometry_exception);
}
TEST_CASE("MVT test 040: Feature has tags that point to non-existent Key in the layer.") {
@ -671,7 +683,7 @@ TEST_CASE("MVT test 040: Feature has tags that point to non-existent Key in the
REQUIRE(layer.num_features() == 1);
auto feature = layer.next_feature();
REQUIRE(feature.num_properties() == 1);
REQUIRE_THROWS_AS(feature.next_property(), const vtzero::out_of_range_exception&);
REQUIRE_THROWS_AS(feature.next_property(), vtzero::out_of_range_exception);
}
TEST_CASE("MVT test 040: Feature has tags that point to non-existent Key in the layer decoded using next_property_indexes().") {
@ -683,7 +695,7 @@ TEST_CASE("MVT test 040: Feature has tags that point to non-existent Key in the
REQUIRE(layer.num_features() == 1);
auto feature = layer.next_feature();
REQUIRE(feature.num_properties() == 1);
REQUIRE_THROWS_AS(feature.next_property_indexes(), const vtzero::out_of_range_exception&);
REQUIRE_THROWS_AS(feature.next_property_indexes(), vtzero::out_of_range_exception);
}
TEST_CASE("MVT test 041: Tags encoded as floats instead of as ints") {
@ -694,7 +706,7 @@ TEST_CASE("MVT test 041: Tags encoded as floats instead of as ints") {
auto layer = tile.next_layer();
REQUIRE(layer.num_features() == 1);
auto feature = layer.next_feature();
REQUIRE_THROWS_AS(feature.next_property(), const vtzero::out_of_range_exception&);
REQUIRE_THROWS_AS(feature.next_property(), vtzero::out_of_range_exception);
}
TEST_CASE("MVT test 042: Feature has tags that point to non-existent Value in the layer.") {
@ -706,7 +718,7 @@ TEST_CASE("MVT test 042: Feature has tags that point to non-existent Value in th
REQUIRE(layer.num_features() == 1);
auto feature = layer.next_feature();
REQUIRE(feature.num_properties() == 1);
REQUIRE_THROWS_AS(feature.next_property(), const vtzero::out_of_range_exception&);
REQUIRE_THROWS_AS(feature.next_property(), vtzero::out_of_range_exception);
}
TEST_CASE("MVT test 043: A layer with six points that all share the same key but each has a unique value.") {
@ -747,7 +759,7 @@ TEST_CASE("MVT test 044: Geometry field begins with a ClosePath command, which i
REQUIRE(feature);
const auto geometry = feature.geometry();
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), vtzero::geometry_exception);
}
TEST_CASE("MVT test 045: Invalid point geometry that includes a MoveTo command and only half of the xy coordinates") {
@ -762,7 +774,7 @@ TEST_CASE("MVT test 045: Invalid point geometry that includes a MoveTo command a
REQUIRE(feature);
const auto geometry = feature.geometry();
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), vtzero::geometry_exception);
REQUIRE_THROWS_WITH(vtzero::decode_geometry(geometry, geom_handler{}), "too few points in geometry");
}
@ -798,7 +810,7 @@ TEST_CASE("MVT test 047: Invalid polygon with wrong ClosePath count 2 (must be c
REQUIRE(feature);
const auto geometry = feature.geometry();
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), vtzero::geometry_exception);
REQUIRE_THROWS_WITH(vtzero::decode_geometry(geometry, geom_handler{}), "ClosePath command count is not 1");
}
@ -814,7 +826,7 @@ TEST_CASE("MVT test 048: Invalid polygon with wrong ClosePath count 0 (must be c
REQUIRE(feature);
const auto geometry = feature.geometry();
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), vtzero::geometry_exception);
REQUIRE_THROWS_WITH(vtzero::decode_geometry(geometry, geom_handler{}), "ClosePath command count is not 1");
}
@ -870,7 +882,7 @@ TEST_CASE("MVT test 051: multipoint with a huge count value, useful for ensuring
REQUIRE(feature);
const auto geometry = feature.geometry();
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), vtzero::geometry_exception);
REQUIRE_THROWS_WITH(vtzero::decode_geometry(geometry, geom_handler{}), "count too large");
}
@ -886,7 +898,7 @@ TEST_CASE("MVT test 052: multipoint with not enough points") {
REQUIRE(feature);
const auto geometry = feature.geometry();
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), vtzero::geometry_exception);
}
TEST_CASE("MVT test 053: clipped square (exact extent): a polygon that covers the entire tile to the exact boundary") {
@ -981,7 +993,7 @@ TEST_CASE("MVT test 057: A point fixture with a gigantic MoveTo command. Can be
REQUIRE(feature);
const auto geometry = feature.geometry();
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), vtzero::geometry_exception);
REQUIRE_THROWS_WITH(vtzero::decode_geometry(geometry, geom_handler{}), "count too large");
}
@ -997,7 +1009,7 @@ TEST_CASE("MVT test 058: A linestring fixture with a gigantic LineTo command") {
REQUIRE(feature);
const auto geometry = feature.geometry();
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(vtzero::decode_geometry(geometry, geom_handler{}), vtzero::geometry_exception);
REQUIRE_THROWS_WITH(vtzero::decode_geometry(geometry, geom_handler{}), "count too large");
}

View File

@ -12,12 +12,15 @@ struct assert_error : public std::runtime_error {
}
};
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define vtzero_assert(x) if (!(x)) { throw assert_error{#x}; }
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define vtzero_assert_in_noexcept_function(x) if (!(x)) { got_an_assert = true; }
extern bool got_an_assert;
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define REQUIRE_ASSERT(x) x; REQUIRE(got_an_assert); got_an_assert = false;
#include <vtzero/output.hpp>

@ -0,0 +1 @@
Subproject commit a351144a7aa6ca4b826295cd4454cd4ce3a6f71f

View File

@ -4,6 +4,10 @@
#include <vtzero/builder.hpp>
#include <vtzero/index.hpp>
#include <vtzero/output.hpp>
#include <vtzero/property_mapper.hpp>
#include <protozero/buffer_fixed.hpp>
#include <protozero/buffer_vector.hpp>
#include <cstdint>
#include <string>
@ -47,8 +51,8 @@ TEST_CASE("Create tile from existing layers") {
}
TEST_CASE("Create layer based on existing layer") {
const auto buffer = load_test_tile();
vtzero::vector_tile tile{buffer};
const auto orig_tile_buffer = load_test_tile();
vtzero::vector_tile tile{orig_tile_buffer};
const auto layer = tile.get_layer_by_name("place_label");
vtzero::tile_builder tbuilder;
@ -58,7 +62,36 @@ TEST_CASE("Create layer based on existing layer") {
fbuilder.add_point(10, 20);
fbuilder.commit();
const std::string data = tbuilder.serialize();
std::string data;
SECTION("use std::string buffer") {
data = tbuilder.serialize();
}
SECTION("use std::string buffer as parameter") {
tbuilder.serialize(data);
}
SECTION("use std::vector<char> buffer as parameter") {
std::vector<char> buffer;
tbuilder.serialize(buffer);
std::copy(buffer.cbegin(), buffer.cend(), std::back_inserter(data));
}
SECTION("use fixed size buffer on stack") {
std::array<char, 1000> buffer = {{0}};
protozero::fixed_size_buffer_adaptor adaptor{buffer};
tbuilder.serialize(adaptor);
std::copy_n(adaptor.data(), adaptor.size(), std::back_inserter(data));
}
SECTION("use fixed size buffer on heap") {
std::vector<char> buffer(1000);
protozero::fixed_size_buffer_adaptor adaptor{buffer};
tbuilder.serialize(adaptor);
std::copy_n(adaptor.data(), adaptor.size(), std::back_inserter(data));
}
vtzero::vector_tile new_tile{data};
const auto new_layer = new_tile.next_layer();
REQUIRE(std::string(new_layer.name()) == "place_label");
@ -131,9 +164,9 @@ TEST_CASE("Committing a feature succeeds after a geometry was added") {
fbuilder.rollback();
}
REQUIRE_THROWS_AS(fbuilder.set_id(10), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_point(20, 20), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_property("x", "y"), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.set_id(10), assert_error);
REQUIRE_THROWS_AS(fbuilder.add_point(20, 20), assert_error);
REQUIRE_THROWS_AS(fbuilder.add_property("x", "y"), assert_error);
}
const std::string data = tbuilder.serialize();
@ -155,13 +188,13 @@ TEST_CASE("Committing a feature fails with assert if no geometry was added") {
SECTION("explicit immediate commit") {
vtzero::point_feature_builder fbuilder{lbuilder};
REQUIRE_THROWS_AS(fbuilder.commit(), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.commit(), assert_error);
}
SECTION("explicit commit after setting id") {
vtzero::point_feature_builder fbuilder{lbuilder};
fbuilder.set_id(2);
REQUIRE_THROWS_AS(fbuilder.commit(), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.commit(), assert_error);
}
}
@ -238,25 +271,22 @@ TEST_CASE("Rollback feature") {
REQUIRE_FALSE(feature);
}
static vtzero::layer next_nonempty_layer(vtzero::vector_tile& tile) {
while (auto layer = tile.next_layer()) {
if (layer && !layer.empty()) {
return layer;
}
}
return vtzero::layer{};
}
static bool vector_tile_equal(const std::string& t1, const std::string& t2) {
vtzero::vector_tile vt1{t1};
vtzero::vector_tile vt2{t2};
for (auto l1 = vt1.next_layer(), l2 = vt2.next_layer();
l1 && l2;
l1 = vt1.next_layer(), l2 = vt2.next_layer()) {
if (l1.empty()) {
l1 = vt1.next_layer();
if (!l1) {
return true;
}
}
if (l2.empty()) {
l2 = vt2.next_layer();
if (!l2) {
return true;
}
}
for (auto l1 = next_nonempty_layer(vt1), l2 = next_nonempty_layer(vt2);
l1 || l2;
l1 = next_nonempty_layer(vt1), l2 = next_nonempty_layer(vt2)) {
if (!l1 ||
!l2 ||
@ -268,18 +298,23 @@ static bool vector_tile_equal(const std::string& t1, const std::string& t2) {
}
for (auto f1 = l1.next_feature(), f2 = l2.next_feature();
f1 && f2;
f1 || f2;
f1 = l1.next_feature(), f2 = l2.next_feature()) {
if (f1.id() != f2.id() ||
if (!f1 ||
!f2 ||
f1.id() != f2.id() ||
f1.geometry_type() != f2.geometry_type() ||
f1.num_properties() != f2.num_properties() ||
f1.geometry().data() != f2.geometry().data()) {
return false;
}
for (auto p1 = f1.next_property(), p2 = f2.next_property();
p1 && p2;
p1 || p2;
p1 = f1.next_property(), p2 = f2.next_property()) {
if (p1.key() != p2.key() || p1.value() != p2.value()) {
if (!p1 ||
!p2 ||
p1.key() != p2.key() ||
p1.value() != p2.value()) {
return false;
}
}
@ -289,6 +324,16 @@ static bool vector_tile_equal(const std::string& t1, const std::string& t2) {
return true;
}
TEST_CASE("vector_tile_equal") {
REQUIRE(vector_tile_equal("", ""));
const auto buffer = load_test_tile();
REQUIRE(buffer.size() == 269388);
REQUIRE(vector_tile_equal(buffer, buffer));
REQUIRE_FALSE(vector_tile_equal(buffer, ""));
}
TEST_CASE("Copy tile") {
const auto buffer = load_test_tile();
vtzero::vector_tile tile{buffer};
@ -316,11 +361,31 @@ TEST_CASE("Copy tile using geometry_feature_builder") {
vtzero::layer_builder lbuilder{tbuilder, layer};
while (auto feature = layer.next_feature()) {
vtzero::geometry_feature_builder fbuilder{lbuilder};
fbuilder.set_id(feature.id());
fbuilder.copy_id(feature);
fbuilder.set_geometry(feature.geometry());
while (auto property = feature.next_property()) {
fbuilder.add_property(property.key(), property.value());
}
fbuilder.copy_properties(feature);
fbuilder.commit();
}
}
const std::string data = tbuilder.serialize();
REQUIRE(vector_tile_equal(buffer, data));
}
TEST_CASE("Copy tile using geometry_feature_builder and property_mapper") {
const auto buffer = load_test_tile();
vtzero::vector_tile tile{buffer};
vtzero::tile_builder tbuilder;
while (auto layer = tile.next_layer()) {
vtzero::layer_builder lbuilder{tbuilder, layer};
vtzero::property_mapper mapper{layer, lbuilder};
while (auto feature = layer.next_feature()) {
vtzero::geometry_feature_builder fbuilder{lbuilder};
fbuilder.copy_id(feature);
fbuilder.set_geometry(feature.geometry());
fbuilder.copy_properties(feature, mapper);
fbuilder.commit();
}
}
@ -360,7 +425,105 @@ TEST_CASE("Copy only point geometries using geometry_feature_builder") {
n = 0;
vtzero::vector_tile result_tile{data};
while (auto layer = result_tile.next_layer()) {
while (layer.next_feature()) {
++n;
}
}
REQUIRE(n == 17);
}
struct points_to_vector {
std::vector<vtzero::point> m_points{};
void points_begin(const uint32_t count) {
m_points.reserve(count);
}
void points_point(const vtzero::point point) {
m_points.push_back(point);
}
void points_end() const {
}
const std::vector<vtzero::point>& result() const {
return m_points;
}
}; // struct points_to_vector
TEST_CASE("Copy only point geometries using point_feature_builder") {
const auto buffer = load_test_tile();
vtzero::vector_tile tile{buffer};
vtzero::tile_builder tbuilder;
int n = 0;
while (auto layer = tile.next_layer()) {
vtzero::layer_builder lbuilder{tbuilder, layer};
while (auto feature = layer.next_feature()) {
vtzero::point_feature_builder fbuilder{lbuilder};
fbuilder.copy_id(feature);
if (feature.geometry().type() == vtzero::GeomType::POINT) {
const auto points = decode_point_geometry(feature.geometry(), points_to_vector{});
fbuilder.add_points_from_container(points);
fbuilder.copy_properties(feature);
fbuilder.commit();
++n;
} else {
fbuilder.rollback();
}
}
}
REQUIRE(n == 17);
const std::string data = tbuilder.serialize();
n = 0;
vtzero::vector_tile result_tile{data};
while (auto layer = result_tile.next_layer()) {
while (layer.next_feature()) {
++n;
}
}
REQUIRE(n == 17);
}
TEST_CASE("Copy only point geometries using point_feature_builder using property_mapper") {
const auto buffer = load_test_tile();
vtzero::vector_tile tile{buffer};
vtzero::tile_builder tbuilder;
int n = 0;
while (auto layer = tile.next_layer()) {
vtzero::layer_builder lbuilder{tbuilder, layer};
vtzero::property_mapper mapper{layer, lbuilder};
while (auto feature = layer.next_feature()) {
vtzero::point_feature_builder fbuilder{lbuilder};
fbuilder.copy_id(feature);
if (feature.geometry().type() == vtzero::GeomType::POINT) {
const auto points = decode_point_geometry(feature.geometry(), points_to_vector{});
fbuilder.add_points_from_container(points);
fbuilder.copy_properties(feature, mapper);
fbuilder.commit();
++n;
} else {
fbuilder.rollback();
}
}
}
REQUIRE(n == 17);
const std::string data = tbuilder.serialize();
n = 0;
vtzero::vector_tile result_tile{data};
while (auto layer = result_tile.next_layer()) {
while (layer.next_feature()) {
++n;
}
}
@ -373,15 +536,15 @@ TEST_CASE("Build point feature from container with too many points") {
// fake container pretending to contain too many points
struct test_container {
std::size_t size() const noexcept {
return 1ul << 29u;
static std::size_t size() noexcept {
return 1UL << 29U;
}
vtzero::point* begin() const noexcept {
static vtzero::point* begin() noexcept {
return nullptr;
}
vtzero::point* end() const noexcept {
static vtzero::point* end() noexcept {
return nullptr;
}
@ -394,7 +557,7 @@ TEST_CASE("Build point feature from container with too many points") {
fbuilder.set_id(1);
test_container tc;
REQUIRE_THROWS_AS(fbuilder.add_points_from_container(tc), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(fbuilder.add_points_from_container(tc), vtzero::geometry_exception);
}
TEST_CASE("Moving a feature builder is allowed") {

View File

@ -95,13 +95,13 @@ TEST_CASE("Calling add_linestring() with bad values throws assert") {
vtzero::linestring_feature_builder fbuilder{lbuilder};
SECTION("0") {
REQUIRE_THROWS_AS(fbuilder.add_linestring(0), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_linestring(0), assert_error);
}
SECTION("1") {
REQUIRE_THROWS_AS(fbuilder.add_linestring(1), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_linestring(1), assert_error);
}
SECTION("2^29") {
REQUIRE_THROWS_AS(fbuilder.add_linestring(1ul << 29u), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_linestring(1UL << 29U), assert_error);
}
}
@ -180,7 +180,7 @@ TEST_CASE("Calling linestring_feature_builder::set_point() throws assert") {
vtzero::layer_builder lbuilder{tbuilder, "test"};
vtzero::linestring_feature_builder fbuilder{lbuilder};
REQUIRE_THROWS_AS(fbuilder.set_point(10, 10), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.set_point(10, 10), assert_error);
}
TEST_CASE("Calling linestring_feature_builder::set_point() with same point throws") {
@ -190,7 +190,7 @@ TEST_CASE("Calling linestring_feature_builder::set_point() with same point throw
fbuilder.add_linestring(2);
fbuilder.set_point(10, 10);
REQUIRE_THROWS_AS(fbuilder.set_point(10, 10), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(fbuilder.set_point(10, 10), vtzero::geometry_exception);
}
TEST_CASE("Calling linestring_feature_builder::set_point() too often throws assert") {
@ -201,7 +201,7 @@ TEST_CASE("Calling linestring_feature_builder::set_point() too often throws asse
fbuilder.add_linestring(2);
fbuilder.set_point(10, 20);
fbuilder.set_point(20, 20);
REQUIRE_THROWS_AS(fbuilder.set_point(30, 20), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.set_point(30, 20), assert_error);
}
TEST_CASE("Add linestring from container") {

View File

@ -106,10 +106,10 @@ TEST_CASE("Calling add_points() with bad values throws assert") {
vtzero::point_feature_builder fbuilder{lbuilder};
SECTION("0") {
REQUIRE_THROWS_AS(fbuilder.add_points(0), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_points(0), assert_error);
}
SECTION("2^29") {
REQUIRE_THROWS_AS(fbuilder.add_points(1ul << 29u), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_points(1UL << 29U), assert_error);
}
}
@ -178,13 +178,13 @@ TEST_CASE("Calling add_point() and then other geometry functions throws assert")
fbuilder.add_point(10, 20);
SECTION("add_point()") {
REQUIRE_THROWS_AS(fbuilder.add_point(10, 20), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_point(10, 20), assert_error);
}
SECTION("add_points()") {
REQUIRE_THROWS_AS(fbuilder.add_points(2), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_points(2), assert_error);
}
SECTION("set_point()") {
REQUIRE_THROWS_AS(fbuilder.set_point(10, 10), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.set_point(10, 10), assert_error);
}
}
@ -193,7 +193,7 @@ TEST_CASE("Calling point_feature_builder::set_point() throws assert") {
vtzero::layer_builder lbuilder{tbuilder, "test"};
vtzero::point_feature_builder fbuilder{lbuilder};
REQUIRE_THROWS_AS(fbuilder.set_point(10, 10), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.set_point(10, 10), assert_error);
}
TEST_CASE("Calling add_points() and then other geometry functions throws assert") {
@ -204,10 +204,10 @@ TEST_CASE("Calling add_points() and then other geometry functions throws assert"
fbuilder.add_points(2);
SECTION("add_point()") {
REQUIRE_THROWS_AS(fbuilder.add_point(10, 20), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_point(10, 20), assert_error);
}
SECTION("add_points()") {
REQUIRE_THROWS_AS(fbuilder.add_points(2), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_points(2), assert_error);
}
}
@ -219,7 +219,7 @@ TEST_CASE("Calling point_feature_builder::set_point() too often throws assert")
fbuilder.add_points(2);
fbuilder.set_point(10, 20);
fbuilder.set_point(20, 20);
REQUIRE_THROWS_AS(fbuilder.set_point(30, 20), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.set_point(30, 20), assert_error);
}
TEST_CASE("Add points from container") {

View File

@ -96,19 +96,19 @@ TEST_CASE("Calling add_ring() with bad values throws assert") {
vtzero::polygon_feature_builder fbuilder{lbuilder};
SECTION("0") {
REQUIRE_THROWS_AS(fbuilder.add_ring(0), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_ring(0), assert_error);
}
SECTION("1") {
REQUIRE_THROWS_AS(fbuilder.add_ring(1), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_ring(1), assert_error);
}
SECTION("2") {
REQUIRE_THROWS_AS(fbuilder.add_ring(2), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_ring(2), assert_error);
}
SECTION("3") {
REQUIRE_THROWS_AS(fbuilder.add_ring(3), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_ring(3), assert_error);
}
SECTION("2^29") {
REQUIRE_THROWS_AS(fbuilder.add_ring(1ul << 29u), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.add_ring(1UL << 29U), assert_error);
}
}
@ -198,10 +198,10 @@ TEST_CASE("Calling polygon_feature_builder::set_point()/close_ring() throws asse
vtzero::polygon_feature_builder fbuilder{lbuilder};
SECTION("set_point") {
REQUIRE_THROWS_AS(fbuilder.set_point(10, 10), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.set_point(10, 10), assert_error);
}
SECTION("close_ring") {
REQUIRE_THROWS_AS(fbuilder.close_ring(), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.close_ring(), assert_error);
}
}
@ -217,10 +217,10 @@ TEST_CASE("Calling polygon_feature_builder::set_point()/close_ring() too often t
fbuilder.set_point(10, 20);
SECTION("set_point") {
REQUIRE_THROWS_AS(fbuilder.set_point(50, 20), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.set_point(50, 20), assert_error);
}
SECTION("close_ring") {
REQUIRE_THROWS_AS(fbuilder.close_ring(), const assert_error&);
REQUIRE_THROWS_AS(fbuilder.close_ring(), assert_error);
}
}
@ -231,7 +231,7 @@ TEST_CASE("Calling polygon_feature_builder::set_point() with same point throws")
fbuilder.add_ring(4);
fbuilder.set_point(10, 10);
REQUIRE_THROWS_AS(fbuilder.set_point(10, 10), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(fbuilder.set_point(10, 10), vtzero::geometry_exception);
}
TEST_CASE("Calling polygon_feature_builder::set_point() creating unclosed ring throws") {
@ -243,7 +243,7 @@ TEST_CASE("Calling polygon_feature_builder::set_point() creating unclosed ring t
fbuilder.set_point(10, 10);
fbuilder.set_point(10, 20);
fbuilder.set_point(20, 20);
REQUIRE_THROWS_AS(fbuilder.set_point(20, 30), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(fbuilder.set_point(20, 30), vtzero::geometry_exception);
}
TEST_CASE("Add polygon from container") {

View File

@ -18,7 +18,7 @@ TEST_CASE("geometry_decoder") {
REQUIRE(decoder.count() == 0);
REQUIRE(decoder.done());
REQUIRE_FALSE(decoder.next_command(vtzero::detail::CommandId::MOVE_TO));
REQUIRE_THROWS_AS(decoder.next_point(), const assert_error&);
REQUIRE_THROWS_AS(decoder.next_point(), assert_error);
}
TEST_CASE("geometry_decoder with point") {
@ -28,10 +28,10 @@ TEST_CASE("geometry_decoder with point") {
REQUIRE(decoder.count() == 0);
REQUIRE_FALSE(decoder.done());
REQUIRE_THROWS_AS(decoder.next_point(), const assert_error&);
REQUIRE_THROWS_AS(decoder.next_point(), assert_error);
SECTION("trying to get LineTo command") {
REQUIRE_THROWS_AS(decoder.next_command(vtzero::detail::CommandId::LINE_TO), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(decoder.next_command(vtzero::detail::CommandId::LINE_TO), vtzero::geometry_exception);
}
SECTION("trying to get ClosePath command") {
@ -40,7 +40,7 @@ TEST_CASE("geometry_decoder with point") {
SECTION("trying to get MoveTo command") {
REQUIRE(decoder.next_command(vtzero::detail::CommandId::MOVE_TO));
REQUIRE_THROWS_AS(decoder.next_command(vtzero::detail::CommandId::MOVE_TO), const assert_error&);
REQUIRE_THROWS_AS(decoder.next_command(vtzero::detail::CommandId::MOVE_TO), assert_error);
REQUIRE(decoder.count() == 1);
REQUIRE(decoder.next_point() == vtzero::point(25, 17));
@ -67,7 +67,7 @@ TEST_CASE("geometry_decoder with incomplete point") {
REQUIRE(decoder.next_command(vtzero::detail::CommandId::MOVE_TO));
REQUIRE(decoder.count() == 1);
REQUIRE_THROWS_AS(decoder.next_point(), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(decoder.next_point(), vtzero::geometry_exception);
}
TEST_CASE("geometry_decoder with multipoint") {
@ -195,7 +195,7 @@ TEST_CASE("geometry_decoder with polygon with wrong ClosePath count 2") {
REQUIRE(decoder.next_command(vtzero::detail::CommandId::LINE_TO));
REQUIRE(decoder.next_point() == vtzero::point(8, 12));
REQUIRE(decoder.next_point() == vtzero::point(20, 34));
REQUIRE_THROWS_AS(decoder.next_command(vtzero::detail::CommandId::CLOSE_PATH), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(decoder.next_command(vtzero::detail::CommandId::CLOSE_PATH), vtzero::geometry_exception);
REQUIRE_THROWS_WITH(decoder.next_command(vtzero::detail::CommandId::CLOSE_PATH), "ClosePath command count is not 1");
}
@ -211,7 +211,7 @@ TEST_CASE("geometry_decoder with polygon with wrong ClosePath count 0") {
REQUIRE(decoder.next_command(vtzero::detail::CommandId::LINE_TO));
REQUIRE(decoder.next_point() == vtzero::point(8, 12));
REQUIRE(decoder.next_point() == vtzero::point(20, 34));
REQUIRE_THROWS_AS(decoder.next_command(vtzero::detail::CommandId::CLOSE_PATH), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(decoder.next_command(vtzero::detail::CommandId::CLOSE_PATH), vtzero::geometry_exception);
REQUIRE_THROWS_WITH(decoder.next_command(vtzero::detail::CommandId::CLOSE_PATH), "ClosePath command count is not 1");
}
@ -312,14 +312,14 @@ TEST_CASE("geometry_decoder decoding linestring with int32 overflow in y coordin
}
TEST_CASE("geometry_decoder with multipoint with a huge count") {
const uint32_t huge_value = (1ul << 29u) - 1;
const uint32_t huge_value = (1UL << 29U) - 1;
const container g = {vtzero::detail::command_move_to(huge_value), 10, 10};
vtzero::detail::geometry_decoder<iterator> decoder{g.cbegin(), g.cend(), g.size() / 2};
REQUIRE(decoder.count() == 0);
REQUIRE_FALSE(decoder.done());
REQUIRE_THROWS_AS(decoder.next_command(vtzero::detail::CommandId::MOVE_TO), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(decoder.next_command(vtzero::detail::CommandId::MOVE_TO), vtzero::geometry_exception);
}
TEST_CASE("geometry_decoder with multipoint with not enough points") {
@ -329,6 +329,6 @@ TEST_CASE("geometry_decoder with multipoint with not enough points") {
REQUIRE(decoder.count() == 0);
REQUIRE_FALSE(decoder.done());
REQUIRE_THROWS_AS(decoder.next_command(vtzero::detail::CommandId::MOVE_TO), const vtzero::geometry_exception&);
REQUIRE_THROWS_AS(decoder.next_command(vtzero::detail::CommandId::MOVE_TO), vtzero::geometry_exception);
}

View File

@ -64,7 +64,7 @@ TEST_CASE("Calling decode_linestring_geometry() with a point geometry fails") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_linestring(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_linestring(dummy_geom_handler{}),
@ -78,7 +78,7 @@ TEST_CASE("Calling decode_linestring_geometry() with a polygon geometry fails")
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_linestring(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_linestring(dummy_geom_handler{}),
@ -92,7 +92,7 @@ TEST_CASE("Calling decode_linestring_geometry() with something other than MoveTo
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_linestring(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_linestring(dummy_geom_handler{}),
@ -106,7 +106,7 @@ TEST_CASE("Calling decode_linestring_geometry() with a count of 0") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_linestring(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_linestring(dummy_geom_handler{}),
@ -120,7 +120,7 @@ TEST_CASE("Calling decode_linestring_geometry() with a count of 2") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_linestring(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_linestring(dummy_geom_handler{}),
@ -135,7 +135,7 @@ TEST_CASE("Calling decode_linestring_geometry() with 2nd command not a LineTo")
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_linestring(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_linestring(dummy_geom_handler{}),
@ -150,7 +150,7 @@ TEST_CASE("Calling decode_linestring_geometry() with LineTo and 0 count") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_linestring(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_linestring(dummy_geom_handler{}),

View File

@ -39,7 +39,7 @@ TEST_CASE("Calling decode_point() with empty input") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_point(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_point(dummy_geom_handler{}),
@ -69,7 +69,7 @@ TEST_CASE("Calling decode_point() with a linestring geometry fails") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_point(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_point(dummy_geom_handler{}),
@ -83,7 +83,7 @@ TEST_CASE("Calling decode_point() with a polygon geometry fails") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_point(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_point(dummy_geom_handler{}),
@ -97,7 +97,7 @@ TEST_CASE("Calling decode_point() with something other than MoveTo command") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_point(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_point(dummy_geom_handler{}),
@ -111,7 +111,7 @@ TEST_CASE("Calling decode_point() with a count of 0") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_point(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_point(dummy_geom_handler{}),
@ -125,7 +125,7 @@ TEST_CASE("Calling decode_point() with more data then expected") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_point(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_point(dummy_geom_handler{}),

View File

@ -74,7 +74,7 @@ TEST_CASE("Calling decode_polygon_geometry() with a point geometry fails") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_polygon(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_polygon(dummy_geom_handler{}),
@ -88,7 +88,7 @@ TEST_CASE("Calling decode_polygon_geometry() with a linestring geometry fails")
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_polygon(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_polygon(dummy_geom_handler{}),
@ -102,7 +102,7 @@ TEST_CASE("Calling decode_polygon_geometry() with something other than MoveTo co
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_polygon(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_polygon(dummy_geom_handler{}),
@ -116,7 +116,7 @@ TEST_CASE("Calling decode_polygon_geometry() with a count of 0") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_polygon(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_polygon(dummy_geom_handler{}),
@ -130,7 +130,7 @@ TEST_CASE("Calling decode_polygon_geometry() with a count of 2") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_polygon(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_polygon(dummy_geom_handler{}),
@ -145,7 +145,7 @@ TEST_CASE("Calling decode_polygon_geometry() with 2nd command not a LineTo") {
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_polygon(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_polygon(dummy_geom_handler{}),
@ -183,7 +183,7 @@ TEST_CASE("Calling decode_polygon_geometry() with 3nd command not a ClosePath")
SECTION("check exception type") {
REQUIRE_THROWS_AS(decoder.decode_polygon(dummy_geom_handler{}),
const vtzero::geometry_exception&);
vtzero::geometry_exception);
}
SECTION("check exception message") {
REQUIRE_THROWS_WITH(decoder.decode_polygon(dummy_geom_handler{}),

View File

@ -14,13 +14,13 @@ TEST_CASE("add keys to layer using key index built into layer") {
vtzero::tile_builder tbuilder;
vtzero::layer_builder lbuilder{tbuilder, "test"};
for (int n = 0; n < max_keys; ++n) {
for (uint32_t n = 0; n < max_keys; ++n) {
const auto key = std::to_string(n);
const auto idx = lbuilder.add_key(key);
REQUIRE(n == idx.value());
}
for (int n = 0; n < max_keys; n += 2) {
for (uint32_t n = 0; n < max_keys; n += 2) {
const auto key = std::to_string(n);
const auto idx = lbuilder.add_key(key);
REQUIRE(n == idx.value());
@ -33,13 +33,13 @@ TEST_CASE("add values to layer using value index built into layer") {
vtzero::tile_builder tbuilder;
vtzero::layer_builder lbuilder{tbuilder, "test"};
for (int n = 0; n < max_values; ++n) {
for (uint32_t n = 0; n < max_values; ++n) {
const auto value = std::to_string(n);
const auto idx = lbuilder.add_value(vtzero::encoded_property_value{value});
REQUIRE(n == idx.value());
}
for (int n = 0; n < max_values; n += 2) {
for (uint32_t n = 0; n < max_values; n += 2) {
const auto value = std::to_string(n);
const auto idx = lbuilder.add_value(vtzero::encoded_property_value{value});
REQUIRE(n == idx.value());

View File

@ -19,14 +19,14 @@ TEST_CASE("default constructed layer") {
REQUIRE(layer.empty());
REQUIRE(layer.num_features() == 0);
REQUIRE_THROWS_AS(layer.key_table(), const assert_error&);
REQUIRE_THROWS_AS(layer.value_table(), const assert_error&);
REQUIRE_THROWS_AS(layer.key_table(), assert_error);
REQUIRE_THROWS_AS(layer.value_table(), assert_error);
REQUIRE_THROWS_AS(layer.key(0), const assert_error&);
REQUIRE_THROWS_AS(layer.value(0), const assert_error&);
REQUIRE_THROWS_AS(layer.key(0), assert_error);
REQUIRE_THROWS_AS(layer.value(0), assert_error);
REQUIRE_THROWS_AS(layer.get_feature_by_id(0), const assert_error&);
REQUIRE_THROWS_AS(layer.next_feature(), const assert_error&);
REQUIRE_THROWS_AS(layer.get_feature_by_id(0), assert_error);
REQUIRE_THROWS_AS(layer.next_feature(), assert_error);
REQUIRE_ASSERT(layer.reset_feature());
}
@ -60,13 +60,13 @@ TEST_CASE("read a layer") {
REQUIRE(layer.key(1) == "oneway");
REQUIRE(layer.key(2) == "osm_id");
REQUIRE(layer.key(3) == "type");
REQUIRE_THROWS_AS(layer.key(4), const vtzero::out_of_range_exception&);
REQUIRE_THROWS_AS(layer.key(4), vtzero::out_of_range_exception);
REQUIRE(layer.value(0).string_value() == "main");
REQUIRE(layer.value(1).int_value() == 0);
REQUIRE(layer.value(2).string_value() == "primary");
REQUIRE(layer.value(3).string_value() == "tertiary");
REQUIRE_THROWS_AS(layer.value(4), const vtzero::out_of_range_exception&);
REQUIRE_THROWS_AS(layer.value(4), vtzero::out_of_range_exception);
}
TEST_CASE("access features in a layer by id") {
@ -99,7 +99,7 @@ TEST_CASE("iterate over all features in a layer") {
std::size_t count = 0;
SECTION("external iterator") {
while (auto feature = layer.next_feature()) {
while (layer.next_feature()) {
++count;
}
}

View File

@ -69,7 +69,7 @@ struct string_conv {
s(std::to_string(value)) {
}
explicit operator std::string() {
explicit operator std::string() const {
return s;
}
@ -94,11 +94,11 @@ TEST_CASE("default constructed property_value") {
}
TEST_CASE("empty property_value") {
char x[1] = {0};
vtzero::data_view dv{x, 0};
char x = 0;
vtzero::data_view dv{&x, 0};
vtzero::property_value pv{dv};
REQUIRE(pv.valid());
REQUIRE_THROWS_AS(pv.type(), const vtzero::format_exception&);
REQUIRE_THROWS_AS(pv.type(), vtzero::format_exception);
}
TEST_CASE("string value") {
@ -128,7 +128,7 @@ TEST_CASE("string value") {
}
TEST_CASE("float value") {
vtzero::encoded_property_value epv{1.2f};
vtzero::encoded_property_value epv{1.2F};
vtzero::property_value pv{epv.data()};
REQUIRE(pv.float_value() == Approx(1.2));
@ -318,8 +318,8 @@ TEST_CASE("create encoded property values from different string types") {
}
TEST_CASE("create encoded property values from different floating point types") {
vtzero::encoded_property_value f1{vtzero::float_value_type{3.2f}};
vtzero::encoded_property_value f2{3.2f};
vtzero::encoded_property_value f1{vtzero::float_value_type{3.2F}};
vtzero::encoded_property_value f2{3.2F};
vtzero::encoded_property_value d1{vtzero::double_value_type{3.2}};
vtzero::encoded_property_value d2{3.2};
@ -361,7 +361,7 @@ TEST_CASE("create encoded property values from different integer types") {
vtzero::property_value pvu{u1.data()};
vtzero::property_value pvs{s1.data()};
REQUIRE(pvi.int_value() == pvu.uint_value());
REQUIRE(pvi.int_value() == static_cast<int64_t>(pvu.uint_value()));
REQUIRE(pvi.int_value() == pvs.sint_value());
}

View File

@ -22,7 +22,7 @@ TEST_CASE("default constructed float_value_type") {
}
TEST_CASE("float_value_type with value") {
float x = 2.7f;
float x = 2.7F;
vtzero::float_value_type v{x};
REQUIRE(v.value == Approx(x));
}

View File

@ -16,8 +16,8 @@ std::string load_test_tile() {
throw std::runtime_error{"could not open: '" + path + "'"};
}
const std::string message{std::istreambuf_iterator<char>(stream.rdbuf()),
std::istreambuf_iterator<char>()};
std::string message{std::istreambuf_iterator<char>(stream.rdbuf()),
std::istreambuf_iterator<char>()};
stream.close();
return message;