Skip to content

Commit

Permalink
Remove bool argument and add default value for handler
Browse files Browse the repository at this point in the history
  • Loading branch information
9999years committed Feb 9, 2024
1 parent e22cbab commit 2213b3d
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/libutil/config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,11 @@ protected:
template<typename T>
struct SettingHandler
{
/**
* The `bool` argument is `true` if the value is being set to the default
* value.
*
* The `T &` argument is the value itself.
*/
std::function<void(bool, T &)> fun;
std::function<void(T &)> fun = [](T & val) {};

SettingHandler() = default;

SettingHandler(std::function<void(bool, T &)> && fun)
SettingHandler(std::function<void(T &)> && fun)
: fun(std::move(fun))
{ }

Expand Down Expand Up @@ -294,9 +288,7 @@ public:
, handler(handler)
{
options->addSetting(this);
if (handler) {
handler.fun(true, value);
}
handler.fun(value);
}

operator const T &() const { return value; }
Expand All @@ -314,9 +306,7 @@ public:

virtual void assign(const T & v) {
value = v;
if (handler) {
handler.fun(false, value);
}
handler.fun(value);
}

void operator =(const T & v) { assign(v); }
Expand Down

0 comments on commit 2213b3d

Please sign in to comment.