mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-22 17:50:47 +00:00
Add a SettingChar type
This commit is contained in:
parent
a138ab2820
commit
e84263eb3b
@ -706,4 +706,57 @@ struct SettingString
|
||||
}
|
||||
};
|
||||
|
||||
struct SettingChar
|
||||
{
|
||||
private:
|
||||
void checkStringIsACharacter(const String & x) const {
|
||||
if (x.size() != 1)
|
||||
throw Exception(std::string("A setting's value string has to be an exactly one character long"));
|
||||
}
|
||||
public:
|
||||
char value;
|
||||
bool changed = false;
|
||||
|
||||
SettingChar(char x = '\0') : value(x) {}
|
||||
|
||||
operator char() const { return value; }
|
||||
SettingChar & operator= (char x) { set(x); return *this; }
|
||||
|
||||
String toString() const
|
||||
{
|
||||
return String(1, value);
|
||||
}
|
||||
|
||||
void set(char x) {
|
||||
value = x;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void set(const String & x)
|
||||
{
|
||||
checkStringIsACharacter(x);
|
||||
value = x[0];
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void set(const Field & x)
|
||||
{
|
||||
String s = safeGet<const String &>(x);
|
||||
checkStringIsACharacter(s);
|
||||
set(s);
|
||||
}
|
||||
|
||||
void set(ReadBuffer & buf)
|
||||
{
|
||||
String x;
|
||||
readBinary(x, buf);
|
||||
checkStringIsACharacter(x);
|
||||
set(x);
|
||||
}
|
||||
|
||||
void write(WriteBuffer & buf) const
|
||||
{
|
||||
writeBinary(toString(), buf);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user