VolumeType as class with enum member class

This commit is contained in:
Gleb Novikov 2020-05-10 09:26:33 +03:00
parent 390b39b272
commit a961e049a2
3 changed files with 51 additions and 4 deletions

View File

@ -494,6 +494,7 @@ namespace ErrorCodes
extern const int CANNOT_DETACH_DICTIONARY_AS_TABLE = 520;
extern const int ATOMIC_RENAME_FAIL = 521;
extern const int INCORRECT_DISK_INDEX = 522;
extern const int UNKNOWN_VOLUME_TYPE = 523;
extern const int KEEPER_EXCEPTION = 999;
extern const int POCO_EXCEPTION = 1000;

View File

@ -10,6 +10,30 @@ namespace DB
namespace ErrorCodes
{
extern const int EXCESSIVE_ELEMENT_IN_CONFIG;
extern const int UNKNOWN_VOLUME_TYPE;
}
void VolumeType::fromString(const String & str)
{
if (str == "JBOD")
value = JBOD;
else if (str == "SINGLE_DISK")
value = SINGLE_DISK;
else
throw DB::Exception("Unexpected string for volume type: " + str, ErrorCodes::UNKNOWN_VOLUME_TYPE);
}
String VolumeType::toString() const
{
switch (value)
{
case JBOD:
return "JBOD";
case SINGLE_DISK:
return "SINGLE_DISK";
default:
return "Unknown";
}
}
IVolume::IVolume(

View File

@ -8,11 +8,33 @@
namespace DB
{
enum VolumeType
class VolumeType
{
JBOD,
SINGLE_DISK,
UNKNOWN
public:
enum Value
{
JBOD,
SINGLE_DISK,
UNKNOWN
};
VolumeType() : value(UNKNOWN) {}
VolumeType(Value value_) : value(value_) {}
bool operator==(const VolumeType & other) const
{
return value == other.value;
}
bool operator!=(const VolumeType & other) const
{
return !(*this == other);
}
void fromString(const String & str);
String toString() const;
private:
Value value;
};
class IVolume;