From 1fe453e70681c1cc55e70fc3ae4930c5fac00658 Mon Sep 17 00:00:00 2001 From: Joey Kleingers Date: Wed, 25 Oct 2023 11:02:30 -0400 Subject: [PATCH 1/2] Add HumanStringToDataType method. Signed-off-by: Joey Kleingers --- src/complex/Common/TypesUtility.hpp | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/complex/Common/TypesUtility.hpp b/src/complex/Common/TypesUtility.hpp index 74d4cf7b9e..08d75a9ca7 100644 --- a/src/complex/Common/TypesUtility.hpp +++ b/src/complex/Common/TypesUtility.hpp @@ -374,6 +374,63 @@ inline constexpr DataType StringToDataType(std::string_view dataTypeString) } } +/** + * @brief Returns a DataType for the passed in string representation + * @param dataTypeString + * @return + */ +inline constexpr DataType HumanStringToDataType(std::string_view dataTypeString) +{ + if(dataTypeString == DataTypeToHumanString(DataType::int8).view()) + { + return DataType::int8; + } + else if(dataTypeString == DataTypeToHumanString(DataType::uint8).view()) + { + return DataType::uint8; + } + else if(dataTypeString == DataTypeToHumanString(DataType::int16).view()) + { + return DataType::int16; + } + else if(dataTypeString == DataTypeToHumanString(DataType::uint16).view()) + { + return DataType::uint16; + } + else if(dataTypeString == DataTypeToHumanString(DataType::int32).view()) + { + return DataType::int32; + } + else if(dataTypeString == DataTypeToHumanString(DataType::uint32).view()) + { + return DataType::uint32; + } + else if(dataTypeString == DataTypeToHumanString(DataType::int64).view()) + { + return DataType::int64; + } + else if(dataTypeString == DataTypeToHumanString(DataType::uint64).view()) + { + return DataType::uint64; + } + else if(dataTypeString == DataTypeToHumanString(DataType::float32).view()) + { + return DataType::float32; + } + else if(dataTypeString == DataTypeToHumanString(DataType::float64).view()) + { + return DataType::float64; + } + else if(dataTypeString == DataTypeToHumanString(DataType::boolean).view()) + { + return DataType::boolean; + } + else + { + throw std::runtime_error("complex::HumanStringToDataType: No known DataType matches the given string value."); + } +} + /** * @brief Converts DataType to NumericType. Fails on DataType::bool and DataType::error. * @param dataType From 367e3f3000ce1a85be7a20fad93e84fed55735ee Mon Sep 17 00:00:00 2001 From: Joey Kleingers Date: Wed, 25 Oct 2023 15:17:20 -0400 Subject: [PATCH 2/2] Replace HumanStringToDataType method with IndexToDataType method. Signed-off-by: Joey Kleingers --- src/complex/Common/TypesUtility.hpp | 69 ++++++++--------------------- 1 file changed, 19 insertions(+), 50 deletions(-) diff --git a/src/complex/Common/TypesUtility.hpp b/src/complex/Common/TypesUtility.hpp index 08d75a9ca7..e3da359777 100644 --- a/src/complex/Common/TypesUtility.hpp +++ b/src/complex/Common/TypesUtility.hpp @@ -375,59 +375,28 @@ inline constexpr DataType StringToDataType(std::string_view dataTypeString) } /** - * @brief Returns a DataType for the passed in string representation - * @param dataTypeString + * @brief Returns a DataType for the passed in index + * @param index * @return */ -inline constexpr DataType HumanStringToDataType(std::string_view dataTypeString) +inline std::optional IndexToDataType(usize index) { - if(dataTypeString == DataTypeToHumanString(DataType::int8).view()) - { - return DataType::int8; - } - else if(dataTypeString == DataTypeToHumanString(DataType::uint8).view()) - { - return DataType::uint8; - } - else if(dataTypeString == DataTypeToHumanString(DataType::int16).view()) - { - return DataType::int16; - } - else if(dataTypeString == DataTypeToHumanString(DataType::uint16).view()) - { - return DataType::uint16; - } - else if(dataTypeString == DataTypeToHumanString(DataType::int32).view()) - { - return DataType::int32; - } - else if(dataTypeString == DataTypeToHumanString(DataType::uint32).view()) - { - return DataType::uint32; - } - else if(dataTypeString == DataTypeToHumanString(DataType::int64).view()) - { - return DataType::int64; - } - else if(dataTypeString == DataTypeToHumanString(DataType::uint64).view()) - { - return DataType::uint64; - } - else if(dataTypeString == DataTypeToHumanString(DataType::float32).view()) - { - return DataType::float32; - } - else if(dataTypeString == DataTypeToHumanString(DataType::float64).view()) - { - return DataType::float64; - } - else if(dataTypeString == DataTypeToHumanString(DataType::boolean).view()) - { - return DataType::boolean; - } - else - { - throw std::runtime_error("complex::HumanStringToDataType: No known DataType matches the given string value."); + switch(index) + { + case static_cast(DataType::int8): + case static_cast(DataType::uint8): + case static_cast(DataType::int16): + case static_cast(DataType::uint16): + case static_cast(DataType::int32): + case static_cast(DataType::uint32): + case static_cast(DataType::int64): + case static_cast(DataType::uint64): + case static_cast(DataType::float32): + case static_cast(DataType::float64): + case static_cast(DataType::boolean): + return static_cast(index); + default: + return {}; } }