Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
---
Checks: '*,-altera-*,-bugprone-easily-swappable-parameters,-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,-llvmlibc-*,-misc-non-private-member-variables-in-classes,-modernize-use-trailing-return-type,-readability-avoid-const-params-in-decls,-readability-function-cognitive-complexity,-readability-identifier-length,-readability-implicit-bool-cast,-readability-implicit-bool-conversion,-readability-magic-numbers'
Checks: '*,-altera-*,-boost-use-ranges,-bugprone-chained-comparison,-bugprone-easily-swappable-parameters,-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,-llvmlibc-*,-misc-non-private-member-variables-in-classes,-modernize-use-trailing-return-type,-readability-avoid-const-params-in-decls,-readability-function-cognitive-complexity,-readability-identifier-length,-readability-implicit-bool-cast,-readability-implicit-bool-conversion,-readability-magic-numbers'
#
# Disabled checks:
#
# altera-*
# Not applicable
#
# boost-use-ranges
# Would introduce extra dependency on boost.
#
# bugprone-chained-comparison
# These are generated by our test framework.
#
# bugprone-easily-swappable-parameters
# When you need them, you need them.
#
Expand Down Expand Up @@ -71,7 +77,6 @@ Checks: '*,-altera-*,-bugprone-easily-swappable-parameters,-cert-dcl21-cpp,-cert
# readability-implicit-bool-conversion
# I don't think this makes the code more readable.
#
WarningsAsErrors: '*'
#WarningsAsErrors: '*'
HeaderFilterRegex: '\/include\/'
AnalyzeTemporaryDtors: false
...
52 changes: 52 additions & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: clang-tidy

on: [ push, pull_request ]

jobs:
clang-tidy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
image: ["debian:bookworm", "debian:testing", "debian:experimental"]
include:
- image: "debian:bookworm"
clang: 15
- image: "debian:testing"
clang: 19
- image: "debian:experimental"
clang: 20
container:
image: ${{ matrix.image }}
env:
BUILD_TYPE: Debug
CC: clang-${{ matrix.clang }}
CXX: clang++-${{ matrix.clang }}
CXXFLAGS: -Wno-c++20-extensions
CPP_VERSION: 14
APT_LISTCHANGES_FRONTEND: none
DEBIAN_FRONTEND: noninteractive
steps:
- name: Prepare container (apt)
run: |
apt-get update -qq
apt-get install -yq \
clang-${{ matrix.clang }} \
clang-tidy-${{ matrix.clang }} \
cmake \
git \
make
shell: bash
- uses: actions/checkout@v4
- uses: ./.github/actions/install-protozero
- uses: ./.github/actions/cmake
- name: Run clang-tidy
run: make clang-tidy | tee vtzero-${{ github.sha }}-clang-tidy-${{ matrix.clang }}.log
shell: bash
working-directory: build
- name: Upload clang-tidy log
uses: actions/upload-artifact@v4
if: always()
with:
name: vtzero-${{ github.sha }}-clang-tidy-${{ matrix.clang }}-log
path: build/vtzero-${{ github.sha }}-clang-tidy-${{ matrix.clang }}.log
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ find_package(Boost)
#
#-----------------------------------------------------------------------------
message(STATUS "Looking for clang-tidy")
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-16 clang-tidy-15 clang-tidy-14)
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-20 clang-tidy-19 clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15)

if(CLANG_TIDY)
message(STATUS "Looking for clang-tidy - found ${CLANG_TIDY}")
Expand Down
1 change: 1 addition & 0 deletions examples/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <limits>
#include <stdexcept>
#include <string>
Expand Down
13 changes: 9 additions & 4 deletions examples/vtzero-check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@

#include <vtzero/vector_tile.hpp>

#include <cstdint>
#include <exception>
#include <iostream>
#include <set>
#include <stdexcept>
#include <string>

namespace {

class result {

int m_return_code = 0;
Expand Down Expand Up @@ -47,7 +50,7 @@ class result {

class CheckGeomHandler {

vtzero::point m_prev_point{};
vtzero::point m_prev_point;
int m_layer_num;
int m_feature_num;
int64_t m_extent;
Expand Down Expand Up @@ -164,13 +167,15 @@ class CheckGeomHandler {

}; // class CheckGeomHandler

} // anonymous namespace

int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " TILE\n";
return 1;
}

std::string input_file{argv[1]};
const std::string input_file{argv[1]};
const auto data = read_file(input_file);

std::set<std::string> layer_names;
Expand All @@ -186,7 +191,7 @@ int main(int argc, char* argv[]) {
result.has_error();
}

std::string name(layer.name());
const std::string name{layer.name()};
if (layer_names.count(name) > 0) {
std::cerr << "Error in layer " << layer_num << ": name is duplicate of previous layer ('" << name << "') (spec 4.1)\n";
result.has_error();
Expand Down
6 changes: 4 additions & 2 deletions examples/vtzero-create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <vtzero/index.hpp>

#include <cstdint>
#include <exception>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
Expand All @@ -21,7 +23,7 @@ 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"};
const vtzero::layer_builder layer_polygons{tile, "polygons"};

vtzero::key_index<std::unordered_map> idx{layer_points};

Expand Down Expand Up @@ -75,7 +77,7 @@ int main() {
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}};
const 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));
Expand Down
5 changes: 5 additions & 0 deletions examples/vtzero-encode-geom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
#include <vtzero/geometry.hpp>

#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>

