27#include <unordered_map>
37std::string DefaultToString(
const U& val) {
38 if constexpr ((std::is_signed_v<U> && std::is_integral_v<U>) ||
39 std::is_floating_point_v<U>) {
40 return std::to_string(val);
41 }
else if constexpr (std::is_same_v<U, bool>) {
42 return val ?
"true" :
"false";
43 }
else if constexpr (std::is_same_v<U, std::string> ||
44 std::is_same_v<U, std::string_view>) {
48 std::format(
"Explicit to_str() is required for {}",
typeid(U).name()));
53U DefaultFromString(
const std::string& val) {
54 if constexpr (std::is_same_v<U, std::string>) {
56 }
else if constexpr (std::is_same_v<U, bool>) {
58 }
else if constexpr ((std::is_signed_v<U> && std::is_integral_v<U>) ||
59 std::is_floating_point_v<U>) {
60 ICEBERG_ASSIGN_OR_THROW(
auto res, StringUtils::ParseNumber<U>(val));
64 std::format(
"Explicit from_str() is required for {}",
typeid(U).name()));
69template <
class ConcreteConfig>
75 Entry(std::string key, T val,
76 std::function<std::string(
const T&)> to_str = internal::DefaultToString<T>,
77 std::function<T(
const std::string&)> from_str = internal::DefaultFromString<T>)
78 : key_{std::move(key)},
79 default_{std::move(val)},
80 to_str_{std::move(to_str)},
81 from_str_{std::move(from_str)} {}
84 const std::string key_;
86 const std::function<std::string(
const T&)> to_str_;
87 const std::function<T(
const std::string&)> from_str_;
90 friend ConcreteConfig;
93 const std::string& key()
const {
return key_; }
95 const T& value()
const {
return default_; }
100 configs_[entry.key_] = entry.to_str_(val);
104 template <
typename T>
106 configs_.erase(entry.key_);
110 ConfigBase& Reset() {
115 template <
typename T>
116 T Get(
const Entry<T>& entry)
const {
117 auto iter = configs_.find(entry.key_);
118 return iter != configs_.cend() ? entry.from_str_(iter->second) : entry.default_;
121 const std::unordered_map<std::string, std::string>& configs()
const {
return configs_; }
123 std::unordered_map<std::string, std::string>& mutable_configs() {
return configs_; }
128 std::unordered_map<std::string, std::string>
Extract(std::string_view prefix)
const {
129 std::unordered_map<std::string, std::string> extracted;
130 for (
const auto& [key, value] : configs_) {
131 if (key.starts_with(prefix)) {
132 extracted[key.substr(prefix.length())] = value;
139 std::unordered_map<std::string, std::string> configs_;
std::unordered_map< std::string, std::string > Extract(std::string_view prefix) const
Extracts the prefix from the configuration.
Definition config.h:128
static bool EqualsIgnoreCase(std::string_view lhs, std::string_view rhs)
Case-insensitive equality using Unicode simple (1:1) case mapping.
Definition string_util.h:82
Define common Iceberg utility macros.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
Provide string utility helpers.