Commit 061ea836 authored by Anton Likhtarov's avatar Anton Likhtarov Committed by Facebook Github Bot

Expose defaultValue()

Summary:
SettingsMetadata provides a type-erased view, so the default value is stored as a string representation.
This method allows getting the actual original default value.

Differential Revision: D10077879

fbshipit-source-id: 2c6bf15eba57da5cb33ad1c657bc9bd51bcd2946
parent cf7517b8
...@@ -63,6 +63,16 @@ class SettingWrapper { ...@@ -63,6 +63,16 @@ class SettingWrapper {
core_.set(t, reason); core_.set(t, reason);
} }
/**
* Returns the default value this setting was constructed with.
* NOTE: SettingsMetadata is type-agnostic, so it only stores the string
* representation of the default value. This method returns the
* actual value that was passed on construction.
*/
const T& defaultValue() const {
return core_.defaultValue();
}
explicit SettingWrapper(SettingCore<T>& core) : core_(core) {} explicit SettingWrapper(SettingCore<T>& core) : core_(core) {}
private: private:
......
...@@ -327,6 +327,10 @@ class SettingCore : public SettingCoreBase { ...@@ -327,6 +327,10 @@ class SettingCore : public SettingCoreBase {
*settingVersion_ = nextGlobalVersion(); *settingVersion_ = nextGlobalVersion();
} }
const T& defaultValue() const {
return defaultValue_;
}
SettingCore( SettingCore(
SettingMetadata meta, SettingMetadata meta,
T defaultValue, T defaultValue,
......
...@@ -58,6 +58,10 @@ struct UserDefinedType { ...@@ -58,6 +58,10 @@ struct UserDefinedType {
} }
} }
bool operator==(const UserDefinedType& other) const {
return value_ == other.value_;
}
int value_; int value_;
}; };
/* Note: conversion intentionally to different strings to test that this /* Note: conversion intentionally to different strings to test that this
...@@ -203,6 +207,17 @@ TEST(Settings, basic) { ...@@ -203,6 +207,17 @@ TEST(Settings, basic) {
EXPECT_FALSE( EXPECT_FALSE(
sn.setFromString("follytest_nonexisting", "300", "from_string")); sn.setFromString("follytest_nonexisting", "300", "from_string"));
} }
EXPECT_EQ(
some_ns::FOLLY_SETTING(follytest, multi_token_type).defaultValue(), 123);
EXPECT_EQ(
a_ns::FOLLY_SETTING(follytest, public_flag_to_a).defaultValue(), 456);
EXPECT_EQ(
b_ns::FOLLY_SETTING(follytest, public_flag_to_b).defaultValue(), "basdf");
EXPECT_EQ(
some_ns::FOLLY_SETTING(follytest, some_flag).defaultValue(), "default");
EXPECT_EQ(
some_ns::FOLLY_SETTING(follytest, user_defined).defaultValue(),
some_ns::UserDefinedType("b"));
{ {
std::string allFlags; std::string allFlags;
folly::settings::Snapshot sn; folly::settings::Snapshot sn;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment