mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-02 12:32:04 +00:00
Revert immutable settings
This commit is contained in:
parent
9e78781378
commit
1b68d79c59
@ -34,19 +34,20 @@ namespace ErrorCodes
|
|||||||
template <typename Type>
|
template <typename Type>
|
||||||
String SettingNumber<Type>::toString() const
|
String SettingNumber<Type>::toString() const
|
||||||
{
|
{
|
||||||
return DB::toString(getValue());
|
return DB::toString(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
Field SettingNumber<Type>::toField() const
|
Field SettingNumber<Type>::toField() const
|
||||||
{
|
{
|
||||||
return getValue();
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
void SettingNumber<Type>::set(Type x)
|
void SettingNumber<Type>::set(Type x)
|
||||||
{
|
{
|
||||||
data.store(Data{x, true}, std::memory_order_relaxed);
|
value = x;
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
@ -58,14 +59,6 @@ void SettingNumber<Type>::set(const Field & x)
|
|||||||
set(applyVisitor(FieldVisitorConvertToNumber<Type>(), x));
|
set(applyVisitor(FieldVisitorConvertToNumber<Type>(), x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename Type>
|
|
||||||
SettingNumber<Type> & SettingNumber<Type>::operator= (const SettingNumber & o)
|
|
||||||
{
|
|
||||||
data.store(o.data.load(std::memory_order_relaxed), std::memory_order_relaxed);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
void SettingNumber<Type>::set(const String & x)
|
void SettingNumber<Type>::set(const String & x)
|
||||||
{
|
{
|
||||||
@ -100,9 +93,9 @@ template <typename Type>
|
|||||||
void SettingNumber<Type>::serialize(WriteBuffer & buf) const
|
void SettingNumber<Type>::serialize(WriteBuffer & buf) const
|
||||||
{
|
{
|
||||||
if constexpr (std::is_integral_v<Type> && std::is_unsigned_v<Type>)
|
if constexpr (std::is_integral_v<Type> && std::is_unsigned_v<Type>)
|
||||||
writeVarUInt(static_cast<UInt64>(getValue()), buf);
|
writeVarUInt(static_cast<UInt64>(value), buf);
|
||||||
else if constexpr (std::is_integral_v<Type> && std::is_signed_v<Type>)
|
else if constexpr (std::is_integral_v<Type> && std::is_signed_v<Type>)
|
||||||
writeVarInt(static_cast<Int64>(getValue()), buf);
|
writeVarInt(static_cast<Int64>(value), buf);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
static_assert(std::is_floating_point_v<Type>);
|
static_assert(std::is_floating_point_v<Type>);
|
||||||
@ -140,28 +133,22 @@ template struct SettingNumber<float>;
|
|||||||
template struct SettingNumber<bool>;
|
template struct SettingNumber<bool>;
|
||||||
|
|
||||||
|
|
||||||
SettingMaxThreads & SettingMaxThreads::operator= (const SettingMaxThreads & o)
|
|
||||||
{
|
|
||||||
data.store(o.data.load(std::memory_order_relaxed), std::memory_order_relaxed);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
String SettingMaxThreads::toString() const
|
String SettingMaxThreads::toString() const
|
||||||
{
|
{
|
||||||
auto d = data.load(std::memory_order_relaxed);
|
|
||||||
/// Instead of the `auto` value, we output the actual value to make it easier to see.
|
/// Instead of the `auto` value, we output the actual value to make it easier to see.
|
||||||
return d.is_auto ? ("auto(" + DB::toString(d.value) + ")") : DB::toString(d.value);
|
return is_auto ? ("auto(" + DB::toString(value) + ")") : DB::toString(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Field SettingMaxThreads::toField() const
|
Field SettingMaxThreads::toField() const
|
||||||
{
|
{
|
||||||
auto d = data.load(std::memory_order_relaxed);
|
return is_auto ? 0 : value;
|
||||||
return d.is_auto ? 0 : d.value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingMaxThreads::set(UInt64 x)
|
void SettingMaxThreads::set(UInt64 x)
|
||||||
{
|
{
|
||||||
data.store({x ? x : getAutoValue(), x == 0, true});
|
value = x ? x : getAutoValue();
|
||||||
|
is_auto = x == 0;
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingMaxThreads::set(const Field & x)
|
void SettingMaxThreads::set(const Field & x)
|
||||||
@ -182,8 +169,7 @@ void SettingMaxThreads::set(const String & x)
|
|||||||
|
|
||||||
void SettingMaxThreads::serialize(WriteBuffer & buf) const
|
void SettingMaxThreads::serialize(WriteBuffer & buf) const
|
||||||
{
|
{
|
||||||
auto d = data.load(std::memory_order_relaxed);
|
writeVarUInt(is_auto ? 0 : value, buf);
|
||||||
writeVarUInt(d.is_auto ? 0 : d.value, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingMaxThreads::deserialize(ReadBuffer & buf)
|
void SettingMaxThreads::deserialize(ReadBuffer & buf)
|
||||||
@ -195,7 +181,8 @@ void SettingMaxThreads::deserialize(ReadBuffer & buf)
|
|||||||
|
|
||||||
void SettingMaxThreads::setAuto()
|
void SettingMaxThreads::setAuto()
|
||||||
{
|
{
|
||||||
data.store({getAutoValue(), true, isChanged()});
|
value = getAutoValue();
|
||||||
|
is_auto = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt64 SettingMaxThreads::getAutoValue() const
|
UInt64 SettingMaxThreads::getAutoValue() const
|
||||||
@ -204,54 +191,22 @@ UInt64 SettingMaxThreads::getAutoValue() const
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingMaxThreads::setChanged(bool changed)
|
|
||||||
{
|
|
||||||
auto d = data.load(std::memory_order_relaxed);
|
|
||||||
data.store({d.value, d.is_auto, changed});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <SettingTimespanIO io_unit>
|
|
||||||
SettingTimespan<io_unit> & SettingTimespan<io_unit>::operator= (const SettingTimespan & o)
|
|
||||||
{
|
|
||||||
std::shared_lock lock_o(o.mutex);
|
|
||||||
value = o.value;
|
|
||||||
changed = o.changed;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <SettingTimespanIO io_unit>
|
|
||||||
SettingTimespan<io_unit>::SettingTimespan(const SettingTimespan & o)
|
|
||||||
{
|
|
||||||
std::shared_lock lock_o(o.mutex);
|
|
||||||
value = o.value;
|
|
||||||
changed = o.changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <SettingTimespanIO io_unit>
|
|
||||||
void SettingTimespan<io_unit>::setChanged(bool c)
|
|
||||||
{
|
|
||||||
std::unique_lock lock(mutex);
|
|
||||||
changed = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <SettingTimespanIO io_unit>
|
template <SettingTimespanIO io_unit>
|
||||||
String SettingTimespan<io_unit>::toString() const
|
String SettingTimespan<io_unit>::toString() const
|
||||||
{
|
{
|
||||||
return DB::toString(getValue().totalMicroseconds() / microseconds_per_io_unit);
|
return DB::toString(value.totalMicroseconds() / microseconds_per_io_unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <SettingTimespanIO io_unit>
|
template <SettingTimespanIO io_unit>
|
||||||
Field SettingTimespan<io_unit>::toField() const
|
Field SettingTimespan<io_unit>::toField() const
|
||||||
{
|
{
|
||||||
return getValue().totalMicroseconds() / microseconds_per_io_unit;
|
return value.totalMicroseconds() / microseconds_per_io_unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <SettingTimespanIO io_unit>
|
template <SettingTimespanIO io_unit>
|
||||||
void SettingTimespan<io_unit>::set(const Poco::Timespan & x)
|
void SettingTimespan<io_unit>::set(const Poco::Timespan & x)
|
||||||
{
|
{
|
||||||
std::unique_lock lock(mutex);
|
|
||||||
value = x;
|
value = x;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
@ -280,7 +235,7 @@ void SettingTimespan<io_unit>::set(const String & x)
|
|||||||
template <SettingTimespanIO io_unit>
|
template <SettingTimespanIO io_unit>
|
||||||
void SettingTimespan<io_unit>::serialize(WriteBuffer & buf) const
|
void SettingTimespan<io_unit>::serialize(WriteBuffer & buf) const
|
||||||
{
|
{
|
||||||
writeVarUInt(getValue().totalMicroseconds() / microseconds_per_io_unit, buf);
|
writeVarUInt(value.totalMicroseconds() / microseconds_per_io_unit, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <SettingTimespanIO io_unit>
|
template <SettingTimespanIO io_unit>
|
||||||
@ -294,47 +249,23 @@ void SettingTimespan<io_unit>::deserialize(ReadBuffer & buf)
|
|||||||
template struct SettingTimespan<SettingTimespanIO::SECOND>;
|
template struct SettingTimespan<SettingTimespanIO::SECOND>;
|
||||||
template struct SettingTimespan<SettingTimespanIO::MILLISECOND>;
|
template struct SettingTimespan<SettingTimespanIO::MILLISECOND>;
|
||||||
|
|
||||||
SettingString & SettingString::operator= (const SettingString & o)
|
|
||||||
{
|
|
||||||
std::shared_lock lock_o(o.mutex);
|
|
||||||
value = o.value;
|
|
||||||
changed = o.changed;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
SettingString::SettingString(const SettingString & o)
|
|
||||||
{
|
|
||||||
std::shared_lock lock(o.mutex);
|
|
||||||
value = o.value;
|
|
||||||
changed = o.changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
String SettingString::toString() const
|
String SettingString::toString() const
|
||||||
{
|
{
|
||||||
std::shared_lock lock(mutex);
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Field SettingString::toField() const
|
Field SettingString::toField() const
|
||||||
{
|
{
|
||||||
std::shared_lock lock(mutex);
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingString::set(const String & x)
|
void SettingString::set(const String & x)
|
||||||
{
|
{
|
||||||
std::unique_lock lock(mutex);
|
|
||||||
value = x;
|
value = x;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingString::setChanged(bool c)
|
|
||||||
{
|
|
||||||
std::unique_lock lock(mutex);
|
|
||||||
changed = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingString::set(const Field & x)
|
void SettingString::set(const Field & x)
|
||||||
{
|
{
|
||||||
set(safeGet<const String &>(x));
|
set(safeGet<const String &>(x));
|
||||||
@ -352,15 +283,10 @@ void SettingString::deserialize(ReadBuffer & buf)
|
|||||||
set(s);
|
set(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingChar & SettingChar::operator= (const SettingChar & o)
|
|
||||||
{
|
|
||||||
data.store(o.data.load(std::memory_order_relaxed), std::memory_order_relaxed);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
String SettingChar::toString() const
|
String SettingChar::toString() const
|
||||||
{
|
{
|
||||||
return String(1, getValue());
|
return String(1, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Field SettingChar::toField() const
|
Field SettingChar::toField() const
|
||||||
@ -370,7 +296,8 @@ Field SettingChar::toField() const
|
|||||||
|
|
||||||
void SettingChar::set(char x)
|
void SettingChar::set(char x)
|
||||||
{
|
{
|
||||||
data.store({x, true});
|
value = x;
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingChar::set(const String & x)
|
void SettingChar::set(const String & x)
|
||||||
@ -400,19 +327,6 @@ void SettingChar::deserialize(ReadBuffer & buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename EnumType, typename Tag>
|
|
||||||
SettingEnum<EnumType, Tag> & SettingEnum<EnumType, Tag>::operator= (const SettingEnum & o)
|
|
||||||
{
|
|
||||||
data.store(o.data.load(std::memory_order_relaxed), std::memory_order_relaxed);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename EnumType, typename Tag>
|
|
||||||
void SettingEnum<EnumType, Tag>::set(EnumType x)
|
|
||||||
{
|
|
||||||
data.store({x, true}, std::memory_order_relaxed);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename EnumType, typename Tag>
|
template <typename EnumType, typename Tag>
|
||||||
void SettingEnum<EnumType, Tag>::serialize(WriteBuffer & buf) const
|
void SettingEnum<EnumType, Tag>::serialize(WriteBuffer & buf) const
|
||||||
{
|
{
|
||||||
@ -428,7 +342,6 @@ void SettingEnum<EnumType, Tag>::deserialize(ReadBuffer & buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define IMPLEMENT_SETTING_ENUM(ENUM_NAME, LIST_OF_NAMES_MACRO, ERROR_CODE_FOR_UNEXPECTED_NAME) \
|
#define IMPLEMENT_SETTING_ENUM(ENUM_NAME, LIST_OF_NAMES_MACRO, ERROR_CODE_FOR_UNEXPECTED_NAME) \
|
||||||
IMPLEMENT_SETTING_ENUM_WITH_TAG(ENUM_NAME, void, LIST_OF_NAMES_MACRO, ERROR_CODE_FOR_UNEXPECTED_NAME)
|
IMPLEMENT_SETTING_ENUM_WITH_TAG(ENUM_NAME, void, LIST_OF_NAMES_MACRO, ERROR_CODE_FOR_UNEXPECTED_NAME)
|
||||||
|
|
||||||
@ -438,7 +351,7 @@ void SettingEnum<EnumType, Tag>::deserialize(ReadBuffer & buf)
|
|||||||
{ \
|
{ \
|
||||||
using EnumType = ENUM_NAME; \
|
using EnumType = ENUM_NAME; \
|
||||||
using UnderlyingType = std::underlying_type<EnumType>::type; \
|
using UnderlyingType = std::underlying_type<EnumType>::type; \
|
||||||
switch (static_cast<UnderlyingType>(getValue())) \
|
switch (static_cast<UnderlyingType>(value)) \
|
||||||
{ \
|
{ \
|
||||||
LIST_OF_NAMES_MACRO(IMPLEMENT_SETTING_ENUM_TO_STRING_HELPER_) \
|
LIST_OF_NAMES_MACRO(IMPLEMENT_SETTING_ENUM_TO_STRING_HELPER_) \
|
||||||
} \
|
} \
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
#include <Core/Types.h>
|
#include <Core/Types.h>
|
||||||
#include <ext/singleton.h>
|
#include <ext/singleton.h>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <atomic>
|
|
||||||
#include <shared_mutex>
|
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
@ -33,26 +31,14 @@ namespace ErrorCodes
|
|||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
struct SettingNumber
|
struct SettingNumber
|
||||||
{
|
|
||||||
struct Data
|
|
||||||
{
|
{
|
||||||
Type value;
|
Type value;
|
||||||
bool changed;
|
bool changed = false;
|
||||||
};
|
|
||||||
|
|
||||||
std::atomic<Data> data;
|
SettingNumber(Type x = 0) : value(x) {}
|
||||||
|
|
||||||
SettingNumber(Type x = 0) : data{{x, false}} {}
|
|
||||||
SettingNumber(const SettingNumber & o) : data{o.data.load(std::memory_order_relaxed)} {}
|
|
||||||
|
|
||||||
bool isChanged() const { return data.load(std::memory_order_relaxed).changed; }
|
|
||||||
void setChanged(bool changed) { data.store({getValue(), changed}, std::memory_order_relaxed); }
|
|
||||||
|
|
||||||
operator Type() const { return getValue(); }
|
|
||||||
Type getValue() const { return data.load(std::memory_order_relaxed).value; }
|
|
||||||
|
|
||||||
|
operator Type() const { return value; }
|
||||||
SettingNumber & operator= (Type x) { set(x); return *this; }
|
SettingNumber & operator= (Type x) { set(x); return *this; }
|
||||||
SettingNumber & operator= (const SettingNumber & o);
|
|
||||||
|
|
||||||
/// Serialize to a test string.
|
/// Serialize to a test string.
|
||||||
String toString() const;
|
String toString() const;
|
||||||
@ -86,27 +72,15 @@ using SettingBool = SettingNumber<bool>;
|
|||||||
* When serializing, `auto` is written in the same way as 0.
|
* When serializing, `auto` is written in the same way as 0.
|
||||||
*/
|
*/
|
||||||
struct SettingMaxThreads
|
struct SettingMaxThreads
|
||||||
{
|
|
||||||
struct Data
|
|
||||||
{
|
{
|
||||||
UInt64 value;
|
UInt64 value;
|
||||||
bool is_auto;
|
bool is_auto;
|
||||||
bool changed;
|
bool changed = false;
|
||||||
};
|
|
||||||
|
|
||||||
std::atomic<Data> data;
|
SettingMaxThreads(UInt64 x = 0) : value(x ? x : getAutoValue()), is_auto(x == 0) {}
|
||||||
|
|
||||||
SettingMaxThreads(UInt64 x = 0) : data{{x ? x : getAutoValue(), x == 0, false}} {}
|
|
||||||
SettingMaxThreads(const SettingMaxThreads & o) : data{o.data.load(std::memory_order_relaxed)} {}
|
|
||||||
|
|
||||||
bool isChanged() const { return data.load(std::memory_order_relaxed).changed; }
|
|
||||||
void setChanged(bool changed);
|
|
||||||
|
|
||||||
operator UInt64() const { return getValue(); }
|
|
||||||
UInt64 getValue() const { return data.load(std::memory_order_relaxed).value; }
|
|
||||||
|
|
||||||
|
operator UInt64() const { return value; }
|
||||||
SettingMaxThreads & operator= (UInt64 x) { set(x); return *this; }
|
SettingMaxThreads & operator= (UInt64 x) { set(x); return *this; }
|
||||||
SettingMaxThreads & operator= (const SettingMaxThreads & o);
|
|
||||||
|
|
||||||
String toString() const;
|
String toString() const;
|
||||||
Field toField() const;
|
Field toField() const;
|
||||||
@ -118,7 +92,6 @@ struct SettingMaxThreads
|
|||||||
void serialize(WriteBuffer & buf) const;
|
void serialize(WriteBuffer & buf) const;
|
||||||
void deserialize(ReadBuffer & buf);
|
void deserialize(ReadBuffer & buf);
|
||||||
|
|
||||||
bool isAuto() const { return data.load(std::memory_order_relaxed).is_auto; }
|
|
||||||
void setAuto();
|
void setAuto();
|
||||||
UInt64 getAutoValue() const;
|
UInt64 getAutoValue() const;
|
||||||
};
|
};
|
||||||
@ -129,37 +102,16 @@ enum class SettingTimespanIO { MILLISECOND, SECOND };
|
|||||||
template <SettingTimespanIO io_unit>
|
template <SettingTimespanIO io_unit>
|
||||||
struct SettingTimespan
|
struct SettingTimespan
|
||||||
{
|
{
|
||||||
mutable std::shared_mutex mutex;
|
|
||||||
Poco::Timespan value;
|
Poco::Timespan value;
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
SettingTimespan(UInt64 x = 0) : value(x * microseconds_per_io_unit) {}
|
SettingTimespan(UInt64 x = 0) : value(x * microseconds_per_io_unit) {}
|
||||||
SettingTimespan(const SettingTimespan & o);
|
|
||||||
|
|
||||||
operator Poco::Timespan() const { return getValue(); }
|
operator Poco::Timespan() const { return value; }
|
||||||
Poco::Timespan getValue() const { std::shared_lock lock(mutex); return value; }
|
|
||||||
SettingTimespan & operator= (const Poco::Timespan & x) { set(x); return *this; }
|
SettingTimespan & operator= (const Poco::Timespan & x) { set(x); return *this; }
|
||||||
SettingTimespan & operator= (const SettingTimespan & o);
|
|
||||||
|
|
||||||
Poco::Timespan::TimeDiff totalSeconds() const
|
Poco::Timespan::TimeDiff totalSeconds() const { return value.totalSeconds(); }
|
||||||
{
|
Poco::Timespan::TimeDiff totalMilliseconds() const { return value.totalMilliseconds(); }
|
||||||
std::shared_lock lock(mutex);
|
|
||||||
return value.totalSeconds();
|
|
||||||
}
|
|
||||||
|
|
||||||
Poco::Timespan::TimeDiff totalMilliseconds() const
|
|
||||||
{
|
|
||||||
std::shared_lock lock(mutex);
|
|
||||||
return value.totalMilliseconds();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isChanged() const
|
|
||||||
{
|
|
||||||
std::shared_lock lock(mutex);
|
|
||||||
return changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setChanged(bool changed);
|
|
||||||
|
|
||||||
String toString() const;
|
String toString() const;
|
||||||
Field toField() const;
|
Field toField() const;
|
||||||
@ -182,19 +134,13 @@ using SettingMilliseconds = SettingTimespan<SettingTimespanIO::MILLISECOND>;
|
|||||||
|
|
||||||
struct SettingString
|
struct SettingString
|
||||||
{
|
{
|
||||||
mutable std::shared_mutex mutex;
|
|
||||||
String value;
|
String value;
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
SettingString(const String & x = String{}) : value(x) {}
|
SettingString(const String & x = String{}) : value(x) {}
|
||||||
SettingString(const SettingString & o);
|
|
||||||
|
|
||||||
operator String() const { return getValue(); }
|
operator String() const { return value; }
|
||||||
String getValue() const { std::shared_lock lock(mutex); return value; }
|
|
||||||
SettingString & operator= (const String & x) { set(x); return *this; }
|
SettingString & operator= (const String & x) { set(x); return *this; }
|
||||||
SettingString & operator= (const SettingString & o);
|
|
||||||
bool isChanged() const { std::shared_lock lock(mutex); return changed; }
|
|
||||||
void setChanged(bool changed);
|
|
||||||
|
|
||||||
String toString() const;
|
String toString() const;
|
||||||
Field toField() const;
|
Field toField() const;
|
||||||
@ -210,25 +156,13 @@ struct SettingString
|
|||||||
struct SettingChar
|
struct SettingChar
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct Data
|
|
||||||
{
|
|
||||||
char value;
|
char value;
|
||||||
bool changed;
|
bool changed = false;
|
||||||
};
|
|
||||||
|
|
||||||
std::atomic<Data> data;
|
SettingChar(char x = '\0') : value(x) {}
|
||||||
|
|
||||||
SettingChar(char x = '\0') : data({x, false}) {}
|
|
||||||
SettingChar(const SettingChar & o) : data{o.data.load(std::memory_order_relaxed)} {}
|
|
||||||
|
|
||||||
operator char() const { return getValue(); }
|
|
||||||
char getValue() const { return data.load(std::memory_order_relaxed).value; }
|
|
||||||
|
|
||||||
|
operator char() const { return value; }
|
||||||
SettingChar & operator= (char x) { set(x); return *this; }
|
SettingChar & operator= (char x) { set(x); return *this; }
|
||||||
SettingChar & operator= (const SettingChar & o);
|
|
||||||
|
|
||||||
bool isChanged() const { return data.load(std::memory_order_relaxed).changed; }
|
|
||||||
void setChanged(bool changed) { data.store({getValue(), changed}, std::memory_order_relaxed);}
|
|
||||||
|
|
||||||
String toString() const;
|
String toString() const;
|
||||||
Field toField() const;
|
Field toField() const;
|
||||||
@ -245,31 +179,19 @@ public:
|
|||||||
/// Template class to define enum-based settings.
|
/// Template class to define enum-based settings.
|
||||||
template <typename EnumType, typename Tag = void>
|
template <typename EnumType, typename Tag = void>
|
||||||
struct SettingEnum
|
struct SettingEnum
|
||||||
{
|
|
||||||
struct Data
|
|
||||||
{
|
{
|
||||||
EnumType value;
|
EnumType value;
|
||||||
bool changed;
|
bool changed = false;
|
||||||
};
|
|
||||||
|
|
||||||
std::atomic<Data> data;
|
SettingEnum(EnumType x) : value(x) {}
|
||||||
|
|
||||||
SettingEnum(EnumType x) : data({x, false}) {}
|
|
||||||
SettingEnum(const SettingEnum & o) : data{o.data.load(std::memory_order_relaxed)} {}
|
|
||||||
|
|
||||||
operator EnumType() const { return getValue(); }
|
|
||||||
EnumType getValue() const { return data.load(std::memory_order_relaxed).value; }
|
|
||||||
|
|
||||||
|
operator EnumType() const { return value; }
|
||||||
SettingEnum & operator= (EnumType x) { set(x); return *this; }
|
SettingEnum & operator= (EnumType x) { set(x); return *this; }
|
||||||
SettingEnum & operator= (const SettingEnum & o);
|
|
||||||
|
|
||||||
bool isChanged() const { return data.load(std::memory_order_relaxed).changed; }
|
|
||||||
void setChanged(bool changed) { data.store({getValue(), changed}, std::memory_order_relaxed);}
|
|
||||||
|
|
||||||
String toString() const;
|
String toString() const;
|
||||||
Field toField() const { return toString(); }
|
Field toField() const { return toString(); }
|
||||||
|
|
||||||
void set(EnumType x);
|
void set(EnumType x) { value = x; changed = true; }
|
||||||
void set(const Field & x) { set(safeGet<const String &>(x)); }
|
void set(const Field & x) { set(safeGet<const String &>(x)); }
|
||||||
void set(const String & x);
|
void set(const String & x);
|
||||||
|
|
||||||
@ -386,7 +308,6 @@ private:
|
|||||||
Derived & castToDerived() { return *static_cast<Derived *>(this); }
|
Derived & castToDerived() { return *static_cast<Derived *>(this); }
|
||||||
const Derived & castToDerived() const { return *static_cast<const Derived *>(this); }
|
const Derived & castToDerived() const { return *static_cast<const Derived *>(this); }
|
||||||
|
|
||||||
using IsChangedFunction = bool (*)(const Derived &);
|
|
||||||
using GetStringFunction = String (*)(const Derived &);
|
using GetStringFunction = String (*)(const Derived &);
|
||||||
using GetFieldFunction = Field (*)(const Derived &);
|
using GetFieldFunction = Field (*)(const Derived &);
|
||||||
using SetStringFunction = void (*)(Derived &, const String &);
|
using SetStringFunction = void (*)(Derived &, const String &);
|
||||||
@ -397,7 +318,7 @@ private:
|
|||||||
|
|
||||||
struct MemberInfo
|
struct MemberInfo
|
||||||
{
|
{
|
||||||
IsChangedFunction is_changed;
|
size_t offset_of_changed;
|
||||||
StringRef name;
|
StringRef name;
|
||||||
StringRef description;
|
StringRef description;
|
||||||
/// Can be updated after first load for config/definition.
|
/// Can be updated after first load for config/definition.
|
||||||
@ -412,7 +333,7 @@ private:
|
|||||||
DeserializeFunction deserialize;
|
DeserializeFunction deserialize;
|
||||||
CastValueWithoutApplyingFunction cast_value_without_applying;
|
CastValueWithoutApplyingFunction cast_value_without_applying;
|
||||||
|
|
||||||
bool isChanged(const Derived & collection) const { return is_changed(collection); }
|
bool isChanged(const Derived & collection) const { return *reinterpret_cast<const bool*>(reinterpret_cast<const UInt8*>(&collection) + offset_of_changed); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class MemberInfos
|
class MemberInfos
|
||||||
@ -772,7 +693,8 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
#define IMPLEMENT_SETTINGS_COLLECTION_ADD_MUTABLE_MEMBER_INFO_HELPER_(TYPE, NAME, DEFAULT, DESCRIPTION) \
|
#define IMPLEMENT_SETTINGS_COLLECTION_ADD_MUTABLE_MEMBER_INFO_HELPER_(TYPE, NAME, DEFAULT, DESCRIPTION) \
|
||||||
add({[](const Derived & d) { return d.NAME.isChanged(); }, \
|
static_assert(std::is_same_v<decltype(std::declval<Derived>().NAME.changed), bool>); \
|
||||||
|
add({offsetof(Derived, NAME.changed), \
|
||||||
StringRef(#NAME, strlen(#NAME)), StringRef(#DESCRIPTION, strlen(#DESCRIPTION)), true, \
|
StringRef(#NAME, strlen(#NAME)), StringRef(#DESCRIPTION, strlen(#DESCRIPTION)), true, \
|
||||||
&Functions::NAME##_getString, &Functions::NAME##_getField, \
|
&Functions::NAME##_getString, &Functions::NAME##_getField, \
|
||||||
&Functions::NAME##_setString, &Functions::NAME##_setField, \
|
&Functions::NAME##_setString, &Functions::NAME##_setField, \
|
||||||
@ -780,7 +702,8 @@ public:
|
|||||||
&Functions::NAME##_castValueWithoutApplying });
|
&Functions::NAME##_castValueWithoutApplying });
|
||||||
|
|
||||||
#define IMPLEMENT_SETTINGS_COLLECTION_ADD_IMMUTABLE_MEMBER_INFO_HELPER_(TYPE, NAME, DEFAULT, DESCRIPTION) \
|
#define IMPLEMENT_SETTINGS_COLLECTION_ADD_IMMUTABLE_MEMBER_INFO_HELPER_(TYPE, NAME, DEFAULT, DESCRIPTION) \
|
||||||
add({[](const Derived & d) { return d.NAME.isChanged(); }, \
|
static_assert(std::is_same_v<decltype(std::declval<Derived>().NAME.changed), bool>); \
|
||||||
|
add({offsetof(Derived, NAME.changed), \
|
||||||
StringRef(#NAME, strlen(#NAME)), StringRef(#DESCRIPTION, strlen(#DESCRIPTION)), false, \
|
StringRef(#NAME, strlen(#NAME)), StringRef(#DESCRIPTION, strlen(#DESCRIPTION)), false, \
|
||||||
&Functions::NAME##_getString, &Functions::NAME##_getField, \
|
&Functions::NAME##_getString, &Functions::NAME##_getField, \
|
||||||
&Functions::NAME##_setString, &Functions::NAME##_setField, \
|
&Functions::NAME##_setString, &Functions::NAME##_setField, \
|
||||||
|
Loading…
Reference in New Issue
Block a user