Skip to content

Commit

Permalink
update fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Feb 21, 2024
1 parent adb7af6 commit 8da0fae
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
[utl]
url=git@github.com:motis-project/utl.git
branch=master
commit=b81cfdccda166cef3c20dd41b4c9697b4137cea4
commit=483b72b6472978b949fad1882a671e53bde25e66
[miniz]
url=git@github.com:motis-project/miniz.git
branch=master
commit=1edbdece9d71dc65c6ff405572ee37cbdcef7af4
[fmt]
url=git@github.com:motis-project/fmt.git
branch=master
commit=c68ab4be8f3cb0e5c6eb181b3f419622e15e02bd
commit=edb385ac526c24bc917ec4a41bb0edb28f0ca59e
[date]
url=git@github.com:motis-project/date.git
branch=master
Expand Down
6 changes: 3 additions & 3 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
507627293430859032
892648132605722204
cista 04f84b0490e0e91ead20ae6eabed5add8f243ba0
res 7d97784ba785ce8a2677ea77164040fde484fb04
date 26d109612ddb8ba331edba7619a6452667f842bb
fmt c68ab4be8f3cb0e5c6eb181b3f419622e15e02bd
fmt edb385ac526c24bc917ec4a41bb0edb28f0ca59e
zlib fe8e13ffca867612951bc6baf114e5ac8b00f305
boost be5235eb2258d2ec19e32546ab767a62311d9b46
doctest 70e8f76437b76dd5e9c0a2eb9b907df190ab71a0
Expand All @@ -13,5 +13,5 @@ abseil-cpp f2b3825f36e37fddd47c5c395096e9b1e99eca12
protobuf 690e03babf0963d3da9615a2dae0891777842719
unordered_dense 77e91016354e6d8cba24a86c5abb807de2534c02
Catch2 47d56f28a9801911c048d011b375e5631dbb658f
utl b81cfdccda166cef3c20dd41b4c9697b4137cea4
utl 483b72b6472978b949fad1882a671e53bde25e66
wyhash 1e012b57fc2227a9e583a57e2eacb3da99816d99
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
-Wno-undefined-func-template
-Wno-unsafe-buffer-usage
-Wno-c++20-compat
-Wno-reserved-macro-identifier
-Wno-documentation-unknown-command
-Wno-duplicate-enum
-Werror)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(nigiri-compile-options -Wall -Wextra -Werror)
Expand Down
5 changes: 5 additions & 0 deletions include/nigiri/common/interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <ostream>
#include <type_traits>

#include "fmt/ostream.h"

#include "cista/strong.h"

namespace nigiri {
Expand Down Expand Up @@ -112,3 +114,6 @@ template <typename T, typename T1, typename = std::common_type_t<T1, T>>
interval(T, T1) -> interval<std::common_type_t<T, T1>>;

} // namespace nigiri

template <typename T>
struct fmt::formatter<nigiri::interval<T>> : ostream_formatter {};
7 changes: 6 additions & 1 deletion include/nigiri/footpath.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "fmt/ostream.h"

#include "utl/verify.h"

#include "cista/reflection/printable.h"
Expand Down Expand Up @@ -65,4 +67,7 @@ inline void serialize(Ctx&, footpath const*, cista::offset_t const) {}
template <typename Ctx>
inline void deserialize(Ctx const&, footpath*) {}

} // namespace nigiri
} // namespace nigiri

template <>
struct fmt::formatter<nigiri::footpath> : ostream_formatter {};
3 changes: 3 additions & 0 deletions include/nigiri/loader/hrd/service/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ struct service {
};

} // namespace nigiri::loader::hrd

template <>
struct fmt::formatter<nigiri::loader::hrd::parser_info> : ostream_formatter {};
5 changes: 5 additions & 0 deletions include/nigiri/location.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <iosfwd>
#include <span>

#include "fmt/ostream.h"

#include "geo/latlng.h"

#include "nigiri/common/it_range.h"
Expand Down Expand Up @@ -37,3 +39,6 @@ struct location {
};

} // namespace nigiri

