Skip to content
Snippets Groups Projects

ENH: New functions getEnumNameFromValue() and getEnumValueFromName()

Merged Daniel Hornung requested to merge f-enum-utilities into f-consolidation
Files
11
+ 32
7
@@ -46,9 +46,9 @@ class Entity;
class Property;
// Atomic data types.
enum AtomicDataType {
enum class AtomicDataType {
// The data type is unset/unknown.
UNSPECIFIED_DATA_TYPE = ProtoAtomicDataType::ATOMIC_DATA_TYPE_UNSPECIFIED,
UNSPECIFIED = ProtoAtomicDataType::ATOMIC_DATA_TYPE_UNSPECIFIED,
// TEXT data type.
TEXT = ProtoAtomicDataType::ATOMIC_DATA_TYPE_TEXT,
// DOUBLE data type.
@@ -61,6 +61,17 @@ enum AtomicDataType {
BOOLEAN = ProtoAtomicDataType::ATOMIC_DATA_TYPE_BOOLEAN,
};
const std::map<AtomicDataType, std::string> atomicdatatype_names =
{
{AtomicDataType::UNSPECIFIED, "UNSPECIFIED"},
{AtomicDataType::TEXT, "TEXT"},
{AtomicDataType::DOUBLE, "DOUBLE"},
{AtomicDataType::DATETIME, "DATETIME"},
{AtomicDataType::INTEGER, "INTEGER"},
{AtomicDataType::BOOLEAN, "BOOLEAN"}
};
class DataType;
class ListDataType;
@@ -144,12 +155,26 @@ public:
DataType(ProtoDataType *wrapped)
: ProtoMessageWrapper<ProtoDataType>(wrapped) {}
DataType() : ProtoMessageWrapper<ProtoDataType>() {}
DataType(AtomicDataType data_type) : DataType() {
this->wrapped->set_atomic_data_type(
static_cast<ProtoAtomicDataType>(data_type));
/**
* Create an AtomicDataType typed DataType. For references, use the std::string constructor.
*/
DataType(AtomicDataType data_type, bool list_type = false) : DataType() {
if (list_type) {
this->wrapped->mutable_list_data_type()->set_atomic_data_type
(static_cast<ProtoAtomicDataType>(data_type));
} else {
this->wrapped->set_atomic_data_type(static_cast<ProtoAtomicDataType>(data_type));
}
}
DataType(const std::string &data_type) : DataType() {
this->wrapped->mutable_reference_data_type()->set_name(data_type);
/**
* Create a reference typed DataType.
*/
DataType(const std::string &data_type, bool list_type = false) : DataType() {
if (list_type) {
this->wrapped->mutable_list_data_type()->mutable_reference_data_type()->set_name(data_type);
} else {
this->wrapped->mutable_reference_data_type()->set_name(data_type);
}
}
[[nodiscard]] inline auto IsAtomic() const noexcept -> bool {
return this->wrapped->data_type_case() == DataTypeCase::kAtomicDataType;
Loading