namespace {

int64_t get_int(const char* arg) {
char* endptr = nullptr;
const int64_t value = std::strtoll(arg, &endptr, 10);
Expand Down Expand Up @@ -76,6 +79,8 @@ uint32_t number(const char* arg) {
return protozero::encode_zigzag32(num);
}

} // anonymous namespace

int main(int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " GEOMETRY ELEMENTS...\n"
Expand Down
6 changes: 3 additions & 3 deletions examples/vtzero-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <iostream>
#include <limits>
#include <string>

int main(int argc, char* argv[]) {
Expand Down Expand Up @@ -64,7 +64,7 @@ int main(int argc, char* argv[]) {
}

const auto data = read_file(filename);
vtzero::vector_tile tile{data};
const vtzero::vector_tile tile{data};

auto layer = get_layer(tile, layer_num_or_name);
std::cerr << "Found layer: " << std::string(layer.name()) << "\n";
Expand Down Expand Up @@ -95,7 +95,7 @@ int main(int argc, char* argv[]) {
layer_builder.add_feature(feature);
}

std::string output = tb.serialize();
const std::string output = tb.serialize();

write_data_to_file(output, output_file);
} catch (const std::exception& e) {
Expand Down
10 changes: 7 additions & 3 deletions examples/vtzero-show.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class geom_handler {

std::string output{};
std::string output;
uint64_t num = 0;

public:
Expand Down Expand Up @@ -119,7 +119,9 @@ 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) {
namespace {

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'
Expand Down Expand Up @@ -171,10 +173,12 @@ static void print_layer(vtzero::layer& layer, bool print_tables, bool print_valu
}
}

static void print_layer_overview(const vtzero::layer& layer) {
void print_layer_overview(const vtzero::layer& layer) {
std::cout << layer.name() << ' ' << layer.num_features() << '\n';
}

} // anonymous namespace

int main(int argc, char* argv[]) {
std::string filename;
std::string layer_num_or_name;
Expand Down
11 changes: 8 additions & 3 deletions examples/vtzero-stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@

#include <vtzero/vector_tile.hpp>

#include <cstdlib>
#include <exception>
#include <iostream>
#include <stdexcept>
#include <string>

static std::size_t geometries_size(const vtzero::layer& layer) {
namespace {

std::size_t geometries_size(const vtzero::layer& layer) {
std::size_t sum = 0;

layer.for_each_feature([&sum](vtzero::feature&& feature) {
Expand All @@ -25,6 +28,8 @@ static std::size_t geometries_size(const vtzero::layer& layer) {
return sum;
}

} // anonymous namespace

int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " TILE\n";
Expand All @@ -33,7 +38,7 @@ int main(int argc, char* argv[]) {

std::cout << "layer,num_features,raw_size,raw_geometries_size,key_table_size,value_table_size\n";
try {
std::string input_file{argv[1]};
const std::string input_file{argv[1]};
const auto data = read_file(input_file);

vtzero::vector_tile tile{data};
Expand Down
15 changes: 10 additions & 5 deletions examples/vtzero-streets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
#include <vtzero/property_mapper.hpp>
#include <vtzero/vector_tile.hpp>

#include <exception>
#include <iostream>
#include <string>

static bool keep_feature(const vtzero::feature& feature) {
namespace {

bool keep_feature(const vtzero::feature& feature) {
static const std::string key{"class"};
static const std::string val{"street"};

Expand All @@ -30,19 +33,21 @@ static bool keep_feature(const vtzero::feature& feature) {
return found;
}

} // anonymous namespace

int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " TILE\n";
return 1;
}

std::string input_file{argv[1]};
std::string output_file{"streets.mvt"};
const std::string input_file{argv[1]};
const std::string output_file{"streets.mvt"};

const auto data = read_file(input_file);

try {
vtzero::vector_tile tile{data};
const vtzero::vector_tile tile{data};

auto layer = get_layer(tile, "road_label");
if (!layer) {
Expand All @@ -69,7 +74,7 @@ int main(int argc, char* argv[]) {
}
}

std::string output = tb.serialize();
const std::string output = tb.serialize();
write_data_to_file(output, output_file);
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << '\n';
Expand Down
6 changes: 3 additions & 3 deletions include/vtzero/builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ namespace vtzero {
}

template <typename T>
using is_layer = std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, layer>;
using is_layer = std::is_same<std::remove_cv_t<std::remove_reference_t<T>>, layer>;

public:

Expand All @@ -213,7 +213,7 @@ namespace vtzero {
* @param version The vector tile spec version of the new layer.
* @param extent The extent of the new layer.
*/
template <typename TString, typename std::enable_if<!is_layer<TString>::value, int>::type = 0>
template <typename TString, typename std::enable_if_t<!is_layer<TString>::value, int> = 0>
layer_builder(vtzero::tile_builder& tile, TString&& name, uint32_t version = 2, uint32_t extent = 4096) :
m_layer(tile.add_layer(std::forward<TString>(name), version, extent)) {
}
Expand Down Expand Up @@ -359,7 +359,7 @@ namespace vtzero {
protected:

/// Encoded geometry.
protozero::packed_field_uint32 m_pbf_geometry{};
protozero::packed_field_uint32 m_pbf_geometry;

/// Number of points still to be set for the geometry to be complete.
countdown_value m_num_points;
Expand Down
8 changes: 4 additions & 4 deletions include/vtzero/builder_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace vtzero {
// 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{};
data_view m_data_view;

// Buffer containing the encoded layer metadata and features
std::string m_data;
Expand All @@ -48,9 +48,9 @@ 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;
Expand Down
Loading
Loading