Skip to content

Commit

Permalink
Add default_func_ field in CommonOption
Browse files Browse the repository at this point in the history
  • Loading branch information
aartdem committed Nov 29, 2023
1 parent f7ff071 commit 3fcf006
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/core/config/common_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@ class CommonOption {
std::optional<T> const default_value_;
typename Option<T>::NormalizeFunc const normalize_func_;
typename Option<T>::ValueCheckFunc const value_check_func_;
typename Option<T>::DefaultFunc const default_func_;

public:
CommonOption(std::string_view name, std::string_view description,
std::optional<T> default_value = std::nullopt,
typename Option<T>::NormalizeFunc normalize_func = nullptr,
typename Option<T>::ValueCheckFunc value_check_func = nullptr)
typename Option<T>::ValueCheckFunc value_check_func = nullptr,
typename Option<T>::DefaultFunc default_func_ = nullptr)
: name_(name),
description_(description),
default_value_(default_value),
normalize_func_(normalize_func),
value_check_func_(value_check_func) {}
value_check_func_(value_check_func),
default_func_(default_func_) {}

[[nodiscard]] Option<T> operator()(T *value_ptr) const {
auto option = default_value_.has_value()
? Option{value_ptr, name_, description_, default_value_.value()}
: Option{value_ptr, name_, description_};
: Option{value_ptr, name_, description_, default_func_};
if (normalize_func_) option.SetNormalizeFunc(normalize_func_);
if (value_check_func_) option.SetValueCheck(value_check_func_);
return option;
Expand Down

0 comments on commit 3fcf006

Please sign in to comment.