Move implementations to cpp file.

This commit is contained in:
Steve Atherton 2023-03-06 18:43:26 -08:00
parent 50d567b5a5
commit f6747adf89
2 changed files with 44 additions and 39 deletions

View File

@ -209,4 +209,43 @@ TEST_CASE("/KeyRangeUtil/KeyRangeComplement") {
}
return Void();
}
}
std::string KeyValueStoreType::getStoreTypeStr(const StoreType& storeType) {
switch (storeType) {
case SSD_BTREE_V1:
return "ssd-1";
case SSD_BTREE_V2:
return "ssd-2";
case SSD_REDWOOD_V1:
return "ssd-redwood-1";
case SSD_ROCKSDB_V1:
return "ssd-rocksdb-v1";
case SSD_SHARDED_ROCKSDB:
return "ssd-sharded-rocksdb";
case MEMORY:
return "memory";
case MEMORY_RADIXTREE:
return "memory-radixtree-beta";
default:
return "unknown";
}
}
KeyValueStoreType KeyValueStoreType::fromString(const std::string& str) {
static std::map<std::string, StoreType> names = { { "ssd-1", SSD_BTREE_V1 },
{ "ssd-2", SSD_BTREE_V2 },
{ "ssd", SSD_BTREE_V2 },
{ "redwood", SSD_REDWOOD_V1 },
{ "ssd-redwood-1", SSD_REDWOOD_V1 },
{ "ssd-redwood-1-experimental", SSD_REDWOOD_V1 },
{ "ssd-rocksdb-v1", SSD_ROCKSDB_V1 },
{ "ssd-sharded-rocksdb", SSD_SHARDED_ROCKSDB },
{ "memory", MEMORY },
{ "memory-radixtree-beta", MEMORY_RADIXTREE } };
auto it = names.find(str);
if (it == names.end()) {
throw unknown_storage_engine();
}
return it->second;
}

View File

@ -926,47 +926,13 @@ struct KeyValueStoreType {
serializer(ar, type);
}
static std::string getStoreTypeStr(const StoreType& storeType) {
switch (storeType) {
case SSD_BTREE_V1:
return "ssd-1";
case SSD_BTREE_V2:
return "ssd-2";
case SSD_REDWOOD_V1:
return "ssd-redwood-1";
case SSD_ROCKSDB_V1:
return "ssd-rocksdb-v1";
case SSD_SHARDED_ROCKSDB:
return "ssd-sharded-rocksdb";
case MEMORY:
return "memory";
case MEMORY_RADIXTREE:
return "memory-radixtree-beta";
default:
return "unknown";
}
}
// Get string representation of engine type. Each enum has one canonical string
// representation, but the reverse is not true (see fromString() below)
static std::string getStoreTypeStr(const StoreType& storeType);
// Convert a string to a KeyValueStoreType
// This is a many-to-one mapping as there are aliases for some storage engines
static KeyValueStoreType fromString(const std::string& str) {
static std::map<std::string, StoreType> names = { { "ssd-1", SSD_BTREE_V1 },
{ "ssd-2", SSD_BTREE_V2 },
{ "ssd", SSD_BTREE_V2 },
{ "redwood", SSD_REDWOOD_V1 },
{ "ssd-redwood-1", SSD_REDWOOD_V1 },
{ "ssd-redwood-1-experimental", SSD_REDWOOD_V1 },
{ "ssd-rocksdb-v1", SSD_ROCKSDB_V1 },
{ "ssd-sharded-rocksdb", SSD_SHARDED_ROCKSDB },
{ "memory", MEMORY },
{ "memory-radixtree-beta", MEMORY_RADIXTREE } };
auto it = names.find(str);
if (it == names.end()) {
throw unknown_storage_engine();
}
return it->second;
}
static KeyValueStoreType fromString(const std::string& str);
std::string toString() const { return getStoreTypeStr((StoreType)type); }
private: