Skip to content

Commit

Permalink
Replace HumanStringToDataType method with IndexToDataType method.
Browse files Browse the repository at this point in the history
Signed-off-by: Joey Kleingers <[email protected]>
  • Loading branch information
joeykleingers authored and imikejackson committed Oct 25, 2023
1 parent 8fbefca commit 185019c
Showing 1 changed file with 19 additions and 50 deletions.
69 changes: 19 additions & 50 deletions src/complex/Common/TypesUtility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataType> 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<int>(DataType::int8):
case static_cast<int>(DataType::uint8):
case static_cast<int>(DataType::int16):
case static_cast<int>(DataType::uint16):
case static_cast<int>(DataType::int32):
case static_cast<int>(DataType::uint32):
case static_cast<int>(DataType::int64):
case static_cast<int>(DataType::uint64):
case static_cast<int>(DataType::float32):
case static_cast<int>(DataType::float64):
case static_cast<int>(DataType::boolean):
return static_cast<DataType>(index);
default:
return {};
}
}

Expand Down

0 comments on commit 185019c

Please sign in to comment.