template <>
struct fmt::formatter<nigiri::location> : ostream_formatter {};
2 changes: 1 addition & 1 deletion include/nigiri/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ inline std::string now() {
template <typename... Args>
void log(log_lvl const lvl,
char const* ctx,
char const* fmt_str,
fmt::format_string<Args...> fmt_str,
Args&&... args) {
if (lvl >= ::nigiri::s_verbosity) {
fmt::print(
Expand Down
20 changes: 20 additions & 0 deletions include/nigiri/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <cinttypes>
#include <variant>

#include "fmt/ostream.h"

#include "date/date.h"
#include "date/tz.h"

Expand Down Expand Up @@ -324,6 +326,24 @@ inline std::ostream& operator<<(std::ostream& out,

} // namespace std::chrono

template <>
struct fmt::formatter<nigiri::duration_t> : ostream_formatter {};

template <>
struct fmt::formatter<nigiri::unixtime_t> : ostream_formatter {};

template <>
struct fmt::formatter<nigiri::debug> : ostream_formatter {};

template <typename T, typename Tag>
struct fmt::formatter<cista::strong<T, Tag>> : ostream_formatter {};

template <typename Ptr>
struct fmt::formatter<cista::basic_string<Ptr>> : ostream_formatter {};

template <std::size_t Size>
struct fmt::formatter<nigiri::bitset<Size>> : ostream_formatter {};

#include <iostream>

namespace nigiri {
Expand Down
20 changes: 14 additions & 6 deletions src/loader/build_footpaths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@

#include "utl/enumerate.h"
#include "utl/equal_ranges_linear.h"
#include "utl/erase_duplicates.h"
#include "utl/erase_if.h"
#include "utl/pairwise.h"
#include "utl/parallel_for.h"
#include "utl/progress_tracker.h"
#include "utl/verify.h"

#include "nigiri/loader/floyd_warshall.h"
#include "nigiri/common/day_list.h"
#include "nigiri/logging.h"
#include "nigiri/rt/frun.h"
#include "nigiri/types.h"
#include "utl/erase_duplicates.h"
#include "utl/erase_if.h"
#include "utl/pairwise.h"
#include "utl/progress_tracker.h"
template <typename T,
template <typename>
typename Ptr,
bool IndexPointers,
typename TemplateSizeType,
class Allocator>
struct fmt::formatter<
cista::basic_vector<T, Ptr, IndexPointers, TemplateSizeType, Allocator>>
: ostream_formatter {};

// #define NIGIRI_BUILD_FOOTPATHS_DEBUG
#if defined(NIGIRI_BUILD_FOOTPATHS_DEBUG)
Expand Down Expand Up @@ -378,8 +387,7 @@ void process_component(timetable& tt,

if (!fgraph[idx_a].empty()) {
utl_verify(fgraph[idx_a].size() == 1,
"invalid size (a): idx_a={}, size={}, data=[{}], "
"idx_b={}, size = {} ",
"invalid size (a): idx_a={}, size={}, data=[{}], idx_b={}",
idx_a, fgraph[idx_a].size(), fgraph[idx_a], idx_b,
fgraph[idx_b].size(), fgraph[idx_b]);

Expand Down
9 changes: 7 additions & 2 deletions src/loader/dir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <variant>
#include <vector>

#include "fmt/ostream.h"

#include "miniz.h"

#include "cista/mmap.h"
Expand All @@ -15,6 +17,9 @@
#include "nigiri/logging.h"
#include "wyhash.h"

template <>
struct fmt::formatter<std::filesystem::path> : ostream_formatter {};

namespace nigiri::loader {

file::content::~content() = default;
Expand Down Expand Up @@ -68,8 +73,8 @@ file fs_dir::get_file(std::filesystem::path const& p) const {
mmap_content& operator=(mmap_content const&) = delete;
explicit mmap_content(std::filesystem::path const& p)
: mmap_{p.string().c_str(), cista::mmap::protection::READ} {
log(log_lvl::info, "loader.fs_dir", "loaded {}: {} bytes", p,
mmap_.size());
log(log_lvl::info, "loader.fs_dir", "loaded {}: {} bytes",
p.generic_string(), mmap_.size());
}
~mmap_content() final = default;
std::string_view get() const final { return mmap_.view(); }
Expand Down
3 changes: 2 additions & 1 deletion src/loader/gtfs/services.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ bitfield calendar_to_bitfield(interval<date::sys_days> const& tt_interval,
log(log_lvl::error, "loader.gtfs.services",
"date {} for service {} out of range [tt_interval={}, calendar={}, "
"iterating={}]",
d, service_name, tt_interval, c.interval_, interval{from, to});
fmt::streamed(d), service_name, tt_interval, c.interval_,
interval{from, to});
break;
}
auto const weekday_index =
Expand Down
6 changes: 2 additions & 4 deletions src/loader/gtfs/trip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ void read_frequencies(trip_data& trips, std::string_view file_content) {
auto const trip_it = trips.trips_.find(t);
if (trip_it == end(trips.trips_)) {
log(log_lvl::error, "loader.gtfs.frequencies",
"frequencies.txt:{}: skipping frequency (trip \"{}\" not "
"found)",
"frequencies.txt: skipping frequency (trip \"{}\" not found)",
t);
return;
}
Expand All @@ -346,8 +345,7 @@ void read_frequencies(trip_data& trips, std::string_view file_content) {
auto const headway_secs = parse<int>(headway_secs_str, -1);
if (headway_secs == -1) {
log(log_lvl::error, "loader.gtfs.frequencies",
"frequencies.txt:{}: skipping frequency (invalid headway secs "
"\"{}\")",
R"(frequencies.txt: skipping frequency (invalid headway secs "{}"))",
headway_secs_str.view());
return;
}
Expand Down
8 changes: 5 additions & 3 deletions src/loader/hrd/load_timetable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ bool applicable(config const& c, dir const& d) {
auto const exists = d.exists(path);
if (!exists) {
log(log_lvl::info, "loader.hrd",
"input={}, missing file for config {}: {}", d.path(),
c.version_.view(), path);
"input={}, missing file for config {}: {}",
d.path().generic_string(), c.version_.view(),
path.generic_string());
}
return exists;
});
Expand Down Expand Up @@ -82,7 +83,8 @@ void load_timetable(source_idx_t const src,
continue;
}

log(log_lvl::info, "loader.hrd.services", "loading {}", path);
log(log_lvl::info, "loader.hrd.services", "loading {}",
path.generic_string());
auto const file = d.get_file(path);
sb.add_services(
c, relative(path, c.fplan_).string().c_str(), file.data(),
Expand Down
10 changes: 5 additions & 5 deletions src/loader/hrd/service/service_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ void service_builder::write_services(source_idx_t const src) {
auto const stops = s.stops(store_);

trip_id_buf_.clear();
fmt::format_to(trip_id_buf_, "{}/{:07}/{}/{:07}/{}/{}",
ref.initial_train_num_, to_idx(stops.front().eva_num_),
s.utc_times_.front().count(),
to_idx(stops.back().eva_num_),
s.utc_times_.back().count(), s.line_info(store_));
fmt::format_to(
std::back_inserter(trip_id_buf_), "{}/{:07}/{}/{:07}/{}/{}",
ref.initial_train_num_, to_idx(stops.front().eva_num_),
s.utc_times_.front().count(), to_idx(stops.back().eva_num_),
s.utc_times_.back().count(), s.line_info(store_));

auto const id = tt_.register_trip_id(
trip_id_buf_, src, ref.display_name(tt_), ref.origin_.dbg_,
Expand Down
2 changes: 1 addition & 1 deletion src/loader/hrd/stamm/station.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void parse_footpaths(config const& c,
auto const duration_int =
parse<int>(line.substr(c.meta_.footpaths_.duration_));
utl::verify(duration_int <= std::numeric_limits<u8_minutes::rep>::max(),
"footpath duration {} > {}",
"footpath duration {} > {}", duration_int,
std::numeric_limits<u8_minutes::rep>::max());
add_footpath(from, to.id_, u8_minutes{duration_int});

Expand Down
2 changes: 1 addition & 1 deletion src/routing/ontrip_train.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace nigiri::routing {
constexpr auto const kTracing = true;

template <typename... Args>
void trace(char const* fmt_str, Args... args) {
void trace(fmt::format_string<Args...> fmt_str, Args... args) {
if constexpr (kTracing) {
fmt::print(std::cout, fmt_str, std::forward<Args&&>(args)...);
}
Expand Down

0 comments on commit 8da0fae

Please sign in to comment.