Skip to content

Commit 6a0c731

Browse files
committed
Revert "Refactor: Use fmt builtin functionality to format variants"
This reverts commit 78ae9ee. Grr. The builtin functionality doesn't work for us. It writes any value out as "variant(VALUE)". I thought I had tested this, but apparently I tested the wrong thing.
1 parent 3a8f53b commit 6a0c731

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/format.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#define FMT_HEADER_ONLY
1414
#include <fmt/format.h>
15-
#include <fmt/std.h>
1615

1716
#include <stdexcept>
1817

src/gen/params.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
#include "overloaded.hpp"
1515
#include "pgsql.hpp"
1616

17+
std::string to_string(param_value_t const &value)
18+
{
19+
return std::visit(
20+
overloaded{[](null_param_t) { return std::string{}; },
21+
[](std::string val) { return val; },
22+
[](auto const &val) { return fmt::to_string(val); }},
23+
value);
24+
}
25+
1726
param_value_t params_t::get(std::string const &key) const
1827
{
1928
return m_map.at(key);
@@ -49,7 +58,7 @@ double params_t::get_double(std::string const &key, double default_value) const
4958
return static_cast<double>(std::get<int64_t>(it->second));
5059
}
5160

52-
throw fmt_error("Invalid value '{}' for {}.", it->second, key);
61+
throw fmt_error("Invalid value '{}' for {}.", to_string(it->second), key);
5362
}
5463

5564
std::string params_t::get_string(std::string const &key) const
@@ -58,7 +67,7 @@ std::string params_t::get_string(std::string const &key) const
5867
if (it == m_map.end()) {
5968
throw fmt_error("Missing parameter '{}' on generalizer.", key);
6069
}
61-
return fmt::format("{}", it->second);
70+
return to_string(it->second);
6271
}
6372

6473
std::string params_t::get_string(std::string const &key,
@@ -73,7 +82,7 @@ std::string params_t::get_identifier(std::string const &key) const
7382
if (it == m_map.end()) {
7483
return {};
7584
}
76-
std::string result = fmt::format("{}", it->second);
85+
std::string result = to_string(it->second);
7786
check_identifier(result, key.c_str());
7887
return result;
7988
}
@@ -85,7 +94,7 @@ void params_t::check_identifier_with_default(std::string const &key,
8594
if (it == m_map.end()) {
8695
m_map.emplace(key, std::move(default_value));
8796
} else {
88-
check_identifier(fmt::format("{}", it->second), key.c_str());
97+
check_identifier(to_string(it->second), key.c_str());
8998
}
9099
}
91100

@@ -111,6 +120,6 @@ void write_to_debug_log(params_t const &params, char const *message)
111120
}
112121
log_debug("{}", message);
113122
for (auto const &[key, value] : params) {
114-
log_debug(" {}={}", key, value);
123+
log_debug(" {}={}", key, to_string(value));
115124
}
116125
}

src/gen/params.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ using null_param_t = std::monostate;
2424
using param_value_t =
2525
std::variant<null_param_t, std::string, int64_t, double, bool>;
2626

27+
/// Convert a parameter value into a string.
28+
std::string to_string(param_value_t const &value);
29+
2730
/**
2831
* A collection of parameters.
2932
*/
@@ -76,7 +79,8 @@ class params_t
7679
}
7780

7881
if (!std::holds_alternative<T>(it->second)) {
79-
throw fmt_error("Invalid value '{}' for {}.", it->second, key);
82+
throw fmt_error("Invalid value '{}' for {}.", to_string(it->second),
83+
key);
8084
}
8185
return std::get<T>(it->second);
8286
}

src/gen/template.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
void template_t::set_params(params_t const &params) {
1313
for (auto const &[key, value] : params) {
14-
m_format_store.push_back(fmt::arg(key.c_str(), value));
14+
m_format_store.push_back(fmt::arg(key.c_str(), to_string(value)));
1515
}
1616
}
1717

0 commit comments

Comments
 (0)